896 lines
		
	
	
		
			25 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			896 lines
		
	
	
		
			25 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | ||
| #include <automask.h>
 | ||
| #include <isam.h>
 | ||
| #include <mask.h>
 | ||
| #include <prefix.h>
 | ||
| #include <progind.h>
 | ||
| #include <relation.h>
 | ||
| #include <sheet.h>
 | ||
| #include <tabutil.h>
 | ||
| 
 | ||
| #include <nditte.h>
 | ||
| 
 | ||
| #include "ce0.h"
 | ||
| #include "ce0900a.h"
 | ||
| #include "../cg/cglib01.h"
 | ||
| 
 | ||
| #define CAMPODITTA "CAMPODITTA"
 | ||
| 
 | ||
| class TConversione_ce_mask : public TAutomask
 | ||
| {
 | ||
|   TRelation*      _rel;
 | ||
|   TCursor*        _cur;
 | ||
|   TCursor_sheet*  _sheet;
 | ||
|      
 | ||
| protected:
 | ||
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | ||
|   bool already_converted(long ditta);
 | ||
|      
 | ||
| public:
 | ||
|   TCursor_sheet& sheet() {return *_sheet;}
 | ||
|   void lista_ditte(TAssoc_array& ditte);
 | ||
|   TConversione_ce_mask(); 
 | ||
|   ~TConversione_ce_mask();
 | ||
| };  
 | ||
|                                                           
 | ||
| static bool esiste_ditta(const TRelation* rel)
 | ||
| {                        
 | ||
|   const long ditta = rel->curr().get_long(NDT_CODDITTA);
 | ||
|   return prefix().exist(ditta);
 | ||
| }                                                                              
 | ||
|    
 | ||
| bool TConversione_ce_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | ||
| {
 | ||
|   switch (o.dlg())
 | ||
|   {
 | ||
|   case F_SCELTADITTE:
 | ||
|     if (e == fe_button)
 | ||
|     {
 | ||
|       sheet().run();
 | ||
|       set(F_DITTESELEZ, sheet().checked());
 | ||
|     } 
 | ||
|     if (e == fe_close)
 | ||
|       if (sheet().checked() == 0)
 | ||
|         return error_box(TR("Non sono state selezionate ditte da convertire"));
 | ||
|     break;
 | ||
|   case F_DITTESELEZ:
 | ||
|     if (e == fe_init)
 | ||
|       o.set(sheet().checked());
 | ||
|     break;    
 | ||
|   case F_MINISTERIALI:
 | ||
|     if (e == fe_init)
 | ||
|     {
 | ||
|       TTable cgr("%CGR");     
 | ||
|       const bool empty = cgr.first() != NOERR;
 | ||
|       o.set(empty ? "X": " ");
 | ||
|     }
 | ||
|     break;    
 | ||
|   default:
 | ||
|     break;
 | ||
|   }     
 | ||
|   return TRUE;
 | ||
| }  
 | ||
| 
 | ||
| bool TConversione_ce_mask::already_converted(long ditta)
 | ||
| {
 | ||
|   prefix().set_codditta(ditta);
 | ||
|   TTable cce("CCE");
 | ||
|   int err = cce.first();
 | ||
|   if (err != NOERR)
 | ||
|     return FALSE;
 | ||
| 
 | ||
|   TFilename ditce = prefix().get_studio();
 | ||
|   ditce.add("cesp/ditce");
 | ||
|   TExternisamfile oldfile(ditce,(bool) FALSE,(bool) FALSE);
 | ||
| 
 | ||
|   for (err = oldfile.first(); err == NOERR; err = oldfile.next())
 | ||
|   {
 | ||
|     long d = oldfile.get_long("CACDD");
 | ||
|     if (d == ditta)
 | ||
|       return TRUE;
 | ||
|   }
 | ||
|   return FALSE;
 | ||
| }
 | ||
| 
 | ||
| void TConversione_ce_mask::lista_ditte(TAssoc_array& ditte)
 | ||
| {
 | ||
|   ditte.destroy();
 | ||
|   for (long i = sheet().items()-1; i >= 0; i--)
 | ||
|   {                                           
 | ||
|     if (sheet().checked(i))
 | ||
|     {
 | ||
|       const TString16 codditta = sheet().row(i).get(1);
 | ||
|       bool add = TRUE;
 | ||
|       if (already_converted(atol(codditta)))
 | ||
|         add = yesno_box(FR("La ditta %s potrebbe gi<67> essere stata converita:\n"
 | ||
|                         "Si desidera continuare ugualmente, azzerando gli archivi attuali?"),
 | ||
|                         (const char*)codditta);
 | ||
|       if (add)
 | ||
|         ditte.add(codditta);
 | ||
|     }  
 | ||
|   }
 | ||
| }    
 | ||
|    
 | ||
| TConversione_ce_mask::TConversione_ce_mask()
 | ||
| : TAutomask("ce0900a")
 | ||
| {
 | ||
|   _rel = new TRelation(LF_NDITTE);
 | ||
|   _cur = new TCursor(_rel); 
 | ||
|   _cur->set_filterfunction(esiste_ditta);
 | ||
|   _sheet = new TCursor_sheet(_cur, " |CODDITTA|RAGSOC", TR("Selezione ditte"), HR("@1|Codice|Ragione sociale@50"), 0, 1);
 | ||
|   _sheet->check(-1);
 | ||
| }
 | ||
| 
 | ||
| TConversione_ce_mask::~TConversione_ce_mask()
 | ||
| {
 | ||
|   delete _sheet;
 | ||
|   delete _cur;
 | ||
|   delete _rel;
 | ||
| }
 | ||
| 
 | ||
| class TConversione_cespiti: public TSkeleton_application
 | ||
| {
 | ||
|   FILE * _log;
 | ||
|   TAssoc_array  _ditte;
 | ||
|   
 | ||
| protected:
 | ||
|   virtual bool create(void);
 | ||
|   virtual void main_loop();
 | ||
|   virtual bool destroy(void) ;
 | ||
|   void open_log();
 | ||
|   void write_log(const char * line);
 | ||
|   void close_log();
 | ||
|   int zap_file(int lf) const;
 | ||
|   void zap_table(const char* tab) const;
 | ||
| 
 | ||
| public:
 | ||
|   bool daconvertire(const long ditta);
 | ||
|   int conv_file(const TFilename& ofname, int nflogicnum);
 | ||
|   int conv_inifile(const TFilename& ofname, const char* ofpar, int nflogicnum);
 | ||
|   int conv_tab(const TFilename& ofname, const char* cod);
 | ||
|   int conv_par(const TFilename& ofname, const char* ofpar, int which_config);
 | ||
|   int get_codesc(const TDate& date, const bool fatal = FALSE);
 | ||
|   const char conv_imptmc(int cod);
 | ||
|   TConversione_cespiti() {}
 | ||
|   virtual ~TConversione_cespiti() {}
 | ||
| };
 | ||
| 
 | ||
| bool TConversione_cespiti::create()
 | ||
| {
 | ||
|   return TSkeleton_application::create();
 | ||
| }
 | ||
| 
 | ||
| bool TConversione_cespiti::destroy()
 | ||
| {
 | ||
|   return TSkeleton_application::destroy();
 | ||
| }
 | ||
|                                       
 | ||
| bool TConversione_cespiti::daconvertire(const long ditta)
 | ||
| {
 | ||
|   TString16 strditta;
 | ||
|   strditta.format("%ld", ditta);
 | ||
|   return _ditte.is_key(strditta); 
 | ||
| }                                      
 | ||
|                                       
 | ||
| void TConversione_cespiti::main_loop()
 | ||
| {  
 | ||
|   TConversione_ce_mask msk;                   
 | ||
|   if (msk.run() == K_ENTER && yesno_box(TR("Confermare la conversione dei cespiti?"))) 
 | ||
|   {                      
 | ||
|     msk.lista_ditte(_ditte);
 | ||
|     if (_ditte.items() == 0)
 | ||
|     {
 | ||
|       warning_box(TR("Nessuna ditta selezionata"));
 | ||
|       return;
 | ||
|     }  
 | ||
|     open_log();
 | ||
|     TString80 s;
 | ||
|     write_log("");        
 | ||
|     write_log("**********************************");        
 | ||
|     s.format(TR("Conversione cespiti del %s"), (const char *) TDate(TODAY).string());
 | ||
|     write_log(s);
 | ||
|     write_log("**********************************");        
 | ||
|     write_log("");        
 | ||
|     
 | ||
|     const char* studio = prefix().get_studio();
 | ||
|     const bool converti_ministeriali  = msk.get_bool(F_MINISTERIALI);
 | ||
|     // conversione archivi
 | ||
|     TFilename file = studio;
 | ||
|     file << "cesp/ammce";
 | ||
|     conv_file(file, 136);
 | ||
|     file = studio;
 | ||
|     file << "cesp/ammmv";
 | ||
|     conv_file(file, 137);
 | ||
|     file = studio;
 | ||
|     file << "cesp/catdi";
 | ||
|     conv_file(file, 138);
 | ||
|     file = studio;
 | ||
|     file << "cesp/cespi";
 | ||
|     conv_file(file, 139);
 | ||
|     file = studio;
 | ||
|     file << "cesp/movam";
 | ||
|     conv_file(file, 141);
 | ||
|     file = studio;
 | ||
|     file << "cesp/movce";
 | ||
|     conv_file(file, 142);
 | ||
|     file = studio;
 | ||
|     file << "cesp/salce";
 | ||
|     conv_file(file, 143); 
 | ||
|     file = studio;
 | ||
|     file << "cesp/coll01";
 | ||
|     conv_inifile(file, "COLL01", 140); 
 | ||
|     // conversione tabelle
 | ||
|     file = studio;
 | ||
|     file << "cesp/ditcb";
 | ||
|     conv_tab(file, "CCB"); 
 | ||
|     file = studio;
 | ||
|     file << "cesp/ditce";
 | ||
|     conv_tab(file, "CCE"); 
 | ||
|     file = studio;
 | ||
|     file << "cesp/tabimp";
 | ||
|     conv_tab(file, "CIM"); 
 | ||
|     file = studio;
 | ||
|     file << "cesp/tabloc";
 | ||
|     conv_tab(file, "LOC"); 
 | ||
|     if (converti_ministeriali)
 | ||
|     { 
 | ||
|       file = studio;
 | ||
|       file << "cesp/tabat";
 | ||
|       conv_tab(file, "%CAT"); 
 | ||
|       file = studio;
 | ||
|       file << "cesp/tabca";
 | ||
|       conv_tab(file, "%CAC"); 
 | ||
|       file = studio;
 | ||
|       file << "cesp/tabgr";
 | ||
|       conv_tab(file, "%CGR"); 
 | ||
|       file = studio;
 | ||
|       file << "cesp/limit";
 | ||
|       conv_tab(file, "%CLM"); 
 | ||
|       file = studio;
 | ||
|       file << "cesp/tmvce";
 | ||
|       conv_tab(file, "%TMC"); 
 | ||
|     }
 | ||
|     // conversione parametri
 | ||
|     file = studio;
 | ||
|     file << "cesp/ditc01";
 | ||
|     conv_par(file, "DITC01", CONFIG_DITTA);
 | ||
|     file = studio;
 | ||
|     file << "cesp/ditca";
 | ||
|     conv_par(file, "DITCA", CONFIG_DITTA);
 | ||
|     message_box("Conversione completata");
 | ||
|     close_log();        
 | ||
|   }    
 | ||
| }
 | ||
| 
 | ||
| void TConversione_cespiti::open_log() 
 | ||
| {                  
 | ||
|   TFilename log;
 | ||
|   
 | ||
|   log << "ceconv.log";
 | ||
|   _log = fopen(log,"w");
 | ||
|   if (_log == NULL)
 | ||
|     fatal_box(FR("Non posso aprire il file di log della conversione(%s)"), (const char *) log);
 | ||
| }
 | ||
| 
 | ||
| void TConversione_cespiti::write_log(const char * line)
 | ||
| {         
 | ||
|   fprintf(_log,"%s\n", line);
 | ||
| }
 | ||
| 
 | ||
| void TConversione_cespiti::close_log()
 | ||
| {
 | ||
|   fclose(_log);
 | ||
| }
 | ||
| 
 | ||
| int TConversione_cespiti::conv_file(const TFilename& ofname, int nflogicnum)
 | ||
| {       
 | ||
|   long oldditta = -1;
 | ||
|   TDir d;
 | ||
|   d.get(nflogicnum);
 | ||
|   d.eod() = 0L;
 | ||
|   d.put(nflogicnum);
 | ||
| 
 | ||
|   TExternisamfile oldfile(ofname,(bool) FALSE,(bool) FALSE);
 | ||
| 
 | ||
|   TLocalisamfile* newfile = NULL; 
 | ||
|   const TRectype& oldrec = oldfile.curr();
 | ||
|   TString s;
 | ||
|   s.format(FR("Conversione tabella %s"), (const char*) ofname);
 | ||
|   TProgind pi(oldfile.eod(), s, FALSE, TRUE);
 | ||
|   
 | ||
|   TAssoc_array converted;
 | ||
|       
 | ||
|   bool to_convert = FALSE;
 | ||
|   for (int err = oldfile.first(); err == NOERR; err = oldfile.next())
 | ||
|   {                 
 | ||
|     pi.addstatus(1);
 | ||
|     // mi posiziono sulla ditta indicata
 | ||
|     const long ditta = oldfile.get_long("CODDITTA");               
 | ||
|     // i record sono ordinati per ditta!                                        
 | ||
|     if (oldditta != ditta)
 | ||
|     {
 | ||
|       oldditta = ditta;
 | ||
|       to_convert = daconvertire(ditta);
 | ||
|       if (to_convert)
 | ||
|       {        
 | ||
|         if (newfile) 
 | ||
|           delete newfile;
 | ||
|         set_firm(ditta); 
 | ||
|         
 | ||
|         TString16 str_ditta; str_ditta.format("%ld", ditta);
 | ||
|         if (!converted.is_key(str_ditta))
 | ||
|         {
 | ||
|           zap_file(nflogicnum);
 | ||
|           converted.add(str_ditta);
 | ||
|         }
 | ||
|         
 | ||
|         newfile = new TLocalisamfile(nflogicnum);
 | ||
|       }
 | ||
|       else                                                      
 | ||
|       {
 | ||
|         s.format(FR("La ditta %ld indicata nel file %s non <20> stata selezionata per la conversione"), ditta, (const char*) ofname);
 | ||
|         write_log(s);
 | ||
|       } 
 | ||
|     } 
 | ||
|     if (!to_convert)
 | ||
|       continue;
 | ||
|         
 | ||
|     // creo nuovo record        
 | ||
|     CHECK(newfile, "Miii");
 | ||
|     TRectype& newrec = newfile->curr();
 | ||
|     newrec.zero();    
 | ||
|     // setto i campi con lo stesso nome
 | ||
|     for (int i = 0; i < oldrec.items(); i++)
 | ||
|     {                                                          
 | ||
|       const char* fieldname = oldrec.fieldname(i);
 | ||
|       if (newrec.exist(fieldname))  
 | ||
|       {
 | ||
|         newrec.put(fieldname, oldfile.get(fieldname));
 | ||
|         if ((newrec.type(fieldname) != oldrec.type(fieldname)) && (newrec.type(fieldname)==_alfafld))
 | ||
|         {                       
 | ||
|           s = newrec.get(fieldname);
 | ||
|           if (s.not_empty())   // Non riempire di zeri i campi vuoti!
 | ||
|             s.right_just(newrec.length(fieldname),'0');
 | ||
|           newrec.put(fieldname, s);
 | ||
|         } 
 | ||
|       } 
 | ||
|     }
 | ||
|     // setto i campi che vanno elaborati pirsunalmente di pirsuna (nomi diversi)
 | ||
|     switch (nflogicnum)
 | ||
|     {
 | ||
|       case 136:
 | ||
|         s.format("%04d",get_codesc(oldfile.get_date("DTINES")));
 | ||
|         newrec.put("CODES", s);
 | ||
|         break;
 | ||
|       case 138:
 | ||
|         s.format("%04d",get_codesc(oldfile.get_date("DTINES")));
 | ||
|         newrec.put("CODES", s);
 | ||
|         newrec.put("CODCGRA", oldfile.get("AG0CGR"));
 | ||
|         newrec.put("CODSPA", oldfile.get("ATACSP"));
 | ||
|         newrec.put("CODCGR", oldfile.get("G0CGR"));
 | ||
|         newrec.put("CODSP", oldfile.get("TACSP"));
 | ||
|         newrec.put("CODCAT", oldfile.get("G0CCT"));
 | ||
|         break;
 | ||
|       case 139:
 | ||
|         newrec.put("CODCGRA", oldfile.get("AG0CGR"));
 | ||
|         newrec.put("CODSPA", oldfile.get("ATACSP"));
 | ||
|         newrec.put("CODCGR", oldfile.get("G0CGR"));
 | ||
|         newrec.put("CODSP", oldfile.get("TACSP"));
 | ||
|         newrec.put("CODCAT", oldfile.get("G0CCT"));
 | ||
|         break;
 | ||
|       case 142:
 | ||
|         newrec.put("CODMOV", oldfile.get("TPMOV"));
 | ||
|         newrec.put("STAMPATO", oldfile.get("STBOLLATO"));
 | ||
|         break;
 | ||
|       case 143:
 | ||
|         s.format("%04d",get_codesc(oldfile.get_date("DTINES")));
 | ||
|         newrec.put("CODES", s);
 | ||
|         break;
 | ||
|     } 
 | ||
|     // scrivo il record sul nuovo file
 | ||
|     newfile->write();
 | ||
|   }  
 | ||
|   if (newfile) 
 | ||
|     delete newfile;
 | ||
|   return 0;
 | ||
| }
 | ||
| 
 | ||
| void TConversione_cespiti::zap_table(const char* tab) const
 | ||
| {   
 | ||
|   if (tab && *tab)
 | ||
|   { 
 | ||
|     TTable newtab(tab);
 | ||
|     for (newtab.first(); !newtab.eof(); newtab.next()) 
 | ||
|       newtab.remove();
 | ||
|   }
 | ||
|   if (tab && *tab)
 | ||
|   { 
 | ||
|     const bool tabella_comune = (tab[0] == '%');
 | ||
|     if (tabella_comune)
 | ||
|     {
 | ||
|       TSystemisamfile f(LF_TABCOM);
 | ||
|       f.pack();
 | ||
|     }
 | ||
|     else  
 | ||
|     {
 | ||
|       TSystemisamfile f(LF_TAB);
 | ||
|       f.pack();
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| int TConversione_cespiti::conv_tab(const TFilename& ofname, const char* tab)
 | ||
| {       
 | ||
|   long oldditta = -1, ditta = -1;
 | ||
|   TExternisamfile oldfile(ofname,(bool)FALSE,(bool)FALSE);
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|   TTable* newfile = NULL;  
 | ||
|   TConfig config("ce0900.ini", tab);
 | ||
|   TAssoc_array& fieldlist = config.list_variables();
 | ||
|   const TString16 campoditta = config.get(CAMPODITTA);
 | ||
|   TString fieldname, fieldvalue;
 | ||
|   TAssoc_array converted;
 | ||
|  
 | ||
|   const bool tabella_comune = (tab[0] == '%');
 | ||
|     
 | ||
|   TString80 message;
 | ||
|   message.format(FR("Conversione tabella %s"), (const char*)ofname);
 | ||
|   TProgind pi(oldfile.eod(), message, FALSE, TRUE);
 | ||
|   
 | ||
|   bool to_convert = TRUE;
 | ||
|   for (int err = oldfile.first(); err == NOERR; err = oldfile.next())
 | ||
|   {                 
 | ||
|     pi.addstatus(1);
 | ||
|     if (!tabella_comune)
 | ||
|       ditta = oldfile.get_long(campoditta);               
 | ||
|     // mi posiziono sulla ditta indicata
 | ||
|     // i record sono ordinati per ditta!                                        
 | ||
|     if (oldditta != ditta)
 | ||
|     {
 | ||
|       oldditta = ditta;
 | ||
|       to_convert = daconvertire(ditta);
 | ||
|       if (to_convert)
 | ||
|       {
 | ||
|         if (newfile)
 | ||
|           delete newfile;
 | ||
|         set_firm(ditta); 
 | ||
|           
 | ||
|         TString16 str_ditta; str_ditta.format("%ld", ditta);
 | ||
|         if (!converted.is_key(str_ditta)) 
 | ||
|         {
 | ||
|           zap_table(tab);
 | ||
|           converted.add(str_ditta);
 | ||
|         }
 | ||
|         newfile = new TTable(tab);
 | ||
|       }
 | ||
|       else                                                      
 | ||
|       {
 | ||
|         TString256 s;
 | ||
|         s.format(FR("La ditta %ld indicata nel file %s non <20> stata selezionata per la conversione"), ditta, (const char*)ofname);
 | ||
|         write_log(s);
 | ||
|         continue;
 | ||
|       } 
 | ||
|     }
 | ||
|     if (!to_convert)
 | ||
|       continue;
 | ||
| 
 | ||
|     // creo nuovo record (Serve per tabelle comuni!)
 | ||
|     if (newfile == NULL)
 | ||
|       newfile = new TTable(tab);
 | ||
|     TRectype newrec = newfile->curr();
 | ||
|     newrec.zero();    
 | ||
|     // setto i campi indicati                   
 | ||
|     FOR_EACH_ASSOC_STRING(fieldlist, obj, key, str)
 | ||
|     {                 
 | ||
|       fieldname = key;
 | ||
|       fieldvalue = str;
 | ||
|       if ((fieldname != CAMPODITTA) && (fieldvalue[0]!='!') && (fieldvalue[0]!='?'))
 | ||
|         newrec.put(key, oldfile.get(str));
 | ||
|       else
 | ||
|       {
 | ||
|         if (fieldvalue[0] == '?')
 | ||
|           newrec.put(key,fieldvalue.sub(1));
 | ||
|         else if (fieldvalue == "!_ESERCIZIO2")
 | ||
|         {
 | ||
|           TString16 codtab, tmp;
 | ||
|           codtab.format("%04d",get_codesc(oldfile.get_date("CBDTI"), TRUE));
 | ||
|           tmp = oldfile.get("CBCGR");
 | ||
|           tmp.right_just(2,'0');
 | ||
|           codtab << tmp;
 | ||
|           tmp = oldfile.get("CBCSP");
 | ||
|           codtab << tmp;
 | ||
|           newrec.put(key, codtab);
 | ||
|         }
 | ||
|         else if (fieldvalue == "!_ESERCIZIO")
 | ||
|         {
 | ||
|           TString8 codtab;
 | ||
|           codtab.format("%04d",get_codesc(oldfile.get_date("CADTI")));
 | ||
|           newrec.put(key, codtab);
 | ||
|         }
 | ||
|         else if (fieldvalue == "!_CODIMP")
 | ||
|         {
 | ||
|           TString80 codtab;
 | ||
|           const TString& codimp = oldfile.get("CODIMP");
 | ||
|           if (!real::is_null(codimp))
 | ||
|           {
 | ||
|             codtab = codimp;
 | ||
|             codtab.right_just(10,'0');
 | ||
|           }
 | ||
|           newrec.put(key, codtab);
 | ||
|         }
 | ||
|         else if (fieldvalue == "!_CODLOC")
 | ||
|         {
 | ||
|           TString80 codtab;
 | ||
|           const TString& codloc = oldfile.get("CODLOC");
 | ||
|           if (!real::is_null(codloc))
 | ||
|           {
 | ||
|             codtab = codloc;
 | ||
|             codtab.right_just(10,'0');
 | ||
|           }
 | ||
|           newrec.put(key, codtab);
 | ||
|         }
 | ||
|         else if (fieldvalue == "!_CAT1")
 | ||
|         {
 | ||
|           TString16 codtab;
 | ||
|           const int gruppo = oldfile.get_int("TACGR");
 | ||
|           const TString16 specie(oldfile.get("TACSP"));
 | ||
|           codtab.format("%02d%s", gruppo,(const char*) specie);
 | ||
|           newrec.put(key, codtab);
 | ||
|         }
 | ||
|         else if (fieldvalue == "!_CAC1")
 | ||
|         {
 | ||
|           TString16 codtab;
 | ||
|           const int gruppo = oldfile.get_int("G0CGR");
 | ||
|           const TString16 specie(oldfile.get("TACSP"));
 | ||
|           const int categoria(oldfile.get_int("G0CCT"));
 | ||
|           if (gruppo == 0)
 | ||
|             codtab.format("      %02d",categoria);
 | ||
|           else
 | ||
|             codtab.format("%02d%-4s%02d", gruppo,(const char*) specie, categoria);
 | ||
|           newrec.put(key, codtab);
 | ||
|         }
 | ||
|         else if (fieldvalue == "!_CAC2")
 | ||
|         {
 | ||
|           TString80 codtab;
 | ||
|           int cod = oldfile.get_int("G0TCS");
 | ||
|           newrec.put(key, cod - 1);
 | ||
|         }
 | ||
|         else if (fieldvalue == "!_CLM1")
 | ||
|         {
 | ||
|           TString80 codtab;
 | ||
|           TDate data = oldfile.get_date("DTVALIM");
 | ||
|           codtab.format("%04d%2d%02d",data.year(),data.month(),data.day());
 | ||
|           newrec.put(key, codtab);
 | ||
|         }
 | ||
|         else if (fieldvalue == "!_CGR1")
 | ||
|         {
 | ||
|           TString80 codtab;
 | ||
|           codtab.format("%02d",oldfile.get_int("G0CGR"));
 | ||
|           newrec.put(key, codtab);
 | ||
|         }
 | ||
|         else if (fieldvalue == "!_TMC1")
 | ||
|         {
 | ||
|           TString80 cod = "";
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP01"));
 | ||
|           cod << " ";
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP03"));
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP04"));
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP05"));
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP06"));
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP07"));
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP08"));
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP09"));
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP10"));
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP11"));
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP12"));
 | ||
|           cod << conv_imptmc(oldfile.get_int("IMP13"));
 | ||
|           newrec.put(key, cod);
 | ||
|         }        
 | ||
|         else if (fieldvalue == "!_TMC2")
 | ||
|         {
 | ||
|           int num = oldfile.get_int("M0TTBL");
 | ||
|           TString16 cod;
 | ||
|           switch (num)
 | ||
|           {
 | ||
|             case 1:  
 | ||
|               cod = "I";
 | ||
|             break;  
 | ||
|             case 2:  
 | ||
|               cod = "E";
 | ||
|             break;  
 | ||
|             case 3:  
 | ||
|               cod = "P";
 | ||
|             break;  
 | ||
|             case 4:  
 | ||
|               cod = "R";
 | ||
|             break;  
 | ||
|             case 5:  
 | ||
|               cod = " ";
 | ||
|             break;  
 | ||
|             default:  
 | ||
|               cod = " ";
 | ||
|           }
 | ||
|           newrec.put(key, cod);
 | ||
|         }
 | ||
|         else if (fieldvalue == "!_TMC3")
 | ||
|         {
 | ||
|           TString16 cod;
 | ||
|           int num = oldfile.get_int("M0SEGN");
 | ||
|           switch (num)
 | ||
|           {
 | ||
|           case 1: 
 | ||
|             cod = "=";
 | ||
|           break;
 | ||
|           case 2:
 | ||
|             cod = "+";
 | ||
|           break;
 | ||
|           case 3:
 | ||
|             cod = "-";
 | ||
|           break;
 | ||
|           default:
 | ||
|           cod = " ";
 | ||
|           }
 | ||
|           newrec.put(key, cod);
 | ||
|         }  
 | ||
|         else if (fieldvalue == "!_CCE1")
 | ||
|         {
 | ||
|           TString16 cod;
 | ||
|           int num = oldfile.get_int("CATAR");
 | ||
|           switch (num)
 | ||
|           {
 | ||
|           case 1: 
 | ||
|             cod = "+";
 | ||
|           break;
 | ||
|           case 2:
 | ||
|             cod = "-";
 | ||
|           break;
 | ||
|           case 3:
 | ||
|             cod = "/";
 | ||
|           break;
 | ||
|           default:
 | ||
|           cod = " ";
 | ||
|           }
 | ||
|           newrec.put(key, cod);
 | ||
|         }
 | ||
|       } 
 | ||
|     }  
 | ||
|     // scrivo il record sul nuovo file
 | ||
|     newrec.write(*newfile);
 | ||
|   }  
 | ||
|   if (newfile)
 | ||
|     delete newfile;
 | ||
|   return 0;
 | ||
| }
 | ||
| 
 | ||
| int TConversione_cespiti::conv_inifile(const TFilename& ofname, const char* ofpar, int nflogicnum)
 | ||
| {       
 | ||
|   long oldditta = -1;
 | ||
|   long ditta;
 | ||
|   TDir d;
 | ||
|   d.get(nflogicnum);
 | ||
|   d.eod() = 0L;
 | ||
|   d.put(nflogicnum);
 | ||
|   TSystemisamfile f(nflogicnum);
 | ||
|   int err = f.pack();
 | ||
|   if (err == NOERR)
 | ||
|   {
 | ||
|     TExternisamfile oldfile(ofname,(bool)FALSE,(bool)FALSE);
 | ||
| 
 | ||
|     TLocalisamfile* newfile = new TLocalisamfile(nflogicnum);   
 | ||
|     TConfig config("ce0900.ini", (const char*) ofpar);
 | ||
|     TAssoc_array& fieldlist = config.list_variables();
 | ||
|     TString& campoditta = (TString&) config.get(CAMPODITTA);
 | ||
|     TString fieldname, fieldvalue;
 | ||
|     TRectype oldrec = oldfile.curr();
 | ||
|     TRectype newrec = newfile->curr();
 | ||
|     TString80 message;
 | ||
|     message.format(FR("Conversione tabella %s"), (const char*) ofname);
 | ||
|     TProgind pi(oldfile.eod(),message, FALSE, TRUE, 10);
 | ||
|     for (int err = oldfile.first(); err == NOERR; err = oldfile.next())
 | ||
|     {                 
 | ||
|       pi.addstatus(1);
 | ||
|       // mi posiziono sulla ditta indicata
 | ||
|       ditta = oldfile.get_long(campoditta);               
 | ||
|       // i record sono ordinati per ditta!                                        
 | ||
|       if (oldditta != ditta)
 | ||
|       {
 | ||
|         oldditta = ditta;
 | ||
|         if (daconvertire(ditta))
 | ||
|           set_firm(ditta);                                        
 | ||
|         else            
 | ||
|         {
 | ||
|           TString256 s;
 | ||
|           s.format(FR("La ditta %ld indicata nel file %s non <20> stata selezionata per la conversione"), ditta, (const char*) ofname);
 | ||
|           write_log(s);
 | ||
|           continue;
 | ||
|         } 
 | ||
|       }  
 | ||
|       // creo nuovo record        
 | ||
|       newrec.zero();    
 | ||
|       // setto i campi indicati                   
 | ||
|       FOR_EACH_ASSOC_STRING(fieldlist, obj, key, str)
 | ||
|       {                 
 | ||
|         fieldname = key;
 | ||
|         fieldvalue = str;
 | ||
|         if ((fieldname != CAMPODITTA) && (fieldvalue[0]!='!'))
 | ||
|           newrec.put(key, oldfile.get(str));
 | ||
|         else
 | ||
|         {
 | ||
|           if (fieldvalue.mid(0,4) == "!_GR")
 | ||
|           {
 | ||
|             TString80 tmp;
 | ||
|             tmp = oldfile.get(fieldvalue.mid(5));
 | ||
|             newrec.put(key,atoi(tmp.mid(0,3)));
 | ||
|           }
 | ||
|           else if (fieldvalue.mid(0,4) == "!_CO")
 | ||
|           {
 | ||
|             TString80 tmp;
 | ||
|             tmp = oldfile.get(fieldvalue.mid(5));
 | ||
|             newrec.put(key,atoi(tmp.mid(3,3)));
 | ||
|           }
 | ||
|           else if (fieldvalue.sub(0,4) == "!_SO")
 | ||
|           {
 | ||
|             TString80 tmp;
 | ||
|             tmp = oldfile.get(fieldvalue.mid(5));
 | ||
|             newrec.put(key,atol(tmp.mid(6,6)));
 | ||
|           }
 | ||
|         } 
 | ||
|       } 
 | ||
|       // scrivo il record sul nuovo file
 | ||
|       newrec.write(*newfile);
 | ||
|     }
 | ||
|     delete newfile;
 | ||
|   }
 | ||
|   else  
 | ||
|     error_box(FR("Errore in compattamento dati.\nFile %d : %d"), nflogicnum,err);
 | ||
|   return 0;
 | ||
| }
 | ||
| 
 | ||
| int TConversione_cespiti::conv_par(const TFilename& ofname, const char* ofpar, int which_config)
 | ||
| {       
 | ||
|   long oldditta = -1;
 | ||
|   long ditta;
 | ||
|   TExternisamfile oldfile(ofname,(bool)FALSE,(bool)FALSE);
 | ||
| 
 | ||
|   TConfig newconfig(which_config, "ce");
 | ||
|   TConfig config("ce0900.ini", (const char*) ofpar);
 | ||
|   TAssoc_array& fieldlist = config.list_variables();
 | ||
|   TString& campoditta = (TString&) config.get(CAMPODITTA);
 | ||
|   TString fieldname, fieldvalue;
 | ||
|   TRectype oldrec = oldfile.curr();
 | ||
|   TString80 message;
 | ||
|   message.format(FR("Conversione tabella %s"), (const char*) ofname);
 | ||
|   TProgind pi(oldfile.eod(),message, FALSE, TRUE);
 | ||
|   for (int err = oldfile.first(); err == NOERR; err = oldfile.next())
 | ||
|   {                 
 | ||
|     pi.addstatus(1);
 | ||
|     if (campoditta.not_empty())
 | ||
|     {
 | ||
|       // mi posiziono sulla ditta indicata
 | ||
|       ditta = oldfile.get_long(campoditta);               
 | ||
|       // i record sono ordinati per ditta!                                        
 | ||
|       if (oldditta != ditta)
 | ||
|       {
 | ||
|         oldditta = ditta;
 | ||
|         if (daconvertire(ditta))
 | ||
|         {
 | ||
|           set_firm(ditta);                                        
 | ||
|           newconfig.set_paragraph("cg");
 | ||
|           newconfig = TConfig(which_config, "ce");
 | ||
|         } 
 | ||
|         else                                                      
 | ||
|         {
 | ||
|           TString256 s;
 | ||
|           s.format(FR("La ditta %ld indicata nel file %s non <20> stata selezionata per la conversione"), ditta, (const char*) ofname);
 | ||
|           write_log(s);
 | ||
|           continue;
 | ||
|         } 
 | ||
|       } 
 | ||
|     } 
 | ||
|     // setto i campi indicati                   
 | ||
|     FOR_EACH_ASSOC_STRING(fieldlist, obj, key, str)
 | ||
|     {                 
 | ||
|       fieldname = key;
 | ||
|       fieldvalue = str;
 | ||
|       if ((fieldname != CAMPODITTA) && (fieldvalue[0]!='!'))
 | ||
|         newconfig.set(key,  oldfile.get(str));
 | ||
|       else
 | ||
|       {
 | ||
|         if (fieldvalue.mid(0,4) == "!_GR")
 | ||
|         {
 | ||
|           TString80 tmp;
 | ||
|           tmp = oldfile.get(fieldvalue.mid(5));
 | ||
|           newconfig.set(key,atoi(tmp.mid(0,3)));
 | ||
|         }
 | ||
|         else if (fieldvalue.mid(0,4) == "!_CO")
 | ||
|         {
 | ||
|           TString80 tmp;
 | ||
|           tmp = oldfile.get(fieldvalue.mid(5));
 | ||
|           newconfig.set(key,atoi(tmp.mid(3,3)));
 | ||
|         }
 | ||
|         else if (fieldvalue.sub(0,4) == "!_SO")
 | ||
|         {
 | ||
|           TString80 tmp;
 | ||
|           tmp = oldfile.get(fieldvalue.mid(5));
 | ||
|           newconfig.set(key,atol(tmp.mid(6,6)));
 | ||
|         }
 | ||
|         else if (fieldvalue.sub(0,4) == "!_ES")
 | ||
|           newconfig.set(key,get_codesc(oldfile.get_date(fieldvalue.mid(5))));
 | ||
|         else if (fieldvalue.sub(0,4) == "!_AN")
 | ||
|         {
 | ||
|           TString80 tmp;
 | ||
|           tmp = oldfile.get(fieldvalue.mid(5));
 | ||
|           newconfig.set(key,tmp.mid(6));
 | ||
|         } 
 | ||
|       } 
 | ||
|     } 
 | ||
|     // verificare se occorre registrare (di solito si cambia paragrafo)
 | ||
|   }
 | ||
|   return 0;
 | ||
| }
 | ||
| 
 | ||
| int TConversione_cespiti::get_codesc(const TDate& date, const bool fatal)
 | ||
| {
 | ||
|   TEsercizi_contabili esercizi;
 | ||
|   int esc = esercizi.date2esc(date);
 | ||
|   if (esc <= 0)
 | ||
|   {
 | ||
|     TString s;
 | ||
|     s << TR("La ditta ") << get_firm() << TR(" non ha un esercizio con data iniziale ");
 | ||
|     s << date.string();
 | ||
|     write_log(s);
 | ||
|     if (fatal)
 | ||
|       fatal_box(s);
 | ||
|     else
 | ||
|       esc = date.year();
 | ||
|   }          
 | ||
|   return esc;
 | ||
| }
 | ||
| 
 | ||
| const char TConversione_cespiti::conv_imptmc(int cod)
 | ||
| {
 | ||
|   switch (cod)
 | ||
|   {
 | ||
|     case 1:
 | ||
|       return 'S';
 | ||
|     break;
 | ||
|     case 2:
 | ||
|       return 'N';
 | ||
|     break;
 | ||
|     case 3:
 | ||
|       return 'O';
 | ||
|     break;
 | ||
|     default:
 | ||
|       return ' ';
 | ||
|   }
 | ||
|   return ' ';   
 | ||
| }
 | ||
| 
 | ||
| //funzione che ritorna il nome del file dei dati da resettare con la zap_file
 | ||
| HIDDEN const TString& build_name(int logicnum)
 | ||
| {
 | ||
|   TDir d; d.get(logicnum, _nolock, _nordir, _sysdirop);
 | ||
|   static TFilename _filename;
 | ||
|   _filename = d.filename();  
 | ||
|   return _filename;
 | ||
| }
 | ||
| 
 | ||
| //funzione per resettare i files e gli indici
 | ||
| int TConversione_cespiti::zap_file(int lf) const
 | ||
| { 
 | ||
|   TFilename name = build_name(lf);
 | ||
|   if (name[0] == '%') name.ltrim(1);
 | ||
|   TExternisamfile f(name);
 | ||
|   return f.zap();
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| int ce0900(int argc, char* argv[])
 | ||
| {
 | ||
|   TConversione_cespiti a ;
 | ||
|   a.run(argc, argv, TR("Conversione cespiti"));
 | ||
|   return 0;
 | ||
| }
 |