Files correlati : ve0.exe Ricompilazione Demo : [ ] Commento : Riportata la versione 3.2 patch 1350 git-svn-id: svn://10.65.10.50/trunk@18385 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			5268 lines
		
	
	
		
			129 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			5268 lines
		
	
	
		
			129 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| // cglib04.cpp 
 | ||
| #include "cglib04.h"
 | ||
| #include "cgsaldac.h"
 | ||
| 
 | ||
| #include <codeb.h>         // RED ALERT!
 | ||
| 
 | ||
| #include <diction.h>
 | ||
| #include <extcdecl.h>
 | ||
| #include <progind.h>
 | ||
| #include <scanner.h>
 | ||
| #include <tabutil.h>
 | ||
| #include <utility.h>
 | ||
| 
 | ||
| const int sizeT = 256;     //Lunghezza del record del TRASFER
 | ||
| const int sizeH = 1024;    //Lunghezza del record dell'HEADER   
 | ||
| 
 | ||
| const int RIC_SIZE = 512;
 | ||
| 
 | ||
| const char* const tracciato_AS = "cgtrc.ini";  
 | ||
| const char* const tracciato_PC = "cgtrcpc.ini";    
 | ||
| 
 | ||
| bool format_if_zero(TString& field, int len)
 | ||
| {
 | ||
|   if (real::is_natural(field))
 | ||
|     field.right_just(len, '0');
 | ||
|   return true;
 | ||
| }
 | ||
| 
 | ||
| ////////////////////////////////////////////////////////////////////
 | ||
| // TRic_recfield                                                    
 | ||
| ////////////////////////////////////////////////////////////////////
 | ||
| 
 | ||
| HIDDEN void __getfieldbuff(int l, int t, const char* recin, char *s)
 | ||
| {
 | ||
|   if (recin == NULL)
 | ||
|   {
 | ||
|     *s = '\0';
 | ||
|     return;
 | ||
|   }
 | ||
|   
 | ||
|   if (t != _alfafld && t != _datefld)
 | ||
|   {                   
 | ||
|     if (t == _intzerofld || t == _longzerofld)
 | ||
|     {             
 | ||
|       byte i = 0;
 | ||
|       for (char* c = (char*)recin; i < l; c++, i++)
 | ||
|         if (*c == ' ') *c = '0';     
 | ||
|         else break;
 | ||
|       if (i == l) 
 | ||
|         l = 0;  
 | ||
|     }
 | ||
|     else                            
 | ||
|     {
 | ||
|       while ((*recin == ' ') && (l))
 | ||
|       {
 | ||
|         recin++;
 | ||
|         l--;
 | ||
|       }
 | ||
|       if ((t != _realfld) && (t != _charfld))
 | ||
|       {
 | ||
|         while ((*recin == '0') && (l))
 | ||
|         {
 | ||
|           recin++;
 | ||
|           l--;
 | ||
|         }
 | ||
|       }
 | ||
|     }  
 | ||
|   }
 | ||
| 
 | ||
|   if (l)
 | ||
|   {
 | ||
|     strncpy(s, recin, l);
 | ||
| //    for (int i = l-1; i >= 0 && s[i] == ' '; i--);
 | ||
| //    l = byte(i+1);
 | ||
|   }
 | ||
|   s[l] = '\0'; 
 | ||
|   if (*s)
 | ||
|   {
 | ||
|     if (t == _datefld)
 | ||
|     {       
 | ||
|       const TDate dt(atol(s));
 | ||
|       strcpy(s, dt.string(full));  
 | ||
|     } else
 | ||
|       if (t == _boolfld)
 | ||
|       {
 | ||
|         const char ok = toupper(*s);
 | ||
|         if (ok == 'T' || ok == 'Y' || ok == 'S' || ok == 'X')
 | ||
|           strcpy(s,"X");
 | ||
|         else
 | ||
|           strcpy(s," ");
 | ||
|       }    
 | ||
|   }
 | ||
| } 
 | ||
| 
 | ||
| void setdec(char * s,int dec) 
 | ||
| {
 | ||
|   char    *s1;
 | ||
|   int     i, l, carry;
 | ||
|   
 | ||
|   if (strlen(s) == 0) strcpy(s, "0");
 | ||
|   if ((s1 = strchr(s, ',')) != NULL) *s1 = '.';
 | ||
|   s1 = strchr(s, '.');
 | ||
|   if ((dec) && (s1 == NULL))
 | ||
|   {
 | ||
|     strcat(s, ".");
 | ||
|     s1 = strchr(s, '.');
 | ||
|   }
 | ||
|   else
 | ||
|     if (!dec) 
 | ||
|     {
 | ||
|       if (s1 == NULL) return ;
 | ||
|       l = strlen(s1); /* occhio verificare */
 | ||
|       carry = (s1[1] >= '5');
 | ||
|       *s1 = '\0';
 | ||
|       while (carry)
 | ||
|       {
 | ||
|         s1--;
 | ||
|         if (*s1 == '-') break;
 | ||
|         if (*s1 == '9')
 | ||
|         {
 | ||
|           *s1 = '0';
 | ||
|           if (s == s1) break;
 | ||
|         }
 | ||
|         else
 | ||
|         {
 | ||
|           (*s1)++;
 | ||
|           carry = false;
 | ||
|         }
 | ||
|       }
 | ||
|       if (carry)
 | ||
|       {
 | ||
|         for (i = l; i > int(*s1 == '-'); i--) s[i] = s[i - 1];
 | ||
|         s[(*s1 == '-')] = '1';
 | ||
|       }
 | ||
|       return;
 | ||
|     }
 | ||
|   s1++;
 | ||
|   l = strlen(s1);
 | ||
|   if (l > dec)
 | ||
|   {
 | ||
|     carry = (s1[dec] >= '5');
 | ||
|     s1[dec] = '\0';
 | ||
|     while (carry)
 | ||
|     {
 | ||
|       dec--;
 | ||
|       if (s1[dec] == '9')
 | ||
|       {
 | ||
|         s1[dec] = '0';
 | ||
|         if (!dec) break;
 | ||
|       }
 | ||
|       else
 | ||
|       {
 | ||
|         s1[dec]++;
 | ||
|         carry = false;
 | ||
|       }
 | ||
|     }
 | ||
|     s1--;
 | ||
|     while (carry)
 | ||
|     {
 | ||
|       s1--;
 | ||
|       if (*s1 == '-') break;
 | ||
|       if (*s1 == '9')
 | ||
|       {
 | ||
|         *s1 = '0';
 | ||
|         if (s == s1) break;
 | ||
|       }
 | ||
|       else
 | ||
|       {
 | ||
|         (*s1)++;
 | ||
|         carry = false;
 | ||
|       }
 | ||
|     }
 | ||
|     if (carry)
 | ||
|     {
 | ||
|       for (i = l; i > int(*s1 == '-'); i--) s[i] = s[i - 1];
 | ||
|       s[(*s1 == '-')] = '1';
 | ||
|     }
 | ||
|   }
 | ||
|   else
 | ||
|     while (l++ < dec) strcat(s1, "0");
 | ||
| }
 | ||
| 
 | ||
| HIDDEN void  __putfieldbuff(int l, int d, int t, const char* s, char* recout)
 | ||
| {
 | ||
|   int len, i;
 | ||
| 
 | ||
|   if (recout == NULL) return;
 | ||
| 
 | ||
|   char s2[RIC_SIZE];
 | ||
|   strcpy(s2, s);
 | ||
| 
 | ||
|   if (t == _datefld)
 | ||
|   {
 | ||
|     if (*s2)
 | ||
|     {
 | ||
|       const TDate dt(s2);
 | ||
|       sprintf(s2,"%8s", dt.string(ANSI));
 | ||
|     }
 | ||
|   }
 | ||
|   else
 | ||
|     if (t == _boolfld)
 | ||
|     {           
 | ||
|       const char ok = toupper(*s2);
 | ||
|       if (ok == 'T' || ok == 'Y' || ok == 'S' || ok == 'X')
 | ||
|         strcpy(s2, "T");
 | ||
|       else
 | ||
|         strcpy(s2, "F");
 | ||
|     }
 | ||
|     else
 | ||
|       if (t == _realfld) setdec(s2, d);
 | ||
| 
 | ||
|   len = strlen(s2);
 | ||
|   
 | ||
|   if (len > l) 
 | ||
|   {
 | ||
|     yesnofatal_box(FR("Impossibile scrivere %d caratteri su di un campo di %d"), (int)len, (int)l);
 | ||
|     return;
 | ||
|   }  
 | ||
|   
 | ||
|   if ((t == _intfld)     ||
 | ||
|       (t == _longfld)    ||
 | ||
|       (t == _wordfld)    ||
 | ||
|       (t == _realfld)    ||
 | ||
|       (t == _intzerofld) ||
 | ||
|       (t == _longzerofld)
 | ||
|       )
 | ||
|   {
 | ||
|     if (len == 0)
 | ||
|     {
 | ||
|       strcpy(s2, "0");
 | ||
|       len = 1;
 | ||
|     } 
 | ||
|     
 | ||
|     const char c = (t == _intzerofld || t == _longzerofld) ? '0' : ' ';
 | ||
|     i = 0;
 | ||
|     while (i < l - len - 1) recout[i++] = c;
 | ||
|     strncpy(&recout[l - len - 1], s2, len) ;
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     strncpy(recout, s2, len) ;
 | ||
|     while (len < l) recout[len++] = ' ';
 | ||
|   }
 | ||
| } 
 | ||
| 
 | ||
| TRic_recfield::TRic_recfield(TRectype& rec, const char* name, int from, int len) 
 | ||
| {      
 | ||
|   strcpy(_name, name);
 | ||
|   _rec = &rec;
 | ||
|   set(from, len);  
 | ||
|   _len = len;     
 | ||
| }
 | ||
| 
 | ||
| void TRic_recfield::set(int from, int to)
 | ||
| 
 | ||
| {
 | ||
|   int nf;
 | ||
|   const RecDes& rd = _rec->rec_des();
 | ||
| 
 | ||
|   if ((nf = findfld(&rd, _name)) == -1)
 | ||
|   {
 | ||
|     _p = NULL;
 | ||
|     _len = 0;
 | ||
|     _dec = 0;
 | ||
|     _type = _nullfld;
 | ||
|     yesnofatal_box(FR("File n. %d unknown field %s"), _rec->num(), _name);
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     CHECK(from >= 0, "Invalid Start");
 | ||
|     _p = _rec->string() + rd.Fd[nf].RecOff + from;
 | ||
|     _dec = rd.Fd[nf].Dec;
 | ||
|     _type = rd.Fd[nf].TypeF;
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| const char* TRic_recfield::operator =(const char* s)
 | ||
| {
 | ||
|   __putfieldbuff( _len, _dec, _type, s, _p);
 | ||
|   _rec->setdirty();
 | ||
|   return s;
 | ||
| }
 | ||
| 
 | ||
| TRic_recfield::operator const char*() const
 | ||
| {                                  
 | ||
|   static char* _isam_string = NULL;
 | ||
|   if (_isam_string == NULL)
 | ||
|     _isam_string = new char[RIC_SIZE];
 | ||
| 
 | ||
|   __getfieldbuff( _len, _type, _p, _isam_string);
 | ||
|   return _isam_string;
 | ||
| }
 | ||
| 
 | ||
| // Ritorna il record di controllo del trasfer
 | ||
| const char* TTransfer_file::record() const 
 | ||
| {         
 | ||
|   return *_control_rec;
 | ||
| } 
 | ||
| 
 | ||
| TTransfer_file::TTransfer_file(char scelta)
 | ||
|               : _comuni2(LF_COMUNI, 2)
 | ||
| { 
 | ||
|   _trasfer     = NULL;    
 | ||
|   _tot_rec     = 0L;
 | ||
|   _numreg_p    = 0L;
 | ||
|   _numreg_piva = 0L;
 | ||
|   _scelta      = scelta;
 | ||
|   _control_rec = new TString(LEN_REC_HEAD);
 | ||
|   switch (scelta)
 | ||
|   {
 | ||
|   case 'S': _trc.leggi_modulo(tracciato_AS); break;
 | ||
|   case 'P': _trc.leggi_modulo(tracciato_PC); break;
 | ||
|   default : break;
 | ||
|   }
 | ||
|       
 | ||
|   _tpcon = NULL;    
 | ||
| 
 | ||
|   _npoccas = 0L;
 | ||
| }
 | ||
| 
 | ||
| TTransfer_file::~TTransfer_file()
 | ||
| {
 | ||
|   delete _control_rec;
 | ||
|   if (_trasfer) 
 | ||
|     fclose (_trasfer);                             
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::close()
 | ||
| {
 | ||
|   if (_trasfer) 
 | ||
|     fclose(_trasfer);
 | ||
| }
 | ||
| 
 | ||
| bool TTransfer_file::open(const char* path, bool create)
 | ||
| {
 | ||
|   if (_trasfer) 
 | ||
|     fclose(_trasfer);
 | ||
| 
 | ||
|   const char* mode = create ? "a+t" : "r+t";
 | ||
|   _trasfer = fopen (path, mode);
 | ||
| 
 | ||
|   return _trasfer != NULL;
 | ||
| }
 | ||
| 
 | ||
| const char* TTransfer_file::path(long codditta)
 | ||
| {
 | ||
|   if (codditta == 0)
 | ||
|     codditta = prefix().get_codditta();
 | ||
|   return firm2dir(codditta);
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::remove_all(bool file_ditta)
 | ||
| {                           
 | ||
|   TString sigle;
 | ||
|   TString dir,trasfer;
 | ||
|   
 | ||
|   if (file_ditta)    
 | ||
|   {             
 | ||
|     const long ditta = prefix().get_codditta();
 | ||
|     dir << firm2dir(ditta);
 | ||
|     trasfer = dir;
 | ||
|     dir << HEADER;
 | ||
|     trasfer << "\\trasfer";
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     dir << firm2dir(0);
 | ||
|     trasfer = dir;
 | ||
|     dir << HEADER;
 | ||
|     trasfer << "\\trasfer";
 | ||
|   }
 | ||
|   
 | ||
|   if (fexist(trasfer))
 | ||
|     ::remove(trasfer);
 | ||
|       
 | ||
|   open(dir,false);
 | ||
|   read_control_rec();
 | ||
|   sigle = sigle_file();
 | ||
|   sigle.trim();
 | ||
|   close(); 
 | ||
|   ::remove(dir); // Rimuove l'header
 | ||
|   dir = "";                                    
 | ||
|   if (file_ditta)
 | ||
|   {
 | ||
|     const long ditta = prefix().get_codditta();
 | ||
|     dir << firm2dir(ditta);
 | ||
|   }  
 | ||
|   else
 | ||
|     dir << firm2dir(0);
 | ||
|   
 | ||
|   
 | ||
|   for (int i = 0; i < sigle.len(); i++)
 | ||
|   {
 | ||
|     char sigla = sigle[i];
 | ||
|   
 | ||
|     if (sigla == 'W')
 | ||
|     {
 | ||
|       TFilename path(dir);
 | ||
|       path.add("tcaus.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);
 | ||
|       path = dir;
 | ||
|       path.add("trcaus.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);
 | ||
|     }
 | ||
|     if (sigla == 'A')
 | ||
|     {
 | ||
|       TFilename path(dir);
 | ||
|       path.add("tclifo.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);
 | ||
|       path.ext("fpt");
 | ||
|       ::remove(path);
 | ||
|     }
 | ||
|     if (sigla == 'P')
 | ||
|     {
 | ||
|       TFilename path(dir);
 | ||
|       path.add("tpcon.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);
 | ||
|     }
 | ||
|     if (sigla == 'Z')
 | ||
|     {
 | ||
|       TFilename path(dir);
 | ||
|       path.add("tmov.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);
 | ||
|       path = dir;
 | ||
|       path.add("trmov.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);
 | ||
|     }
 | ||
|     if (sigla == 'U')
 | ||
|     {
 | ||
|       TFilename path(dir);
 | ||
|       path.add("trmoviva.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);
 | ||
|       path = dir;
 | ||
|       path.add("toccas.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);      
 | ||
|     }               
 | ||
|     if (sigla == 'B')
 | ||
|     {
 | ||
|       TFilename path(dir);
 | ||
|       path.add("tpart.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);
 | ||
|       path = dir;
 | ||
|       path.add("tscad.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);
 | ||
|       path = dir;
 | ||
|       path.add("tpagsca.dbf");
 | ||
|       ::remove(path);
 | ||
|       path.ext("cdx");
 | ||
|       ::remove(path);
 | ||
|     }    
 | ||
|   } 
 | ||
| }
 | ||
| 
 | ||
| bool TTransfer_file::read_control_rec()
 | ||
| {
 | ||
|   if (_trasfer == NULL || !exist()) 
 | ||
|     return false;
 | ||
|   
 | ||
|   // va all'inizio del file
 | ||
|   fseek(_trasfer, 0L, SEEK_SET); 
 | ||
|   const word letti = fread(_control_rec->get_buffer(sizeH), 1, sizeH, _trasfer);  
 | ||
|   _control_rec->cut(sizeH);
 | ||
|   
 | ||
|   _tiporec  = _control_rec->left(2);
 | ||
|   if (_tiporec != " 1")
 | ||
|     return false;
 | ||
| 
 | ||
|   _nome_simb  = _control_rec->sub(60,70);
 | ||
|   _ditta      = atol(_control_rec->sub(70,75));
 | ||
|   _nultras    = atoi(_control_rec->sub(75,78));
 | ||
|   
 | ||
|   const TString& tmp = _control_rec->sub(78,86);
 | ||
|   _dataultras = converti(tmp,true);
 | ||
|   
 | ||
|   _sigle_file = _control_rec->sub(86,95); _sigle_file.rtrim();
 | ||
|   _nrec_file  = _control_rec->sub(95,149); 
 | ||
|   _ult_file   = _control_rec->sub(240,241); _ult_file.trim();
 | ||
|   _key        = _control_rec->sub(241,301); _key.trim();
 | ||
|   fill_index(_sigle_file, _nrec_file);
 | ||
|   
 | ||
|   return true;
 | ||
| }
 | ||
| 
 | ||
| bool TTransfer_file::read_control_rec_t()
 | ||
| {
 | ||
|   if (!exist()) 
 | ||
|     return false;
 | ||
|   
 | ||
|   // va all'inizio del file
 | ||
|   fseek (_trasfer, 0L, SEEK_SET);
 | ||
|   const word letti = fread((char*)(const char*)_control_rec_t,sizeof(char),sizeT,_trasfer);
 | ||
|   
 | ||
|   _tiporec  = _control_rec_t.sub(0,2);
 | ||
|   
 | ||
|   if (_tiporec == " 1")
 | ||
|   {    
 | ||
|     _nome_simb  = _control_rec_t.sub(15,25);
 | ||
|     _ditta      = atol(_control_rec_t.sub(25,29));
 | ||
|     _nultras    = atoi(_control_rec_t.sub(29,32));
 | ||
|     const TString8 tmp = _control_rec_t.sub(32,38);
 | ||
|     _dataultras = converti(tmp,false);
 | ||
|     
 | ||
|     _sigle_file = _control_rec_t.sub(38,47);
 | ||
|     _nrec_file  = _control_rec_t.sub(47,101); 
 | ||
|     _ult_file = _control_rec_t.sub(240,241);
 | ||
|     _ult_file = _ult_file.trim();
 | ||
|     _key      = _control_rec_t.sub(241,256);
 | ||
|     _key      = _key.trim();
 | ||
|     fill_index(_sigle_file,_nrec_file);
 | ||
|   }
 | ||
|   else
 | ||
|     return false;
 | ||
|   
 | ||
|   return true;
 | ||
| }
 | ||
| 
 | ||
| bool TTransfer_file::write_control_rec(const char* str, const int size)
 | ||
| {
 | ||
|   if (!exist()) return false;
 | ||
|   
 | ||
|   fseek(_trasfer, 0, SEEK_SET);
 | ||
|   const int nscritti = fwrite (str,1,size,_trasfer);
 | ||
|   
 | ||
|   return true;
 | ||
| }
 | ||
| 
 | ||
| const char* TTransfer_file::name(int i)
 | ||
| {
 | ||
|   TToken_string* data = (TToken_string*)_index.objptr(i);
 | ||
|   return data ? data->get(0) : "";
 | ||
| }
 | ||
| 
 | ||
| long TTransfer_file::nrec(int i)      
 | ||
| {
 | ||
|   TToken_string* data = (TToken_string*)_index.objptr(i);
 | ||
|   return data ? data->get_long(1) : 0L;
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::lenrec(int i)
 | ||
| {
 | ||
|   TToken_string* data = (TToken_string*)_index.objptr(i);
 | ||
|   return data ? data->get_int(2) : 0;
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::lenrec(char sigla)
 | ||
| {
 | ||
|   const int i = num(sigla);
 | ||
|   return lenrec(i);
 | ||
| }
 | ||
| 
 | ||
| long TTransfer_file::start(char sigla)
 | ||
| {
 | ||
|   const int i = num(sigla);
 | ||
|   return start(i);
 | ||
| }
 | ||
| 
 | ||
| long TTransfer_file::start(int i)
 | ||
| {
 | ||
|   if (i == 0)
 | ||
|     return 1;
 | ||
|   else
 | ||
|   {
 | ||
|     TToken_string& data = (TToken_string&)_index[i-1];
 | ||
|     return data.get_long(1) + 1;
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| long TTransfer_file::end(int i)
 | ||
| {
 | ||
|   TToken_string& data = (TToken_string&)_index[i];
 | ||
|   return data.get_long(4);
 | ||
| }
 | ||
| 
 | ||
| long TTransfer_file::rec(int i)
 | ||
| {   
 | ||
|   long rec = 1;
 | ||
|   
 | ||
|   if (i > 0)
 | ||
|   { 
 | ||
|     TToken_string& data = (TToken_string&)_index[i-1];
 | ||
|     rec = (data.get_long(1)) + 1;
 | ||
|   }
 | ||
|   
 | ||
|   return rec;
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::num(char sigla)  
 | ||
| {
 | ||
|   const int items = _index.items(); 
 | ||
|   for (int i = 0; i < items; i++)
 | ||
|   {
 | ||
|     const char* dep = name(i);
 | ||
|     if ( dep[0] == sigla) 
 | ||
|       return i; 
 | ||
|   }
 | ||
|   
 | ||
|   return -1;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::go2rec(const long recnum)
 | ||
| {
 | ||
|   readat(recnum);
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::readat(long recnum)
 | ||
| {       
 | ||
|   long pos,offset;
 | ||
|   
 | ||
|   // name_file | numrec | lenrec | start | end      ESEMPIO
 | ||
|   //     w     |  100   |   82   |   0   | 8199       DI
 | ||
|   //     p     |  130   |   40   |  8200 | 9399     INDICE
 | ||
|   
 | ||
|   int items = _index.items();
 | ||
| 	int i;
 | ||
|   
 | ||
|   for (i = 0; i < items; i++) 
 | ||
|   {      
 | ||
|     if (recnum <= nrec(i))       
 | ||
|     {                           
 | ||
|       if (i > 0)                
 | ||
|       {  
 | ||
|         pos    = end(i-1) + 1;
 | ||
|         offset = recnum - nrec(i-1);
 | ||
|         pos   += offset * lenrec(i);
 | ||
|       }
 | ||
|       else
 | ||
|       {       
 | ||
|         pos = recnum * lenrec(i); 
 | ||
|       }                           
 | ||
|       break;                    
 | ||
|     }                            
 | ||
|   }                              
 | ||
|   _curpos  = recnum;
 | ||
|   _curfile = name(i);
 | ||
|   fseek(_trasfer,pos,SEEK_SET);
 | ||
| } 
 | ||
| 
 | ||
| int TTransfer_file::read_rec_trasfer(long numrec, int size)
 | ||
| {
 | ||
|   go2rec(numrec);
 | ||
|   const word letti = fread((char*)(const char*)_record,sizeof(char),size,_trasfer);
 | ||
|   return letti;
 | ||
| }
 | ||
| 
 | ||
| char TTransfer_file::flg_agg(char sigla) const
 | ||
| { 
 | ||
|   char flag;
 | ||
|   switch (sigla)
 | ||
|   {
 | ||
|   case 'W': flag = (*_control_rec)[235]; break;
 | ||
|   case 'A': flag = (*_control_rec)[236]; break;
 | ||
|   case 'P': flag = (*_control_rec)[237]; break;
 | ||
|   default : flag = ' '; break;
 | ||
|   }
 | ||
|   return flag;
 | ||
| }
 | ||
| 
 | ||
| bool TTransfer_file::numprot_att() const
 | ||
| { 
 | ||
|  char flag = (*_control_rec)[238];
 | ||
|   return flag == 'X';
 | ||
| }
 | ||
| 
 | ||
| bool TTransfer_file::numprot_pas() const
 | ||
| { 
 | ||
|   char flag = (*_control_rec)[239];
 | ||
|   return flag == 'X';
 | ||
| }
 | ||
| 
 | ||
| char TTransfer_file::flg_agg_IV(char sigla) const
 | ||
| {
 | ||
|   char flag = ' ';
 | ||
|   
 | ||
|   if (sigla == 'P')
 | ||
|     flag = (*_control_rec)[234];
 | ||
|   
 | ||
|   return flag;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::put(const char* val, const char* file, int fieldnum,long recnum)
 | ||
| {
 | ||
|   int da = go2field(fieldnum,file,recnum,false);           
 | ||
|   _record.overwrite(val, da);
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::write(long numrec, int size)
 | ||
| {
 | ||
|   go2rec(numrec);
 | ||
|   const word scritti = fwrite((char*)(const char*)_record,sizeof(char),size,_trasfer);
 | ||
|   return scritti;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::writeat(const char* str,int size,int fieldnum,const char* file)
 | ||
| {
 | ||
|   go2field(fieldnum,file);
 | ||
|   
 | ||
|   const int nscritti = fwrite (str,1,size,_trasfer);
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::writeat(const char* str,int size,int fieldnum,const char* file, const long nrec)
 | ||
| {
 | ||
|   go2field(fieldnum,file,nrec);
 | ||
|   
 | ||
|   const int nscritti = fwrite (str,1,size,_trasfer);
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::go2field(int fieldnum, const char* file, const long nrec, bool seek)
 | ||
| {
 | ||
|   int pos_campo = 0;
 | ||
| 
 | ||
|   if (nrec < 0)
 | ||
|     readat(_curpos);  // Mi posiziono all' inizio del record
 | ||
|   else
 | ||
|     readat(nrec);
 | ||
|   
 | ||
|   TString16 key;
 | ||
|   if (!file)
 | ||
|     key.format("%2s%d",(const char*)_curfile,fieldnum);
 | ||
|   else
 | ||
|     key.format("%2s%d", file, fieldnum);
 | ||
|   
 | ||
|   if (_trc.is_key(key))  
 | ||
|   {
 | ||
|     TToken_string * data = (TToken_string *) _trc.objptr(key);
 | ||
|     
 | ||
|     // NB 
 | ||
|     // Nel tracciato parto da 1 (per compatibilita'), 
 | ||
|     // la fseek() conta da 0
 | ||
|     pos_campo = data->get_int(2) - 1;
 | ||
|     if (seek)
 | ||
|       fseek(_trasfer,pos_campo,SEEK_CUR);
 | ||
|   }
 | ||
|   return pos_campo;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::fill_index(const TString& sigle_file, const TString& nrec_file)
 | ||
| {
 | ||
|   TToken_string data;
 | ||
|   char sigla;
 | ||
|   long nrec,nrecp,start,end;       
 | ||
|   int  i;
 | ||
|   int  k = 0;
 | ||
|   int  lrec = 256;
 | ||
|   
 | ||
|   start = end = 0;
 | ||
|   
 | ||
|   nrecp = 0L;
 | ||
|   
 | ||
|   _index.destroy();
 | ||
| 
 | ||
|   _last_tab = 0;
 | ||
|   _last_mov = 0;
 | ||
|   
 | ||
|   for (i = 0; i < sigle_file.len(); i++)
 | ||
|   {                      
 | ||
|     data   = "";
 | ||
|     sigla  = sigle_file.mid(i,1)[0];
 | ||
|     nrec   = atol(nrec_file.mid(k,6));
 | ||
| 
 | ||
|     if (sigla == 'W' || sigla == 'P' || sigla == 'A')
 | ||
|     {
 | ||
|       _last_tab++;
 | ||
|       _last_mov++;
 | ||
|     }
 | ||
|     
 | ||
|     if (sigla == 'Z' || sigla == 'U' || sigla == 'B')
 | ||
|       _last_mov++;
 | ||
| 
 | ||
|     // A causa di errori di invio da parte del sistema
 | ||
|     // a volte si possono riscontrare GPF.
 | ||
|     // La riga commentata sottostante viene lasciata come
 | ||
|     // possibile correzione (che alla PRASSI ovviamente non vogliono)
 | ||
|     // da sostituire a quella analoga poco piu' sotto.
 | ||
|     // In pratica viene tolto l'and con nrec != 0
 | ||
|     //
 | ||
|     
 | ||
|     if (sigla != ' ')                      // Cosi funziona sempre
 | ||
|     //if (sigla != ' ' && nrec != 0)       // Cosi funziona solo se non ci sono zeri
 | ||
|     {
 | ||
|       data.add(sigla);
 | ||
|       data.add(nrec + nrecp);
 | ||
|       data.add(lrec);
 | ||
|       nrecp += nrec; 
 | ||
|       
 | ||
|       end = (nrecp * lrec) -1;
 | ||
|       data.add(start);
 | ||
|       data.add(end);
 | ||
|       start = end + 1;
 | ||
|       
 | ||
|       _index.add(data, i);
 | ||
|     }                            
 | ||
|     k += 6;
 | ||
|   }
 | ||
| 
 | ||
|   _tot_rec = nrecp;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::annulla_classi(int g, int c,bool conto)
 | ||
| {
 | ||
|   TLocalisamfile pcon (LF_PCON);
 | ||
|   bool okann = false;
 | ||
|   
 | ||
|   pcon.setkey(1);
 | ||
|   pcon.zero();
 | ||
|   pcon.put("GRUPPO", g);
 | ||
|   pcon.put("CONTO",  c);
 | ||
|   
 | ||
|   for (pcon.read(); !pcon.eof(); pcon.next())
 | ||
|   {                                    
 | ||
|     int gruppo = pcon.get_int("GRUPPO");
 | ||
|     int conto  = pcon.get_int("CONTO");
 | ||
| 
 | ||
|     if (gruppo != g || conto != c) break;
 | ||
|     
 | ||
|     if (conto)
 | ||
|     {                           
 | ||
|       okann = true;
 | ||
|       long sottoc = pcon.get_long("SOTTOCONTO");
 | ||
|       if (sottoc == 0) continue;
 | ||
|     }
 | ||
|     else
 | ||
|     {
 | ||
|       TString sez = pcon.get("SEZIVD");
 | ||
|       long    sottoc = pcon.get_long("SOTTOCONTO");
 | ||
|       
 | ||
|       if (sottoc == 0)
 | ||
|         if (sez.empty()) break;
 | ||
|         else           
 | ||
|         {
 | ||
|           okann = true;
 | ||
|           continue;
 | ||
|         }
 | ||
|     }
 | ||
|     
 | ||
|     if (okann )
 | ||
|     {
 | ||
|       pcon.zero("SEZIVD");
 | ||
|       pcon.zero("LETTIVD");
 | ||
|       pcon.zero("NUMRIVD");
 | ||
|       pcon.zero("NUMIVD");
 | ||
|       pcon.zero("SEZIVDOPP");
 | ||
|       pcon.zero("LETTIVDOPP");
 | ||
|       pcon.zero("NUMRIVDOPP");
 | ||
|       pcon.zero("NUMIVDOPP");
 | ||
|     
 | ||
|       pcon.rewrite();
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| // La gogna e' troppo poco: inguardabile!
 | ||
| // Pointer e reference ben conditi con scansioni inutili della tabella ESC!
 | ||
| int TTransfer_file::dataes(const TDate& d, int* prevesc, TDate& finesp)
 | ||
| {                   
 | ||
|   *prevesc = 0;
 | ||
|   
 | ||
|   TTable esc("ESC");
 | ||
|   for (int err = esc.first(); err == NOERR; err = esc.next())
 | ||
|   {
 | ||
|     const TDate ia(esc.get("D0"));   // Data inizio esercizio
 | ||
|     const TDate fa(esc.get("D1"));   // Data fine esercizio
 | ||
|     const int anno = esc.get_int("CODTAB");  
 | ||
|     if (d >= ia && d <= fa)
 | ||
|       return anno;
 | ||
|     *prevesc = anno;
 | ||
|     finesp = fa;   
 | ||
|   } 
 | ||
|   return 0;
 | ||
| }
 | ||
| 
 | ||
| char TTransfer_file::TipoConto(int g, int c)
 | ||
| {
 | ||
|   char tipo = ' ';
 | ||
|   
 | ||
|   if (g != 0 && c != 0)
 | ||
|   {    
 | ||
|     bool found = false;
 | ||
|   
 | ||
|     if (_tpcon != NULL) // Valido solo se si sta trasferendo anche il piano dei conti
 | ||
|     {
 | ||
|       _tpcon->put(PCN_GRUPPO,     g);
 | ||
|       _tpcon->put(PCN_CONTO,      c);
 | ||
|       _tpcon->put(PCN_SOTTOCONTO, 0l);
 | ||
|       if (_tpcon->read() == NOERR)
 | ||
|       {
 | ||
|         tipo = _tpcon->get_char(PCN_TMCF);
 | ||
|         found = true;
 | ||
|       }  
 | ||
|     }
 | ||
|     
 | ||
|     if (!found)
 | ||
|     {
 | ||
|       TLocalisamfile pcon (LF_PCON);
 | ||
|       pcon.setkey(1);
 | ||
|       pcon.zero();
 | ||
|       pcon.put(PCN_GRUPPO,     g);
 | ||
|       pcon.put(PCN_CONTO,      c);
 | ||
|       pcon.put(PCN_SOTTOCONTO, 0l);
 | ||
|       if (pcon.read() == NOERR)
 | ||
|       {
 | ||
|         tipo = pcon.get_char(PCN_TMCF);
 | ||
|         found = true;
 | ||
|       }
 | ||
|     }  
 | ||
|   }
 | ||
|   if (tipo < ' ')
 | ||
|     tipo = ' ';
 | ||
|   return tipo;
 | ||
| }
 | ||
| 
 | ||
| const char* TTransfer_file::numero_civico(TString& indirizzo)
 | ||
| {
 | ||
|   int i,j;
 | ||
|   
 | ||
|   TString& TEMP = get_tmp_string();
 | ||
|   
 | ||
|   i = indirizzo.find(','); // Cerca prima la virgola
 | ||
|   if (i >= 0)              // se la trova restituisce la prima parola dopo di essa
 | ||
|   {
 | ||
|     TToken_string t(indirizzo,',');
 | ||
|     TEMP = t.get(1);
 | ||
|     TEMP.trim();
 | ||
|     TToken_string n(TEMP,' '); // Il primo item dopo la virgola e' il numero civico
 | ||
|     TEMP = n.get(0);
 | ||
|     indirizzo = t.get(0); // Prima parte di indirizzo. Gia' senza la virgola.
 | ||
|     j = n.items();
 | ||
|     for (i = 1; i < j; i++)
 | ||
|       indirizzo << " " << n.get(i); // Completa l'indirizzo
 | ||
|     TEMP.trim();
 | ||
|   }
 | ||
|   else                     // Se non c'e' nessuna virgola
 | ||
|   {                        // Ritorna l'ultima parola a partire da dx che contiene almeno una cifra
 | ||
|     TToken_string t(indirizzo,' ');
 | ||
|     TEMP = t.get(t.items()-1);
 | ||
|     j = TEMP.len();
 | ||
|     for (i = 0; i<j; i++)
 | ||
|       if (isdigit(TEMP[i]))
 | ||
|       {
 | ||
|         indirizzo.rtrim(j); // Toglie la parte del numero dall'indirizzo
 | ||
|         TEMP.trim();
 | ||
|         break;
 | ||
|       }
 | ||
|     if (i == j)
 | ||
|       TEMP = "";
 | ||
|   }
 | ||
|   
 | ||
|   return TEMP;
 | ||
| }
 | ||
| 
 | ||
| const char* TTransfer_file::cerca_comune_cap(const TString& field, const TString& localita)
 | ||
| {             
 | ||
| /*
 | ||
|   const TString80 dencom(localita);
 | ||
|   TString16 cap(field); 
 | ||
| 	
 | ||
| 	TString& TEMP = get_tmp_string();
 | ||
| 
 | ||
|   if (cap[2] == '1')
 | ||
|   {
 | ||
|     cap.cut(3);
 | ||
|     cap << "00";
 | ||
|   }
 | ||
|   
 | ||
|   TRelation relcom(LF_COMUNI);
 | ||
|   TRectype & comrec = relcom.curr();
 | ||
| 
 | ||
| 	comrec.put(COM_CAPCOM, cap);
 | ||
| 
 | ||
| 	int maxlen = 0;
 | ||
| 	TCursor comuni (&relcom, "", 3, &comrec, &comrec);
 | ||
| 	const TRecnotype items = comuni.items();
 | ||
|   
 | ||
| 	comuni.freeze();
 | ||
|   for (comuni = 0L; comuni.pos() < items; ++comuni)
 | ||
|   {
 | ||
|     const TString & denominazione = comrec.get(COM_DENCOM);
 | ||
| 		int i = 0;
 | ||
| 
 | ||
|     for (i = 0; dencom[i] && dencom[i] == denominazione[i]; i++);
 | ||
| 
 | ||
| 		if (maxlen < i)
 | ||
| 		{
 | ||
| 			maxlen = i;
 | ||
| 			if (maxlen > 2)
 | ||
| 				TEMP = comrec.get(COM_COM);
 | ||
|     }
 | ||
|   } 
 | ||
|   return TEMP;
 | ||
| */
 | ||
|   return cap2comune(field, localita);  // Guy: Oggi e' meglio fare cosi', o no?
 | ||
| }
 | ||
| 
 | ||
| const char* TTransfer_file::cerca_cap_comune(const TString& localita)
 | ||
| {                               
 | ||
|   const TRectype& rec = _comuni2.get(localita);
 | ||
|   return rec.get(COM_CAPCOM);
 | ||
| }
 | ||
| 
 | ||
| const char* TTransfer_file::cerca_comune_den(const TString& field)
 | ||
| {   
 | ||
|   const TRectype& rec = _comuni2.get(field);
 | ||
|   return rec.get(COM_COM);
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_tmp_tabelle(TString& record, bool create)
 | ||
| {
 | ||
|   TString16 key,cap;
 | ||
|   
 | ||
|   int     numfield = 2;  //Per le tabelle il primo campo della mappa non e' significativo
 | ||
|                          //ai fini del trasferimento (flag di record gia trasferito).
 | ||
|   const TMappa_trc& trc  = mappa();
 | ||
|   TIsamtempfile*    file = NULL; 
 | ||
|   TRectype*         dep  = NULL;
 | ||
|   int               logicnum;
 | ||
|   int               campi_righe = 0;
 | ||
|   int               num_riga    = 1;
 | ||
|   int  gruppo,conto;
 | ||
|   
 | ||
|   const TString4 sigla = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
|   
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     int logicnum_p = 0;
 | ||
| 
 | ||
|     do
 | ||
|     {  
 | ||
|       logicnum = trc.logicnum(key);
 | ||
|         
 | ||
|       if (logicnum != logicnum_p)
 | ||
|       {
 | ||
|         if (logicnum_p)
 | ||
|         {              
 | ||
|           _prog->addstatus(1);
 | ||
|           trasfer_data_tab(*file, *dep);            
 | ||
|           delete file; file = NULL;
 | ||
|           delete dep; dep = NULL;
 | ||
|         }           
 | ||
|         
 | ||
|         TFilename tmp_path;
 | ||
|         if (sigla == "W1")
 | ||
|         {
 | ||
|           if (logicnum == LF_CAUSALI)
 | ||
|             tmp_path = _tmpcaus;
 | ||
|           else
 | ||
|             tmp_path = _tmprcaus;
 | ||
|         }
 | ||
| 
 | ||
|         if (sigla == "A1")
 | ||
|           tmp_path = _tmpclifo;
 | ||
| 
 | ||
|         if (sigla == "P1" || sigla == "P2" || sigla == "P3")
 | ||
|           tmp_path = _tmppcon;
 | ||
|   
 | ||
|         file = new TIsamtempfile(logicnum, tmp_path, create);
 | ||
|         dep  = new TRectype (logicnum);
 | ||
|         dep->zero();
 | ||
|       }                                                 
 | ||
|         
 | ||
|       logicnum_p = logicnum;
 | ||
| 
 | ||
|       if (logicnum == LF_RCAUSALI) 
 | ||
|       {
 | ||
|         campi_righe++;
 | ||
| 
 | ||
|         if (campi_righe == CAMPI_RCAUS)
 | ||
|         {
 | ||
|           // scarta le righe non significative
 | ||
|           // --------------------  NB  -----------------------
 | ||
|           // supponiamo il GRUPPO INDISPENSABILE !!!!!!!!!!!!!
 | ||
|           //
 | ||
|           if (dep->get("GRUPPO").not_empty()) 
 | ||
|           {
 | ||
|             dep->put("NRIGA", num_riga++);
 | ||
|             trasfer_data_tab(*file, *dep);
 | ||
|           }
 | ||
|           else
 | ||
|             num_riga++;
 | ||
|             
 | ||
|           campi_righe   = 1;
 | ||
|         } 
 | ||
|       }
 | ||
| 
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString16 fname = trc.field_name(key); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|         
 | ||
|       //Il nostro codice registro IVA e' lungo 3: se il loro registro (lungo 1) e' alfanumerico
 | ||
|       //devo allinearlo a sinistra, mentre se e' numerico devo allinearlo a destra riempendolo con degli zero.      
 | ||
|       if (logicnum == LF_CAUSALI)
 | ||
|       {                          
 | ||
|         if (fname == "REG")
 | ||
|         {
 | ||
|           char f = field[0];
 | ||
|           if (isdigit(f))
 | ||
|             field.format("%03c", f);
 | ||
|           else
 | ||
|             field.format("%-3c", f);     
 | ||
|           
 | ||
|           int tipomov = atoi(record.sub(208,209));   // Tipo movimento del saldaconto
 | ||
|           dep->put(CAU_TIPOMOV, tipomov);            // sulla causale
 | ||
|         }
 | ||
|           
 | ||
|         if (fname == "M770")
 | ||
|           if (field == "0")
 | ||
|             field = " ";
 | ||
| 
 | ||
|         if (fname == "NUMDOC" || fname == "DATADOC")
 | ||
|         {
 | ||
|           if (field == "0")
 | ||
|             field = " ";
 | ||
|           else
 | ||
|             if (field == "1")
 | ||
|               field = "X";
 | ||
|         }
 | ||
|           
 | ||
|         if (fname == "CODCAUSIM")
 | ||
|           if (field == "000")
 | ||
|             field = "   ";                 
 | ||
|       }                           
 | ||
|         
 | ||
|       if (logicnum == LF_RCAUSALI && (fname == "GRUPPO" || fname == "CONTO") )
 | ||
|       {
 | ||
|         if (fname == "GRUPPO")
 | ||
|           gruppo = atoi(field);
 | ||
|             
 | ||
|         if (fname == "CONTO")
 | ||
|         {
 | ||
|           conto = atoi(field);
 | ||
|           char tipo = TipoConto(gruppo,conto);
 | ||
|           dep->put(RCA_TIPOCF, tipo);
 | ||
|         }
 | ||
|       }
 | ||
|         
 | ||
|       //Il tipo cliente/fornitore presente su AS400 puo' assumere come valori 1 o 2
 | ||
|       //mentre quello su PC C o F; devo fare la conversione.
 | ||
|       if (sigla == "A1") 
 | ||
|       {
 | ||
|         if (fname == "CODCF")
 | ||
|         {
 | ||
|           long codcf = atol(field);
 | ||
|           field.format("%6ld", codcf);
 | ||
|         }
 | ||
|         if (fname == "TIPOCF")
 | ||
|         {
 | ||
|           if (field == "1")
 | ||
|             field = "C"; 
 | ||
|             
 | ||
|           if (field == "2")
 | ||
|             field = "F";
 | ||
|         }
 | ||
|         //Il tipo persona (fisica/giuridica) su AS400 puo' assumere come valori 1 e 0
 | ||
|         //mentre quello su PC F o G; devo fare la conversione.
 | ||
|         if (fname == "TIPOPERS")
 | ||
|         {
 | ||
|           if (field == "1")
 | ||
|             field = "F";
 | ||
|             
 | ||
|           if (field == "0")
 | ||
|             field = "G";
 | ||
|         }        
 | ||
|           
 | ||
|         //Il codice pagamento su AS400 e' un alfanumerico di due, mentre su PC e' un
 | ||
|         //alfanumerico di 4 trattato con il flag Z. Dunque in ricezione se si tratta
 | ||
|         //di un numero va riempito con degli 0. Se si tratta di un alfa va allineato a destra.                       
 | ||
|         if (fname == "CODPAG")
 | ||
|         {    
 | ||
|           TString16 f = field;
 | ||
|           //if (real::is_natural(f))
 | ||
|           //  field.format("%04s", (const char*) f);
 | ||
|           //else
 | ||
|             field.format("%-4s", (const char*) f);
 | ||
|         }
 | ||
|           
 | ||
|         if (fname == "INDCF")
 | ||
|         {            
 | ||
|           field = field.rtrim();
 | ||
|           if (field != "")
 | ||
|           {
 | ||
|             const char* numero = numero_civico(field);
 | ||
|             dep->put(CLI_CIVCF, (const char*)numero);
 | ||
|           }
 | ||
|         }
 | ||
|           
 | ||
|         if (fname == "CAPCF")
 | ||
|         {
 | ||
|           if (field == "00000")
 | ||
|             field = "     ";
 | ||
|           else
 | ||
|             cap = field;
 | ||
|         }
 | ||
|           
 | ||
|         if (fname == "LOCALITACF")
 | ||
|         {
 | ||
|           TString80 comune;
 | ||
|             
 | ||
|           if (cap.not_empty())
 | ||
|             comune = cerca_comune_cap(cap,field);
 | ||
|           else
 | ||
|             dep->put(CLI_CAPCF,cerca_cap_comune(field));
 | ||
|           if (comune.empty())
 | ||
|             comune = cerca_comune_den(field);
 | ||
|           if (comune.not_empty())
 | ||
|           {
 | ||
|             dep->put(CLI_COMCF, comune);
 | ||
|             field = "";
 | ||
|           }
 | ||
|         } 
 | ||
|           
 | ||
|         if (fname == "ALLEG")
 | ||
|         {
 | ||
|           if (field == "0")
 | ||
|             field = " "; 
 | ||
|           if (field == "2") 
 | ||
|             dep->put("OCCAS", (const char*) "X");                      
 | ||
|               
 | ||
|         }  
 | ||
|         if (fname == "PAIV")
 | ||
|           if (field == "00000000000")
 | ||
|             field = " ";    
 | ||
|       }
 | ||
|         
 | ||
|       //Quando ricevo la IV direttiva del piano dei conti per evitare che nell'archivio,
 | ||
|       //in caso di numero romano vuoto, venga memorizzato la stringa letta sul trasfer ("000"),
 | ||
|       //vuoto la stringa prima di fare la put.
 | ||
|       if (sigla == "P1" || sigla == "P2" || sigla == "P3")
 | ||
|       {
 | ||
|         if (fname == "GRUPPO")
 | ||
|         {
 | ||
|           int gruppo = atoi(field);
 | ||
|           field.format("%3d", gruppo);
 | ||
|         }                             
 | ||
|         if (fname == "CONTO") 
 | ||
|         {
 | ||
|           int conto = atoi(field);
 | ||
|           field.format("%3d", conto);
 | ||
|         }                            
 | ||
|         if (fname == "SOTTOCONTO")
 | ||
|         {
 | ||
|           long sottoc = atol(field);
 | ||
|           field.format("%6ld", sottoc);
 | ||
|         }
 | ||
|       }
 | ||
|       if (sigla == "P2" || sigla == "P3")
 | ||
|       { 
 | ||
|         if (fname == "STSOTTBIL")
 | ||
|         {
 | ||
|           if (field == "0")
 | ||
|             field = " ";
 | ||
|           else
 | ||
|             if (field == "1")
 | ||
|               field = "X";
 | ||
|         }
 | ||
|  
 | ||
|         if (fname == "NUMRIVD" || fname == "NUMRIVDOPP")
 | ||
|         {
 | ||
|           if (field == "000")
 | ||
|             field = "";
 | ||
|         }
 | ||
|         if (fname == "SEZIVD" || fname == "SEZIVDOPP")
 | ||
|         {
 | ||
|           if (field == " ")
 | ||
|             field = "0";
 | ||
|         }
 | ||
|         if (fname == "IVACOMP")    // MI3695
 | ||
|         {
 | ||
|           if (field == "00")
 | ||
|             field = "";
 | ||
|         }
 | ||
|       } 
 | ||
|         
 | ||
|       dep->put(fname, (const char*)field);                      
 | ||
| 
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));
 | ||
|       
 | ||
|     if (logicnum == LF_RCAUSALI) 
 | ||
|     { 
 | ||
|         campi_righe++;
 | ||
| 
 | ||
|         if (campi_righe == CAMPI_RCAUS)
 | ||
|         {
 | ||
|           TString16 gruppo(dep->get("GRUPPO"));     
 | ||
|           //          
 | ||
|           // scarta le righe non significative
 | ||
|           // --------------------  NB  -----------------------
 | ||
|           // supponiamo il GRUPPO INDISPENSABILE !!!!!!!!!!!!!
 | ||
|           //
 | ||
|           if (gruppo.not_empty()) 
 | ||
|           {
 | ||
|             dep->put("NRIGA", num_riga++);
 | ||
|             trasfer_data_tab(*file, *dep);
 | ||
|           }                                                
 | ||
|           else
 | ||
|             num_riga++;
 | ||
|             
 | ||
|           campi_righe   = 1;
 | ||
|         }  
 | ||
|     }
 | ||
|     else                      
 | ||
|     {
 | ||
|       _prog->addstatus(1);
 | ||
|       trasfer_data_tab(*file, *dep);  
 | ||
|     }
 | ||
|       
 | ||
|     delete file;
 | ||
|     delete dep;
 | ||
|   } // if (trc.is_key((const char*) key))
 | ||
| }
 | ||
|                                 
 | ||
| int TTransfer_file::trasfer_data_tab(TIsamtempfile& file, TRectype& dep)
 | ||
| { 
 | ||
|   file.zero();
 | ||
|   file.curr() = dep;
 | ||
|       
 | ||
|   if (file.read() == NOERR)     
 | ||
|   {   
 | ||
|     file.zero();
 | ||
|     file.curr() = dep;
 | ||
|     file.rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     file.zero();
 | ||
|     file.curr() = dep;     
 | ||
|     file.write();    
 | ||
|   }
 | ||
|   
 | ||
|   return 0;
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::annoes_datacomp(const TString& record, TDate& datacomp)
 | ||
| { 
 | ||
|   const TString& tmp = record.sub(15,21);
 | ||
|   _datareg     = converti(tmp,false);
 | ||
|   const int segn  = atoi(record.sub(21,22));  
 | ||
|   
 | ||
|   int aep = 0;
 | ||
|   int ae = date2esc(_datareg, &aep);
 | ||
|   
 | ||
|   if (segn == 0)
 | ||
|     datacomp = _datareg;
 | ||
|   
 | ||
|   if (ae != 0)
 | ||
|   {
 | ||
|     if (segn == 1)
 | ||
|     {
 | ||
|       datacomp = data_fine_esercizio(aep);
 | ||
|       ae = aep;
 | ||
|     }
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     int ae = _datareg.year();
 | ||
|     
 | ||
|     if (segn == 0)
 | ||
|       return ae;
 | ||
|       
 | ||
|     if (segn == 1)
 | ||
|       return (ae - 1);
 | ||
|   }
 | ||
|   
 | ||
|   return ae;
 | ||
| }
 | ||
|                
 | ||
| void TTransfer_file::decimali(TString& campo, int dec)
 | ||
| {                   
 | ||
|   if (dec > 0)
 | ||
|   {  
 | ||
| /*  
 | ||
|     const int l = campo.len();
 | ||
|     if (l >= dec)
 | ||
|     {
 | ||
|       const int p = l - dec; 
 | ||
|       if (p == 0 || campo[p-1] != '.')
 | ||
|         campo.insert(".", p);
 | ||
|     }
 | ||
| */
 | ||
|     if (campo.find('.') < 0)  // Controlla che non ci sia gi<67> la virgola!
 | ||
|     {     
 | ||
|       int l = campo.len();
 | ||
|       if (campo[0] == '-')
 | ||
|       {
 | ||
|         while (l-1 <= dec)
 | ||
|         {
 | ||
|           campo.insert("0", 1);  // Aggiunge s<> quanti zeri dopo il meno
 | ||
|           l++;
 | ||
|         }
 | ||
|       }
 | ||
|       else
 | ||
|       {
 | ||
|         while (l <= dec)
 | ||
|         {
 | ||
|           campo.insert("0", 0);  // Aggiunge s<> quanti zeri in testa
 | ||
|           l++;
 | ||
|         }
 | ||
|       }
 | ||
|       const int dot = l-dec;
 | ||
|       campo.insert(".", dot);
 | ||
|       if (campo[dot+1] == ' ')   // Controlla se devo mettere lo zero prima dei centesimi!
 | ||
|         campo[dot+1] = '0';      
 | ||
|     }
 | ||
|   }
 | ||
| }                      
 | ||
| 
 | ||
| int TTransfer_file::strip_zero(TString& importo)
 | ||
| {
 | ||
|   TString16 app;
 | ||
|   
 | ||
|   int size = importo.len();
 | ||
| 	int i;
 | ||
|   
 | ||
|   for (i = 0; i < size; i++)
 | ||
|     if (importo[i] != '0') break;
 | ||
|     
 | ||
|   if (i > 0)
 | ||
|   {
 | ||
|     app = importo.mid(importo[i] == '.' ? i - 1 : i);
 | ||
|     importo = app;
 | ||
|   }               
 | ||
|   
 | ||
|   return (i ? i - 1 : i);
 | ||
| }
 | ||
| 
 | ||
| bool TTransfer_file::my_isdigit(unsigned char ch)
 | ||
| {
 | ||
|   return (ch >= '0' && ch <= '9');
 | ||
| }
 | ||
|                                                  
 | ||
| int TTransfer_file::look(unsigned char carattere)
 | ||
| {
 | ||
|   for (int i = 0; i < 10; i++)
 | ||
|     if (_tabella[i] == carattere)
 | ||
|       return i;
 | ||
|       
 | ||
|   return -1;
 | ||
| }             
 | ||
|                                                   
 | ||
| void TTransfer_file::negativo(TString& importo)
 | ||
| {                           
 | ||
|   strip_zero(importo);
 | ||
|   
 | ||
|   int size = importo.len();
 | ||
|   
 | ||
|   if (!size) return;
 | ||
|   
 | ||
|   unsigned char last = importo[size - 1];
 | ||
|   
 | ||
|   if (!my_isdigit(last))
 | ||
|   {     
 | ||
|     int new_last = look(last);
 | ||
|     TString16 dep; dep << new_last;
 | ||
|     if (new_last >= 0) 
 | ||
|     {
 | ||
|       importo[size - 1] = dep[0];
 | ||
|       importo.insert("-");  
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| // Controlla se la ditta <20> in euro 
 | ||
| static bool ditta_in_euro() 
 | ||
| {
 | ||
|   return is_euro_value(NULL);
 | ||
| }
 | ||
|  
 | ||
| void TTransfer_file::write_tmp_movPN(TString& record)
 | ||
| {
 | ||
|   TString key,str,codreg;
 | ||
|   int     numfield = 3; //Per i movimenti i primi due campi della mappa non sono significativi
 | ||
|   //ai fini del trasferimento (flag record gia trasferito e nuovo ultimo numero di registrazione). 
 | ||
|   const TMappa_trc& trc  = mappa();
 | ||
|   TIsamtempfile*    file = NULL; 
 | ||
|   TRectype*         dep  = NULL;
 | ||
|   int               logicnum;
 | ||
|   TDate             datacomp;
 | ||
|   TString           nreg;
 | ||
|   int               fnrmov = 13;
 | ||
|   TString           tmp_path,tipodoc;
 | ||
|   real              importo = ZERO;
 | ||
|   static bool       create = true;
 | ||
|   
 | ||
|   int solo_sezionale = atoi(record.mid(218,1));
 | ||
|   if (solo_sezionale != 1)
 | ||
|   {  
 | ||
|     const TString4 sigla = record.mid(0,2);
 | ||
|     key.format("%2s%d", (const char*)sigla,numfield);
 | ||
|       
 | ||
|     if (trc.is_key((const char *) key)) 
 | ||
|     {    
 | ||
|       int logicnum_p = 0;             
 | ||
|   
 | ||
|       _numreg = atol(record.sub(2,8));
 | ||
|         
 | ||
|       if (_numreg == _numreg_p)
 | ||
|       {
 | ||
|         numfield = fnrmov;
 | ||
|         key.format("%2s%d", (const char*)sigla,numfield);
 | ||
|       }
 | ||
|         
 | ||
|       _annoes   = annoes_datacomp(record,datacomp); 
 | ||
|       _numreg_p = _numreg;   
 | ||
|   
 | ||
|       do
 | ||
|       {  
 | ||
|         logicnum = trc.logicnum(key);
 | ||
|             
 | ||
|         if (logicnum != logicnum_p)
 | ||
|         {
 | ||
|           if (logicnum_p)
 | ||
|           {
 | ||
|             trasfer_data_mov(*file, *dep);
 | ||
|             delete file;
 | ||
|             delete dep;
 | ||
|           }
 | ||
|   
 | ||
|           if (sigla == "Z1")
 | ||
|           {
 | ||
|             if (logicnum == LF_MOV)
 | ||
|               tmp_path = _tmpmov;
 | ||
|             else
 | ||
|               tmp_path = _tmprmov;
 | ||
|           }
 | ||
|           
 | ||
|           file = new TIsamtempfile(logicnum, tmp_path, create);
 | ||
|           dep  = new TRectype (logicnum);
 | ||
|           dep->zero();
 | ||
|             
 | ||
|           logicnum_p = logicnum;                                                
 | ||
|         }    
 | ||
|         
 | ||
|         const int from  = trc.from(key);
 | ||
|         const int to    = trc.to(key);
 | ||
|         TString16 fname = trc.field_name(key); 
 | ||
|         TString field   = record.sub(from-1,to); 
 | ||
|         int flag  = trc.flag(key);
 | ||
|         int dec   = trc.flag_bis(key);
 | ||
|             
 | ||
|         TRecfield campo (*dep,fname);
 | ||
|         if (campo.type() == _realfld)
 | ||
|         {
 | ||
|           negativo(field);
 | ||
|         
 | ||
|           // Cerco di riconoscere gli importi in euro  
 | ||
|           if (dec == 0 && (to-from) >= 8 && record.size()==sizeT && ditta_in_euro())
 | ||
|           {
 | ||
|             flag = 3;
 | ||
|             dec = 2;
 | ||
|           }
 | ||
|         }
 | ||
|   
 | ||
|         if (flag == 3)
 | ||
|         { 
 | ||
|           if (dec > 0)
 | ||
|             decimali(field,dec);
 | ||
|           // Non capisco a cosa serva ma mi adeguo: forse toglie gli zeri iniziali
 | ||
|           const real appoggio = field;      
 | ||
|           field = appoggio.string(0, dec);
 | ||
|         }
 | ||
|               
 | ||
|         if (logicnum == LF_MOV)
 | ||
|         {
 | ||
|           if (fname == MOV_REG)
 | ||
|           {                         
 | ||
|             if (real::is_natural(field))
 | ||
|               field.format("%03s", (const char*) field);
 | ||
|             else
 | ||
|               field.format("%-3s", (const char*) field);
 | ||
|           }                           
 | ||
|   
 | ||
|           //Il codice pagamento su AS400 e' un alfanumerico di due, mentre su PC e' un
 | ||
|           //alfanumerico di 4 trattato con il flag Z. Dunque in ricezione se si tratta
 | ||
|           //di un numero va riempito con degli 0. Se si tratta di un alfa va allineato a destra.                       
 | ||
|           if (fname == MOV_CODPAG)
 | ||
|           { 
 | ||
|             const TString8 f = field;
 | ||
|             field.format("%-4s", (const char*)f);
 | ||
|           }
 | ||
|           
 | ||
|           if (fname == MOV_CODCAUS)
 | ||
|           {
 | ||
|             if (field == "000")
 | ||
|               field = "";
 | ||
|             
 | ||
|             int nr = atoi(record.sub(8,10));
 | ||
|             if (nr == 1)
 | ||
|             {
 | ||
|               TString descr = record.sub(44,74);
 | ||
|               dep->put(RMV_DESCR, descr);        // Descrizione della prima riga riportata sulla testata
 | ||
|             }
 | ||
|           } 
 | ||
|           
 | ||
|           if (fname == MOV_TIPODOC)
 | ||
|             tipodoc = field;          
 | ||
|         }
 | ||
|   
 | ||
|         if (fname == "IMPORTO")
 | ||
|         {
 | ||
|           const real imp = field;  
 | ||
|           importo = imp;
 | ||
|         }  
 | ||
|         
 | ||
|         if (logicnum == LF_RMOV)
 | ||
|         {
 | ||
|           if (fname == RMV_NUMRIG)
 | ||
|           {
 | ||
|             const int nriga = atoi(field);
 | ||
|             field.format("%3d", nriga);
 | ||
|           }                            
 | ||
|           if (fname == RMV_GRUPPO || fname == RMV_GRUPPOC)
 | ||
|           {
 | ||
|             const int gruppo = atoi(field);
 | ||
|             field.format("%3d", gruppo);
 | ||
|           }        
 | ||
|           if (fname == RMV_CONTO || fname == RMV_CONTOC)
 | ||
|           {
 | ||
|             const int conto = atoi(field);
 | ||
|             field.format("%3d", conto);
 | ||
|           }                            
 | ||
|           if (fname == RMV_SOTTOCONTO || fname == RMV_SOTTOCONTOC)
 | ||
|           {
 | ||
|             const long sottoc = atol(field);
 | ||
|             field.format("%6ld", sottoc);
 | ||
|           }
 | ||
|         }
 | ||
|         
 | ||
|         if (logicnum == LF_MOV && (fname == MOV_NUMREG || flag == 2) ) 
 | ||
|         {                       
 | ||
|           if (fname == MOV_NUMREG) 
 | ||
|           {
 | ||
|             dep->put(MOV_ANNOES,   _annoes);                                     
 | ||
|             dep->put(MOV_NUMREG,   _numreg);
 | ||
|             dep->put(MOV_DATAREG,  _datareg);
 | ||
|             dep->put(MOV_DATACOMP, datacomp);  
 | ||
|             const int annoiva = _datareg.year();
 | ||
|             dep->put(MOV_ANNOIVA,  annoiva);
 | ||
|           }
 | ||
|           if (flag == 2)
 | ||
|             dep->put(fname,converti(field,false));
 | ||
|         }
 | ||
|         else  
 | ||
|           if (logicnum == LF_RMOV && (fname == RMV_NUMREG || fname == RMV_NUMRIG) ) 
 | ||
|           {                        
 | ||
|             if (fname == RMV_NUMREG)
 | ||
|             {   
 | ||
|               dep->put(RMV_ANNOES,  _annoes);                                     
 | ||
|               dep->put(RMV_NUMREG,  _numreg);
 | ||
|             }
 | ||
|   
 | ||
|             if (fname == RMV_NUMRIG)
 | ||
|             {
 | ||
|               dep->put(RMV_NUMRIG,  field);  
 | ||
|               dep->put(RMV_DATAREG, _datareg);
 | ||
|             }          
 | ||
|           }
 | ||
|           else
 | ||
|             dep->put(fname, field);
 | ||
|             
 | ||
|         numfield++;
 | ||
|         key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|       }
 | ||
|       while (trc.is_key((const char*) key));
 | ||
|       _prog->addstatus(1);
 | ||
|       
 | ||
|       if (importo != ZERO)
 | ||
|         trasfer_data_mov(*file, *dep);      
 | ||
|   
 | ||
|       if (create)
 | ||
|         create = false;    // I files (mov e rmov) vanno creati la prima volta che si tenta di scrivere un record su di essi
 | ||
|           
 | ||
|       delete file;
 | ||
|       delete dep;
 | ||
|     } // if (trc.is_key((const char*) key))
 | ||
|   } // if (solo_sezionale != 1)
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::trasfer_data_mov(TIsamtempfile& file, TRectype& dep)
 | ||
| {  
 | ||
|   file.zero();
 | ||
|   file.curr() = dep;
 | ||
|                       
 | ||
|   if (file.read() == NOERR)     
 | ||
|   { 
 | ||
|     file.zero();
 | ||
|     file.curr() = dep;
 | ||
|     file.rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     file.zero();
 | ||
|     file.curr() = dep;     
 | ||
|     file.write();    
 | ||
|   }
 | ||
|   return 0;
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::cerca_annoes(long numreg, TString& tipodoc) const
 | ||
| {
 | ||
|   const long ditta = prefix().get_codditta();
 | ||
| 
 | ||
|   TFilename tmpmov = "%";
 | ||
|   tmpmov  << firm2dir(ditta);
 | ||
|   tmpmov.add(TEMP_MOV);
 | ||
|   TIsamtempfile tmov (LF_MOV, tmpmov, 0);  
 | ||
| 
 | ||
|   int anno = 0;
 | ||
|   
 | ||
|   tmov.setkey(1);
 | ||
|   tmov.zero();
 | ||
|   tmov.put(MOV_NUMREG, numreg);
 | ||
|   if (tmov.read() == NOERR)                                  
 | ||
|   {
 | ||
|     anno    = tmov.get_int(MOV_ANNOES);
 | ||
|     tipodoc = tmov.get    (MOV_TIPODOC);
 | ||
|   }
 | ||
|   
 | ||
|   return anno;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::scrivi_occasionali(const TString& record, TString& cfpi)
 | ||
| { 
 | ||
|   const TString80 ragsoc = record.sub(61,86);
 | ||
|   cfpi.cut(0);
 | ||
|   if (ragsoc.blank()) 
 | ||
|     return;
 | ||
|   
 | ||
|   TString80 ind       = record.sub(86,108);
 | ||
|   const TString80 com = record.sub(108,126);
 | ||
|   const TString8 cap  = record.sub(126,131);
 | ||
|   TString16 civ;
 | ||
|   
 | ||
|   ind.rtrim();
 | ||
|   if (ind.full())
 | ||
|     civ = numero_civico(ind);
 | ||
|   
 | ||
|   cfpi = record.sub(176, 192); // Patch per crp: cerca il codice fiscale in un campo non documentato
 | ||
|   if (cfpi.blank())
 | ||
|     cfpi.format("RIC%13ld", ++_npoccas);
 | ||
|   
 | ||
|   //ricerca_comune(com);
 | ||
|   _cod_com.cut(0);
 | ||
|   if (cap.full())
 | ||
|     _cod_com = cerca_comune_cap(cap,com);
 | ||
|   if (_cod_com.empty())
 | ||
|     _cod_com = cerca_comune_den(com);
 | ||
|   
 | ||
|   _toccas->setkey(1);
 | ||
|   _toccas->zero();
 | ||
|   _toccas->put(OCC_CFPI,   cfpi);
 | ||
|   _toccas->put(OCC_RAGSOC, ragsoc);
 | ||
|   _toccas->put(OCC_INDIR,  ind);
 | ||
|   _toccas->put(OCC_CIV,    civ);
 | ||
|   _toccas->put(OCC_CAP,    cap);  
 | ||
|   if (_cod_com.full())
 | ||
|     _toccas->put(OCC_COM, _cod_com);
 | ||
|   
 | ||
|   int err = _toccas->write();
 | ||
|   if (err == _isreinsert)
 | ||
|     err = _toccas->rewrite();
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_tmp_movIVA(const TString& record)
 | ||
| {
 | ||
|   static bool       create = true;
 | ||
|   const TMappa_trc& trc  = mappa();
 | ||
|   
 | ||
|   int numfield = 3; //Per i movimenti i primi due campi della mappa non sono significativi
 | ||
|   const TString4 sigla = record.mid(0,2);
 | ||
|   TString4 key; key.format("%2s%d", (const char*)sigla, numfield);
 | ||
|     
 | ||
|   if (trc.is_key(key)) 
 | ||
|   {
 | ||
|     const int         fnrmiva = 11;                          
 | ||
| 
 | ||
|     //ai fini del trasferimento (flag record gia trasferito e nuovo ultimo numero di registrazione).  
 | ||
|     TIsamtempfile*    file = NULL; 
 | ||
|     TRectype*         dep  = NULL;
 | ||
|     TFilename         tmp_path;
 | ||
|     TString16 cfpi;
 | ||
|       
 | ||
|     int logicnum_p = 0;             
 | ||
|       
 | ||
|     _numreg = atol(record.sub(2,8));
 | ||
|       
 | ||
|     if (_numreg == _numreg_piva)
 | ||
|     {
 | ||
|       numfield = fnrmiva;
 | ||
|       key.format("%2s%d", (const char*)sigla,numfield);
 | ||
|     }
 | ||
|     else
 | ||
|       scrivi_occasionali(record, cfpi);                       
 | ||
|                            
 | ||
|     _numreg_piva = _numreg;
 | ||
|         
 | ||
|     do
 | ||
|     {  
 | ||
|       const int logicnum = trc.logicnum(key);
 | ||
|           
 | ||
|       if (logicnum != logicnum_p)
 | ||
|       {
 | ||
|         if (logicnum_p)
 | ||
|         {
 | ||
|           trasfer_data_moviva(*file, *dep);
 | ||
|           delete file; file = NULL;
 | ||
|           delete dep; dep = NULL;
 | ||
|         }
 | ||
| 
 | ||
|         if (sigla == "U1")
 | ||
|         { 
 | ||
|           if (logicnum == LF_MOV)                            
 | ||
|           {
 | ||
|             tmp_path = _tmpmov;
 | ||
|             file = new TIsamtempfile(logicnum, tmp_path, 0);
 | ||
|           }
 | ||
|           else
 | ||
|           {
 | ||
|             tmp_path = _tmprmoviva;
 | ||
|             file = new TIsamtempfile(logicnum, tmp_path, create);
 | ||
|           }
 | ||
|         }
 | ||
| 
 | ||
|         dep = new TRectype(logicnum);
 | ||
|       }                                                 
 | ||
|           
 | ||
|       logicnum_p = logicnum;                                                
 | ||
|           
 | ||
|       const int from  = trc.from(key);
 | ||
|       const int to    = trc.to(key);
 | ||
|       const TString16 fname = trc.field_name(key); 
 | ||
|       TString80 field = record.sub(from-1,to); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       int     dec   = trc.flag_bis(key);
 | ||
|           
 | ||
|       if (logicnum == LF_MOV && fname == MOV_TOTDOC)
 | ||
|       {
 | ||
|         numfield++;
 | ||
|         key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|         continue;
 | ||
|       }
 | ||
|       
 | ||
|       const TRecfield campo(*dep, fname);
 | ||
|       if (campo.type() == _realfld)
 | ||
|       {
 | ||
|         negativo(field);
 | ||
|         
 | ||
|         // Cerco di riconoscere gli importi in euro  
 | ||
|         if (dec == 0 && (to-from) >= 8 && record.size()==sizeT && ditta_in_euro())
 | ||
|         {
 | ||
|           flag = 3;
 | ||
|           dec = 2;
 | ||
|         }
 | ||
|       }
 | ||
|                                                      
 | ||
|       if (flag == 3)
 | ||
|       {
 | ||
|         if (dec > 0)
 | ||
|           decimali(field,dec);
 | ||
|         const real appoggio = field;
 | ||
|         field = appoggio.string(0, dec);  
 | ||
|       }                           
 | ||
|       
 | ||
|       if (logicnum == LF_RMOVIVA)
 | ||
|       {
 | ||
|         if (fname == RMI_NUMRIG)
 | ||
|         {
 | ||
|           const int nriga = atoi(field);
 | ||
|           field.format("%3d", nriga);
 | ||
|         }         
 | ||
|       }
 | ||
|       
 | ||
|       if (logicnum == LF_MOV && ( fname == MOV_NUMREG || flag == 2 ) ) 
 | ||
|       {  
 | ||
|         if (fname == MOV_NUMREG)
 | ||
|         {
 | ||
|           dep->put(MOV_NUMREG,   _numreg);
 | ||
|           dep->put(MOV_OCFPI,    cfpi);
 | ||
|         }
 | ||
|             
 | ||
|         if (flag == 2)
 | ||
|         {
 | ||
|           TString80 f = converti(field,false);
 | ||
|           dep->put(fname,f);
 | ||
|         }                                       
 | ||
|       }
 | ||
|       else
 | ||
|         if (logicnum == LF_RMOVIVA && fname == RMI_NUMREG)
 | ||
|         {
 | ||
|           TString4 tipodoc;
 | ||
|           const int annoes = cerca_annoes(_numreg,tipodoc);                    
 | ||
|           dep->put("ANNOES", annoes);                                     
 | ||
|           dep->put("NUMREG", _numreg);
 | ||
|         }
 | ||
|         else
 | ||
|           dep->put(fname, field);          
 | ||
|       
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*)sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key(key));
 | ||
|         
 | ||
|     _prog->addstatus(1);                                  
 | ||
|     trasfer_data_moviva(*file, *dep);
 | ||
|     
 | ||
|     if (create)
 | ||
|       create = false;
 | ||
|         
 | ||
|     delete file;
 | ||
|     delete dep;
 | ||
|   } // if (trc.is_key((const char*) key))
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::trasfer_data_moviva(TIsamtempfile& file, const TRectype& dep)
 | ||
| {   
 | ||
|   if (dep.get_long(MOV_NUMREG) <= 0)
 | ||
|     return NOERR;
 | ||
| 
 | ||
|   file.curr() = dep;           
 | ||
|   if (file.read() == NOERR)     
 | ||
|   { 
 | ||
|     if (dep.num() == LF_MOV)
 | ||
|     { 
 | ||
|       TDate data74ter = dep.get_date(MOV_DATA74TER);
 | ||
|       TString4 codval    (dep.get     (MOV_CODVALI));   
 | ||
|       TString80 ocfpi     (dep.get     (MOV_OCFPI));
 | ||
|       long    codcf     = dep.get_long(MOV_CODCF);
 | ||
|       real    cambioi   (dep.get_real(MOV_CAMBIOI));
 | ||
|       real    corrlire  (dep.get_real(MOV_CORRLIRE));
 | ||
|       real    corrvaluta(dep.get_real(MOV_CORRVALUTA));
 | ||
|       file.put(MOV_DATA74TER, data74ter);
 | ||
|       file.put(MOV_CODVALI,   codval);            
 | ||
|       file.put(MOV_OCFPI,     ocfpi);
 | ||
|       file.put(MOV_CODCF,     codcf);
 | ||
|       file.put(MOV_CAMBIOI,   cambioi);
 | ||
|       file.put(MOV_CORRLIRE,  corrlire);
 | ||
|       file.put(MOV_CORRVALUTA,corrvaluta);
 | ||
|     }
 | ||
|     else
 | ||
|     {
 | ||
|       file.curr() = dep;
 | ||
|     }
 | ||
|     file.rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     file.curr() = dep;     
 | ||
|     file.write();    
 | ||
|   }
 | ||
|   
 | ||
|   return NOERR;
 | ||
| }                    
 | ||
| 
 | ||
| void TTransfer_file::tipo_anagrafica(TString& record,TString& tipoc)
 | ||
| {
 | ||
|   char tipo = (record.sub(15,16))[0];
 | ||
|   switch (tipo)
 | ||
|   {
 | ||
|   case '1':
 | ||
|     tipoc = "C";
 | ||
|     break;
 | ||
|   case '2':
 | ||
|     tipoc = "F";
 | ||
|     break;
 | ||
|   case '3': 
 | ||
|     tipoc = " ";
 | ||
|   default:
 | ||
|     break;
 | ||
|   };              
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::ultima_riga_partita(TString& record)
 | ||
| {                     
 | ||
|   TString tipoc;                         
 | ||
|   int  riga = 0;
 | ||
|   
 | ||
|   TRecnotype rec = _tpart->recno();
 | ||
|   TIsamtempfile& tpart = *_tpart;
 | ||
|   
 | ||
|   tipo_anagrafica(record,tipoc);
 | ||
|   
 | ||
|   int  gruppo = atoi(record.sub(16,18));
 | ||
|   int  conto  = atoi(record.sub(18,20));
 | ||
|   long sottoc = atol(record.sub(20,26));
 | ||
|   
 | ||
|   tpart.setkey(1);
 | ||
|   tpart.zero();
 | ||
|   tpart.put(PART_TIPOCF,     tipoc);
 | ||
|   tpart.put(PART_GRUPPO,     gruppo);
 | ||
|   tpart.put(PART_CONTO,      conto);
 | ||
|   tpart.put(PART_SOTTOCONTO, sottoc);
 | ||
|   tpart.put(PART_ANNO,       _annoSC);
 | ||
|   tpart.put(PART_NUMPART,    _numpartSC);
 | ||
|   
 | ||
|   const TRectype partita(tpart.curr());
 | ||
|   
 | ||
|   for (tpart.read(_isgteq); !tpart.eof(); tpart.next())
 | ||
|   {      
 | ||
|     TString16 part_rec  = partita.get(PART_NUMPART);      //CONF
 | ||
|     TString16 part_file = tpart.get(PART_NUMPART);
 | ||
|     if (tpart.curr() != partita || part_file != part_rec) break;
 | ||
|     
 | ||
|     riga = tpart.get_int(PART_NRIGA);
 | ||
|   }                                  
 | ||
|   
 | ||
|   _tpart->readat(rec);
 | ||
|   
 | ||
|   return riga+1;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_tmp_movSC(TString& record)
 | ||
| {             
 | ||
|   TString annostr;
 | ||
|   
 | ||
|   _nregSC    = atol(record.sub(2,8));
 | ||
|   _numrigSC  = atoi(record.sub(8,10));
 | ||
|   TString app (record.sub(26,28));
 | ||
|   int     anno = atoi(app);
 | ||
|   if (anno < 80)
 | ||
|     annostr = "20"; 
 | ||
|   else 
 | ||
|     annostr = "19";
 | ||
|   annostr << app;
 | ||
|   _annoSC    = atoi(annostr);
 | ||
|   _numpartSC = record.sub(28,35);
 | ||
| 
 | ||
|   int tipomov = atoi(record.sub(37,38));
 | ||
|     
 | ||
|   if (_nregSC != _nregSC_p || _numrigSC != _numrigSC_p || 
 | ||
|       _annoSC != _annoSC_p || _numpartSC != _numpartSC_p)
 | ||
|     _nrigaSC = ultima_riga_partita(record);
 | ||
|   
 | ||
|   _nregSC_p    = _nregSC;
 | ||
|   _numrigSC_p  = _numrigSC;
 | ||
|   _annoSC_p    = _annoSC;
 | ||
|   _annoSCA     = _annoSC;
 | ||
|   _numpartSC_p = _numpartSC;                         
 | ||
|   
 | ||
|   partita(record);          
 | ||
|   if (tipomov == 1)
 | ||
|     scadenza(record);    
 | ||
|   else
 | ||
|     pagsca(record);
 | ||
|         
 | ||
|   _prog->addstatus(1);                                  
 | ||
| }
 | ||
| 
 | ||
| /* Guy: Funzione in disuso??? 
 | ||
| void TTransfer_file::calcola_imposta(const TString& field, real& imposta)
 | ||
| {                                    
 | ||
|   TString256 buffer;
 | ||
|   
 | ||
|   TRecnotype rec = _ttab->recno();
 | ||
|   TIsamtempfile& tab = *_ttab; 
 | ||
|   
 | ||
|   long nreg = atol(field);
 | ||
|   TString16 app; app.format("%2s%06ld", (const char*) "U1", nreg);
 | ||
| 
 | ||
|   TRic_recfield recf (tab.curr(), "S0", 0, 256);
 | ||
|     
 | ||
|   tab.zero();
 | ||
|   tab.put("CODTAB", app);
 | ||
| 
 | ||
|   const TRectype rectab (tab.curr());
 | ||
|     
 | ||
|   for (tab.read(); !tab.eof(); tab.next())
 | ||
|   {
 | ||
|     if (tab.curr() > rectab) break;
 | ||
|     
 | ||
|     buffer = (const char*)recf;
 | ||
|                                   
 | ||
|     app = buffer.sub(34,43);
 | ||
|     negativo(app);
 | ||
|     if (ditta_in_euro())
 | ||
|       app.insert(".", app.len()-2);
 | ||
|     
 | ||
|     const real imp = app;
 | ||
|     imposta += imp;                              
 | ||
|   } 
 | ||
|   _ttab->readat(rec);
 | ||
| }
 | ||
| */
 | ||
| 
 | ||
| bool TTransfer_file::solo_SC(TString& field)
 | ||
| {                                           
 | ||
|   TIsamtempfile tmov (LF_MOV, _tmpmov, false);
 | ||
|   
 | ||
|   long nreg = atol(field);
 | ||
|                 
 | ||
|   tmov.setkey(1);              
 | ||
|   tmov.zero();   
 | ||
|   tmov.put(MOV_NUMREG, nreg);
 | ||
|   if (tmov.read() == NOERR)
 | ||
|     return false;      
 | ||
|   
 | ||
|   return true;  
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::calcola_impdocval(long nreg,int nrig,TString& record)
 | ||
| {
 | ||
|   int key = _tpart->getkey();      
 | ||
|   TRecnotype rec = _tpart->recno();
 | ||
|   TIsamtempfile& part = *_tpart;
 | ||
|   bool prima_volta = true;
 | ||
|   real doc,val;
 | ||
|   
 | ||
|   doc = ZERO;
 | ||
|   val = ZERO;
 | ||
|  
 | ||
|   real itdoc (record.sub(116,127));
 | ||
|   TString app (record.sub(127,140));
 | ||
|   negativo(app);
 | ||
|   decimali(app,3);
 | ||
|   real itval (app);
 | ||
|       
 | ||
|   part.setkey(2);
 | ||
|   part.zero();
 | ||
|   part.put(PART_NREG,   nreg);
 | ||
|   part.put(PART_NUMRIG, nrig);
 | ||
|       
 | ||
|   TRectype partita (part.curr());
 | ||
|       
 | ||
|   for (part.read(); !part.eof(); part.next())
 | ||
|   { 
 | ||
|     TString part_rec  = partita.get(PART_NUMPART);
 | ||
|     TString part_file = part.get(PART_NUMPART);       
 | ||
|     
 | ||
|     if (part.curr() > partita || part_file != part_rec) break;
 | ||
|     
 | ||
|     if (prima_volta )
 | ||
|     {    
 | ||
|       doc = part.get_real(PART_IMPTOTDOC) + itdoc;
 | ||
|       val = part.get_real(PART_IMPTOTVAL) + itval;
 | ||
|       prima_volta = false;
 | ||
|     }
 | ||
|         
 | ||
|     part.put(PART_IMPTOTDOC, doc);
 | ||
|     part.put(PART_IMPTOTVAL, val);  
 | ||
|     part.setkey(1);
 | ||
|     part.rewrite();
 | ||
|     part.setkey(2);
 | ||
|   }                
 | ||
|   _tpart->readat(rec);
 | ||
|   _tpart->setkey(key);
 | ||
| }
 | ||
| 
 | ||
| // Scrive partita da record di sistema a record di file temporaneo
 | ||
| void TTransfer_file::partita(TString& record)
 | ||
| {                          
 | ||
|   const TMappa_trc& trc = mappa();
 | ||
|   TString     sigla,key;
 | ||
|   int         numfield;     // Campo di partenza del saldaconto su cgtrc.ini
 | ||
|   TString     tipoc;
 | ||
|   bool        solo_saldaconto = false;                        
 | ||
|   static long numreg;
 | ||
|   static int  numrig;
 | ||
|   
 | ||
|   int tipomov = atoi(record.sub(37,38));
 | ||
| 
 | ||
|   if (tipomov == 1)
 | ||
|     numfield = 1;
 | ||
|   else
 | ||
|     if (tipomov == 2)
 | ||
|       numfield = 50;
 | ||
|     else 
 | ||
|       if (tipomov == 3 || tipomov == 4 || tipomov == 5 || tipomov == 6)
 | ||
|         numfield = 100;
 | ||
|          
 | ||
|   sigla     = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
|     
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     _deppart->zero();
 | ||
| 
 | ||
|     tipo_anagrafica(record,tipoc);
 | ||
| 
 | ||
|     do
 | ||
|     {
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString16 fname = trc.field_name(key); 
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       int     dec   = trc.flag_bis(key);
 | ||
|       
 | ||
|       if (dec == 5 && fname == "CAMBIO")  // CM500412
 | ||
|       {
 | ||
|         if (record[160] == '6')
 | ||
|           dec = 6;
 | ||
|       }
 | ||
| 
 | ||
|       TRecfield campo (*_deppart,fname);
 | ||
|       if (campo.type() == _realfld)
 | ||
|       {
 | ||
|         negativo(field);
 | ||
|         
 | ||
|         // Cerco di riconoscere gli importi in euro  
 | ||
|         if (dec == 0 && (to-from) >= 8 && record.size()==sizeT && ditta_in_euro())
 | ||
|         {
 | ||
|           flag = 3;
 | ||
|           dec = 2;
 | ||
|         }
 | ||
|       }
 | ||
| 
 | ||
|       if (flag == 3)
 | ||
|       { 
 | ||
|         if (dec > 0)
 | ||
|           decimali(field,dec);
 | ||
|         const real appoggio = field;
 | ||
|         field = appoggio.string(0, dec);
 | ||
|       }
 | ||
| 
 | ||
|       if (fname == "TIPOC")
 | ||
|         field = tipoc;
 | ||
| 
 | ||
|       if (fname == "GRUPPO" || fname == "CONTO" || fname == "GRUPPOCL" || fname == "CONTOCL")
 | ||
|       {
 | ||
|         int app = atoi(field);
 | ||
|         field.format("%3d", app);
 | ||
|       }        
 | ||
|       if (fname == "SOTTOCONTO")
 | ||
|       {
 | ||
|         long sottoc = atol(field);
 | ||
|         field.format("%6ld", sottoc);
 | ||
|       }
 | ||
|       if (fname == "ANNO")
 | ||
|       {
 | ||
|         TString16 app  = field;
 | ||
|         int     anno = atoi(field);
 | ||
|         if (anno < 80)
 | ||
|         {
 | ||
|           field = "20"; 
 | ||
|           field << app;
 | ||
|         }
 | ||
|         else 
 | ||
|         {
 | ||
|           field = "19";
 | ||
|           field << app; 
 | ||
|         }
 | ||
|       }
 | ||
|       if (fname == "NRIGA") 
 | ||
|       {
 | ||
|         TString app (format("%4d", _nrigaSC));
 | ||
|         field = app;        
 | ||
|       }
 | ||
|       if (fname == "NREG")
 | ||
|       { 
 | ||
|         solo_saldaconto = solo_SC(field);
 | ||
|         if (!solo_saldaconto)
 | ||
|         {
 | ||
|           long app = atol(field);
 | ||
|           field.format("%7ld", app);    
 | ||
| /*          real imposta;  
 | ||
|         
 | ||
|           if (tipomov == 1)   // L'imposta va calcolata solo in caso di FATTURA
 | ||
|           {
 | ||
|             calcola_imposta(field,imposta);
 | ||
|             _deppart->put("IMPOSTA", imposta);  
 | ||
|           }   */
 | ||
|         }
 | ||
|         else 
 | ||
|           field = "";               
 | ||
|         numreg = atol(field);  
 | ||
|       }
 | ||
|       if (fname == "NUMRIG")
 | ||
|       { 
 | ||
|         if (!solo_saldaconto) 
 | ||
|         {
 | ||
|           int app = atoi(field);
 | ||
|           field.format("%3d", app);      
 | ||
|         }
 | ||
|         else
 | ||
|           field = "";        
 | ||
|         numrig = atoi(field);  
 | ||
|       }
 | ||
|       if (fname == "REG")
 | ||
|       {                         
 | ||
|         if (real::is_natural(field))
 | ||
|           field.format("%03s", (const char*)field);
 | ||
|         else
 | ||
|           field.format("%-3s", (const char*)field);
 | ||
|       }                           
 | ||
| 
 | ||
|       if (fname == "CODCAUS")
 | ||
|         if (field == "000" /* || solo_saldaconto */)   // Il codice causale serve! CM600476
 | ||
|           field = "";
 | ||
|       
 | ||
|       if (flag == 2)
 | ||
|       {
 | ||
|         TString f = converti(field,false);
 | ||
|         _deppart->put(fname,f);
 | ||
|       }
 | ||
|       else
 | ||
|         _deppart->put(fname, field);
 | ||
| 
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));
 | ||
|   }  // if (trc.is_key((const char*) key)
 | ||
|   
 | ||
|   _tpart->setkey(1);
 | ||
|   _tpart->zero();
 | ||
|   _tpart->curr() = *_deppart;
 | ||
|   if (_tpart->read() != NOERR)
 | ||
|   {     
 | ||
|     _tpart->zero();
 | ||
|     _tpart->curr() = *_deppart;
 | ||
|     _tpart->write();
 | ||
|   }
 | ||
|   
 | ||
| //  if (tipomov != 1 && tipomov != 4) 
 | ||
| //    calcola_impdocval(numreg,numrig,record);
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::calcola_importo(TString& record)
 | ||
| {                               
 | ||
|   TString tipoc;
 | ||
|   TRecnotype rec = _tpart->recno();
 | ||
|   TIsamtempfile& part = *_tpart;
 | ||
|   
 | ||
|   tipo_anagrafica(record,tipoc);
 | ||
|   
 | ||
|   part.setkey(1);
 | ||
|   part.zero();
 | ||
|   part.put(PART_TIPOCF,     tipoc);
 | ||
|   part.put(PART_GRUPPO,     (atoi(record.sub(16,18))));
 | ||
|   part.put(PART_CONTO,      (atoi(record.sub(18,20))));
 | ||
|   part.put(PART_SOTTOCONTO, (atol(record.sub(20,26)))); 
 | ||
|   part.put(PART_ANNO,       _SCAanno);
 | ||
|   part.put(PART_NUMPART,    record.sub(28,35));
 | ||
|   part.put(PART_NRIGA,      _nrigaSC);
 | ||
|   if (part.read() == NOERR)
 | ||
|   { 
 | ||
|     _imp    += part.get_real(PART_IMPORTO);
 | ||
|     _impval += part.get_real(PART_IMPORTOVAL);
 | ||
|     part.put(PART_IMPORTO,    _imp);
 | ||
|     part.put(PART_IMPORTOVAL, _impval);
 | ||
|     
 | ||
|     int err = part.rewrite();  
 | ||
|     _imp    = ZERO;
 | ||
|     _impval = ZERO;
 | ||
|   }    
 | ||
|   _tpart->readat(rec);    
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::scadenza(TString& record)
 | ||
| {                          
 | ||
|   const TMappa_trc& trc = mappa();
 | ||
|   TString     sigla,key,app_imp,app_val;
 | ||
|   int         numfield = 150;
 | ||
|   TString     tipoc;              
 | ||
|   static bool prima_volta = true;          
 | ||
| 
 | ||
|   int tipomov = atoi(record.sub(37,38));
 | ||
|    
 | ||
|   sigla     = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
|     
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     _depscad->zero();
 | ||
| 
 | ||
|     tipo_anagrafica(record,tipoc);
 | ||
| 
 | ||
|     do
 | ||
|     {
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString fname = trc.field_name(key); 
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       int     dec   = trc.flag_bis(key);
 | ||
| 
 | ||
|       TRecfield campo (*_depscad,fname);
 | ||
|       if (campo.type() == _realfld)
 | ||
|       {
 | ||
|         negativo(field);
 | ||
|       
 | ||
|         // Cerco di riconoscere gli importi in euro  
 | ||
|         if (dec == 0 && (to-from) >= 8 && record.size()<1024 && ditta_in_euro())
 | ||
|         {
 | ||
|           flag = 3;
 | ||
|           dec = 2;
 | ||
|         }
 | ||
|       }
 | ||
|       
 | ||
|       if (flag == 3)
 | ||
|       { 
 | ||
|         if (dec > 0)
 | ||
|           decimali(field,dec);
 | ||
|         const real appoggio = field;
 | ||
|         field = appoggio.string(0, dec);
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == "IMPORTO")
 | ||
|         app_imp = field;
 | ||
|       if (fname == "IMPORTOVAL")
 | ||
|         app_val = field;
 | ||
|         
 | ||
|       if (fname == "TIPOC")
 | ||
|         field = tipoc;
 | ||
| 
 | ||
|       if (fname == "GRUPPO" || fname == "CONTO")
 | ||
|       {
 | ||
|         int app = atoi(field);
 | ||
|         field.format("%3d", app);
 | ||
|       }        
 | ||
|       if (fname == "SOTTOCONTO")
 | ||
|       {
 | ||
|         long sottoc = atol(field);
 | ||
|         field.format("%6ld", sottoc);
 | ||
|       }
 | ||
|       if (fname == "ANNO")
 | ||
|       {  
 | ||
|         TString app  = field;
 | ||
|         int     anno = atoi(field);
 | ||
|         if (anno < 80)
 | ||
|         {
 | ||
|           field = "20"; 
 | ||
|           field << app;
 | ||
|         }
 | ||
|         else 
 | ||
|         {
 | ||
|           field = "19";
 | ||
|           field << app; 
 | ||
|         }
 | ||
|         _annoSCA = atoi(field);
 | ||
|       }
 | ||
|       if (fname == "NRIGA") 
 | ||
|       {
 | ||
|         TString app (format("%4d", _nrigaSC));
 | ||
|         field = app;        
 | ||
|       }
 | ||
| 
 | ||
|       //Il codice pagamento su AS400 e' un alfanumerico di due, mentre su PC e' un
 | ||
|       //alfanumerico di 4 trattato con il flag Z. Dunque in ricezione se si tratta
 | ||
|       //di un numero va riempito con degli 0. Se si tratta di un alfa va allineato a destra.                       
 | ||
|       if (fname == "CODPAG")
 | ||
|       { 
 | ||
|         TString16 f = field;
 | ||
|         field.format("%-4s", (const char*) f);
 | ||
|       }
 | ||
| 
 | ||
|       if (flag == 2)
 | ||
|       {
 | ||
|         TString f = converti(field,false);
 | ||
|         _depscad->put(fname,f);
 | ||
|       }
 | ||
|       else
 | ||
|         _depscad->put(fname, field);
 | ||
| 
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));
 | ||
|   }  // if (trc.is_key((const char*) key)
 | ||
|   
 | ||
|   _tscad->setkey(1);
 | ||
|   _tscad->zero();
 | ||
|   _tscad->curr() = *_depscad;
 | ||
|   
 | ||
|   if (_tscad->read() == NOERR)     
 | ||
|   { 
 | ||
|     _tscad->zero();
 | ||
|     _tscad->curr() = *_depscad;
 | ||
|     _tscad->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _tscad->zero();
 | ||
|     _tscad->curr() = *_depscad;     
 | ||
|     _tscad->write();    
 | ||
|   }                                      
 | ||
| 
 | ||
|   if (prima_volta)
 | ||
|   {
 | ||
|     _SCAnreg_p    = -1;
 | ||
|     _SCAnumrig_p  = -1;
 | ||
|     _SCAanno_p    = -1;
 | ||
|     _SCAnumpart_p = "-1";
 | ||
|   }
 | ||
|   
 | ||
|   TString annostr;
 | ||
|   
 | ||
|   _SCAnreg      = atol(record.sub(2,8));
 | ||
|   _SCAnumrig    = atoi(record.sub(8,10));
 | ||
|   TString app (record.sub(26,28));
 | ||
|   int     anno = atoi(app);
 | ||
|   if (anno < 80)
 | ||
|     annostr = "20"; 
 | ||
|   else 
 | ||
|     annostr = "19";
 | ||
|   annostr << app;
 | ||
|   _SCAanno      = atoi(annostr);
 | ||
|   _SCAnumpart   = record.sub(28,35);
 | ||
|   real imp (app_imp);
 | ||
|   real val (app_val);
 | ||
|   _imp    = imp;
 | ||
|   _impval = val;
 | ||
| //  calcola_importo(record);  
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::recupera_scadenze(TString& record,TString& tipo)
 | ||
| {
 | ||
|   TRecnotype rec = _tscad->recno();
 | ||
|   TIsamtempfile& scad = *_tscad;
 | ||
|   int num_scad = 0;   
 | ||
|   TString recs,file;
 | ||
|   
 | ||
|   int rata = atoi(record.sub(35,37));
 | ||
|   
 | ||
|   scad.setkey(1);
 | ||
|   scad.zero();
 | ||
|   scad.put(SCAD_TIPOCF,     tipo);
 | ||
|   scad.put(SCAD_GRUPPO,     (atoi(record.sub(16,18))));
 | ||
|   scad.put(SCAD_CONTO,      (atoi(record.sub(18,20))));
 | ||
|   scad.put(SCAD_SOTTOCONTO, (atol(record.sub(20,26)))); 
 | ||
|   scad.put(SCAD_ANNO,       _annoSCA);
 | ||
|   scad.put(SCAD_NUMPART,    record.sub(28,35));
 | ||
|   
 | ||
|   TRectype scadenza (scad.curr());
 | ||
|   
 | ||
|   for (scad.read(); !scad.eof(); scad.next())
 | ||
|   {                
 | ||
|     recs = scadenza.get(SCAD_NUMPART);
 | ||
|     file = scad.get(SCAD_NUMPART);
 | ||
| 
 | ||
|     if (scad.curr() != scadenza || file != recs) break;
 | ||
|     
 | ||
|     if (scad.get_int(SCAD_NRATA) != rata) continue;
 | ||
|     
 | ||
|     num_scad++; 
 | ||
|     _nrigaSCA = scad.get_int(SCAD_NRIGA);
 | ||
|     _nrataSCA = scad.get_int(SCAD_NRATA);
 | ||
|   }                                                                               
 | ||
|   _tscad->readat(rec);
 | ||
| 
 | ||
|   return num_scad;
 | ||
| }
 | ||
| 
 | ||
| char TTransfer_file::what_is_this(TString& record,TString& tipo)
 | ||
| { 
 | ||
|   TRecnotype rec = _ttab->recno();
 | ||
|   TIsamtempfile& ttab = *_ttab;
 | ||
|   TString    buffer(sizeT);
 | ||
|   
 | ||
|   char caso = 'p';
 | ||
| 
 | ||
|   int     tipomov = atoi(record.sub(37,38));
 | ||
|   
 | ||
|   if (tipomov != 2 && tipomov != 4)
 | ||
|   { 
 | ||
|     TRic_recfield recf (ttab.curr(), "S0", 0, sizeT);  
 | ||
|     
 | ||
|     const long nreg    = atol(record.sub(2,8));
 | ||
|     const int  nriga   = atoi(record.sub(8,10));
 | ||
|     const int  anno    = atoi(record.sub(26,28));
 | ||
|     const TString8 numpart = record.sub(28,35); 
 | ||
|     const int  nrata   = atoi(record.sub(35,37));
 | ||
|     const int  num_rig = atoi(record.sub(10,13));
 | ||
|   
 | ||
|     TString80 dep;
 | ||
|     dep.format("%2s%d%06ld%02d%2d%7s%02d", (const char*)"B1",3,nreg,nriga,anno,(const char*)numpart,nrata);         
 | ||
|   
 | ||
|     ttab.zero();
 | ||
|     ttab.put("CODTAB", dep);
 | ||
|   
 | ||
|     TRectype tabella (ttab.curr());
 | ||
|   
 | ||
|     for (ttab.read(_isgteq); !ttab.eof(); ttab.next())
 | ||
|     {
 | ||
|       if (ttab.curr() > tabella) break;
 | ||
| 
 | ||
|       buffer = (const char*) recf;    
 | ||
|       
 | ||
|       int b1nurt = atoi(buffer.sub(10,13));
 | ||
|       int tipo   = atoi(buffer.sub(37,38));
 | ||
|     
 | ||
|       if (b1nurt < num_rig && (tipo != 2 && tipo != 4))  
 | ||
|       {
 | ||
|         _esiste_pagsca = true;  
 | ||
|         break;
 | ||
|       }
 | ||
|     }
 | ||
|   }   
 | ||
|   
 | ||
|   if (_esiste_pagsca)
 | ||
|     caso = 'r';
 | ||
|   
 | ||
|   TString4 codval = record.sub(79,82);
 | ||
|   codval.trim();
 | ||
|   real impv (record.sub(127,140));
 | ||
|   
 | ||
|   if (tipomov == 4)
 | ||
|   { 
 | ||
|     if (codval.empty() || (codval.not_empty() && impv != ZERO))
 | ||
|       caso = 'a';
 | ||
|     if (codval.not_empty() && impv == ZERO)
 | ||
|       caso = 'd';  
 | ||
|   }              
 | ||
|   _ttab->readat(rec);
 | ||
|   return caso;
 | ||
| }
 | ||
| 
 | ||
| /*
 | ||
| void TTransfer_file::aggiorna_partita(TString& record,TString& tipo,real& importo,real& importoval,
 | ||
|                                       real& abbuoni,real& diffcam,real& ritenute,real& ritsoc)
 | ||
| { 
 | ||
|   TRecnotype rec = _tpart->recno();
 | ||
|   TIsamtempfile& part = *_tpart;
 | ||
|   real    abb,diff;
 | ||
|   TString sez    = ""; 
 | ||
|   TString sezabb = "";  
 | ||
|   TString sezdc  = "";
 | ||
| 
 | ||
|   abb  = ZERO;
 | ||
|   diff = ZERO;
 | ||
|   
 | ||
|   part.setkey(1);
 | ||
|   part.zero();
 | ||
|   part.put(PART_TIPOCF,     tipo);
 | ||
|   part.put(PART_GRUPPO,     (atoi(record.sub(16,18))));
 | ||
|   part.put(PART_CONTO,      (atoi(record.sub(18,20))));
 | ||
|   part.put(PART_SOTTOCONTO, (atol(record.sub(20,26)))); 
 | ||
|   part.put(PART_ANNO,       _annoSCA);
 | ||
|   part.put(PART_NUMPART,    record.sub(28,35));
 | ||
|   part.put(PART_NRIGA,      _nrigaSC);
 | ||
|   if (part.read() == NOERR)
 | ||
|   { 
 | ||
|     sez      = part.get     (PART_SEZ);
 | ||
|     sezabb   = part.get     (PART_SEZABB);
 | ||
|     sezdc    = part.get     (PART_SEZDIFCAM);
 | ||
|     real imp = part.get_real(PART_IMPORTO) + importo;
 | ||
|     real val = part.get_real(PART_IMPORTOVAL) + importoval;
 | ||
|     
 | ||
|     part.put(PART_IMPORTO, imp);
 | ||
|     part.put(PART_IMPORTOVAL, val);
 | ||
| 
 | ||
|     real ritf = part.get_real(PART_RITENUTE) + ritenute;
 | ||
|     part.put(PART_RITENUTE, ritf);
 | ||
| 
 | ||
|     real rits = part.get_real(PART_RITSOC) + ritsoc;
 | ||
|     part.put(PART_RITSOC, rits);
 | ||
|     
 | ||
|     if (abbuoni != ZERO)
 | ||
|     {  
 | ||
|       if (sezabb.empty())  
 | ||
|       {
 | ||
|         abb = part.get_real(PART_ABBUONI) + abbuoni;
 | ||
|         sezabb = sez;
 | ||
|       }
 | ||
|       else
 | ||
|         if (sez == sezabb)
 | ||
|           abb = part.get_real(PART_ABBUONI) + abbuoni;        
 | ||
|         else
 | ||
|           abb = part.get_real(PART_ABBUONI) - abbuoni;                
 | ||
|       if (abb < ZERO)
 | ||
|       {
 | ||
|         abb = abb * -1;
 | ||
|         if (sezabb == "D")
 | ||
|           sezabb = "A";
 | ||
|         else          
 | ||
|           if (sezabb == "A")
 | ||
|           sezabb = "D";
 | ||
|       }            
 | ||
|       part.put(PART_SEZABB,  sezabb);   
 | ||
|       part.put(PART_ABBUONI, abb);  
 | ||
|     }
 | ||
|     
 | ||
|     if (diffcam != ZERO)
 | ||
|     {
 | ||
|       if (sezdc.empty())  
 | ||
|       {
 | ||
|         diff = part.get_real(PART_DIFFCAM) + diffcam;
 | ||
|         sezdc = sez;
 | ||
|       }
 | ||
|       else
 | ||
|         if (sez == sezdc)
 | ||
|           diff = part.get_real(PART_DIFFCAM) + diffcam;        
 | ||
|         else
 | ||
|           diff = part.get_real(PART_DIFFCAM) - diffcam;                
 | ||
|       if (diff < ZERO)
 | ||
|       {
 | ||
|         diff = diff * -1;
 | ||
|         if (sezdc == "D")
 | ||
|           sezdc = "A";
 | ||
|         else          
 | ||
|           if (sezdc == "A")
 | ||
|           sezdc = "D";      
 | ||
|       }                
 | ||
|       part.put(PART_SEZDIFCAM, sezdc);   
 | ||
|       part.put(PART_DIFFCAM,   diff);
 | ||
|     }
 | ||
|     part.rewrite();
 | ||
|   }         
 | ||
|   _tpart->readat(rec);
 | ||
| }
 | ||
| */
 | ||
| 
 | ||
| char TTransfer_file::leggi_sez_partita(TString& record,TString& tipo)
 | ||
| { 
 | ||
|   TRecnotype rec = _tpart->recno();
 | ||
|   TIsamtempfile& part = *_tpart;
 | ||
|   
 | ||
|   char sez = '\0'; 
 | ||
|            
 | ||
|   part.setkey(1);
 | ||
|   part.zero();
 | ||
|   part.put(PART_TIPOCF,     tipo);
 | ||
|   part.put(PART_GRUPPO,     (atoi(record.sub(16,18))));
 | ||
|   part.put(PART_CONTO,      (atoi(record.sub(18,20))));
 | ||
|   part.put(PART_SOTTOCONTO, (atol(record.sub(20,26)))); 
 | ||
|   part.put(PART_ANNO,       _annoSCA);
 | ||
|   part.put(PART_NUMPART,    record.sub(28,35));
 | ||
|   part.put(PART_NRIGA,      _nrigaSC);
 | ||
|   if (part.read() == NOERR)
 | ||
|     sez = part.get_char(PART_SEZ);
 | ||
| 
 | ||
|   _tpart->readat(rec);
 | ||
|   
 | ||
|   return sez;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::pagsca(TString& record)
 | ||
| {                          
 | ||
|   const TMappa_trc& trc  = mappa();
 | ||
|   TString     sigla,key;
 | ||
|   int         numfield = 200;     
 | ||
|   TString     tipoc;            
 | ||
|   real        importo,importoval,abbuoni,diffcam,ritenute,imp,impv;
 | ||
|   bool        solo_saldaconto = false; 
 | ||
|   char        sez,sezione;  
 | ||
|   
 | ||
|   
 | ||
|   importo    = ZERO;
 | ||
|   importoval = ZERO;
 | ||
|   abbuoni    = ZERO;
 | ||
|   diffcam    = ZERO;
 | ||
|   ritenute   = ZERO;                            
 | ||
|   imp        = ZERO;
 | ||
|   impv       = ZERO;
 | ||
|   
 | ||
|   _esiste_pagsca = false;                       
 | ||
|   
 | ||
|   int tipomov = atoi(record.sub(37,38));
 | ||
|   
 | ||
|   tipo_anagrafica(record,tipoc);
 | ||
|   
 | ||
|   int  num_scad = recupera_scadenze(record,tipoc);  
 | ||
|   if (num_scad == 0 || num_scad > 1)
 | ||
|   {
 | ||
|     _nrigaSCA = 9999;
 | ||
|     _nrataSCA = 9999;
 | ||
|   }  
 | ||
|   
 | ||
|   // Questa funzione ritorna: - 'p' nel caso di pagamento        
 | ||
|   //                          - 'r' nel caso di ritenuta
 | ||
|   //                          - 'a' nel caso di abbuono
 | ||
|   //                          - 'd' nel caso di differenza cambio
 | ||
|   char caso     = what_is_this(record,tipoc);  // I don't know
 | ||
|   
 | ||
|   sigla     = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
|     
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     _deppagsca->zero();
 | ||
| 
 | ||
|     do
 | ||
|     {
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString fname = trc.field_name(key); 
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       int     dec   = trc.flag_bis(key);
 | ||
|       
 | ||
|       if (fname != "IMP" && fname != "SEZ") 
 | ||
|       {
 | ||
|         TRecfield campo (*_deppagsca,fname);
 | ||
|         if (campo.type() == _realfld)
 | ||
|         {
 | ||
|           negativo(field);  
 | ||
|           // Cerco di riconoscere gli importi in euro  
 | ||
|           if (dec == 0 && (to-from) >= 8 && record.size()<1024 && ditta_in_euro())
 | ||
|           {
 | ||
|             flag = 3;
 | ||
|             dec = 2;
 | ||
|           }
 | ||
|         }
 | ||
|       }
 | ||
| 
 | ||
|       if (flag == 3)
 | ||
|       { 
 | ||
|         if (dec > 0)
 | ||
|           decimali(field,dec);
 | ||
| 
 | ||
|         real appoggio (field);    
 | ||
|       }
 | ||
| 
 | ||
|       if (fname == "TIPOC")
 | ||
|         field = tipoc;
 | ||
| 
 | ||
|       if (fname == "GRUPPO" || fname == "CONTO")
 | ||
|       {
 | ||
|         int app = atoi(field);
 | ||
|         field.format("%3d", app);
 | ||
|       }        
 | ||
|       if (fname == "SOTTOCONTO")
 | ||
|       {
 | ||
|         long sottoc = atol(field);
 | ||
|         field.format("%6ld", sottoc);
 | ||
|       }
 | ||
|       if (fname == "ANNO")
 | ||
|       {
 | ||
|         TString app  = field;
 | ||
|         int     anno = atoi(field);
 | ||
|         if (anno < 80)
 | ||
|         {
 | ||
|           field = "20"; 
 | ||
|           field << app;
 | ||
|         }
 | ||
|         else 
 | ||
|         {
 | ||
|           field = "19";
 | ||
|           field << app; 
 | ||
|         }
 | ||
|       }
 | ||
|       if (fname == "NRIGA") 
 | ||
|       { 
 | ||
|         TString app (format("%4d", _nrigaSCA));
 | ||
|         field = app;        
 | ||
|       }
 | ||
|       if (fname == "NRATA")
 | ||
|       {
 | ||
|         TString nrata (format("%4d", _nrataSCA));
 | ||
|         field = nrata;        
 | ||
|         TString app (format("%4d", _nrigaSC));
 | ||
|         _deppagsca->put("NRIGP", app);
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == "IMPORTO")
 | ||
|       {
 | ||
|         real appoggio (field);
 | ||
|         importo = appoggio; 
 | ||
|       }
 | ||
|       else 
 | ||
|         if (fname == "IMPORTOVAL")
 | ||
|         {
 | ||
|           real appoggio (field);
 | ||
|           importoval = appoggio;
 | ||
|         }
 | ||
|         else
 | ||
|         if (fname == "IMP")
 | ||
|         { 
 | ||
|           TString4 codval = record.sub(79,82);
 | ||
|           codval.trim();
 | ||
|         
 | ||
|           if (caso == 'a' || caso == 'd')
 | ||
|             _deppagsca->put(PAGSCA_ACCSAL, "S");
 | ||
|         else
 | ||
|           _deppagsca->put(PAGSCA_ACCSAL, "A");
 | ||
|           if (caso == 'p')
 | ||
|           {
 | ||
|             _deppagsca->put(PAGSCA_IMPORTO,    importo);
 | ||
|             _deppagsca->put(PAGSCA_IMPORTOVAL, importoval); 
 | ||
|             imp  = importo;
 | ||
|             impv = importoval;
 | ||
|           }    
 | ||
|           if (caso == 'a')
 | ||
|           {
 | ||
|             if (codval.empty())
 | ||
|               abbuoni = importo;
 | ||
|             else
 | ||
|               abbuoni = importoval; 
 | ||
|           }
 | ||
|           if (caso == 'd')
 | ||
|             diffcam = importo;
 | ||
|           if (caso == 'r')
 | ||
|           {
 | ||
|             ritenute = importo;
 | ||
|             _deppagsca->put(PAGSCA_RITENUTE, ritenute);
 | ||
|           }
 | ||
|                                                    
 | ||
|           sez = leggi_sez_partita(record,tipoc);
 | ||
|         
 | ||
|           if (abbuoni != ZERO)
 | ||
|           {
 | ||
|             if (sez != sezione)
 | ||
|               abbuoni = abbuoni * -1;  
 | ||
|             _deppagsca->put(PAGSCA_ABBUONI, abbuoni);  
 | ||
|           }                          
 | ||
|           if (diffcam != ZERO)
 | ||
|           {
 | ||
|             if (sez != sezione)
 | ||
|               diffcam = diffcam * -1;                
 | ||
|             _deppagsca->put(PAGSCA_DIFFCAM, diffcam);  
 | ||
|           }  
 | ||
|           if (_nrigaSCA == 9999 && _nrataSCA == 9999)
 | ||
|           {
 | ||
|             abbuoni = ZERO;
 | ||
|             diffcam = ZERO;
 | ||
|           }
 | ||
| //          aggiorna_partita(record,tipoc,imp,impv,abbuoni,diffcam,ritenute);        
 | ||
|         }
 | ||
|         else                                               
 | ||
|           if (fname == "SEZ")
 | ||
|           { 
 | ||
|             sezione = field[0];
 | ||
|             if (caso == 'a')
 | ||
|             {
 | ||
|               if (field == "A")
 | ||
|                 _deppagsca->put(PAGSCA_PASSATT, "P");
 | ||
|               else
 | ||
|                 if (field == "D")
 | ||
|                   _deppagsca->put(PAGSCA_PASSATT, "A");
 | ||
|             }
 | ||
|           }
 | ||
|           else
 | ||
|             if (flag == 2)
 | ||
|             {
 | ||
|               TString f = converti(field,false);
 | ||
|               _deppagsca->put(fname,f);
 | ||
|             }
 | ||
|             else
 | ||
|               _deppagsca->put(fname, field);
 | ||
| 
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));
 | ||
|   }  // if (trc.is_key((const char*) key)
 | ||
| 
 | ||
|   _tpagsca->setkey(1);
 | ||
|   _tpagsca->zero();
 | ||
|   _tpagsca->curr() = *_deppagsca;
 | ||
|   
 | ||
|   if (_tpagsca->read() == NOERR)     
 | ||
|   { 
 | ||
|     TString accsal = _tpagsca->get(PAGSCA_ACCSAL);
 | ||
|     real importo   = _tpagsca->get_real(PAGSCA_IMPORTO)    + _deppagsca->get_real(PAGSCA_IMPORTO);
 | ||
|     real valuta    = _tpagsca->get_real(PAGSCA_IMPORTOVAL) + _deppagsca->get_real(PAGSCA_IMPORTOVAL);
 | ||
|     real abbuoni   = _tpagsca->get_real(PAGSCA_ABBUONI)    + _deppagsca->get_real(PAGSCA_ABBUONI);
 | ||
|     real diffcam   = _tpagsca->get_real(PAGSCA_DIFFCAM)    + _deppagsca->get_real(PAGSCA_DIFFCAM);
 | ||
|     real ritenute  = _tpagsca->get_real(PAGSCA_RITENUTE)   + _deppagsca->get_real(PAGSCA_RITENUTE);
 | ||
|     real ritsoc    = _tpagsca->get_real(PAGSCA_RITSOC)     + _deppagsca->get_real(PAGSCA_RITSOC);
 | ||
| 
 | ||
|     if (accsal != "S")
 | ||
|       _tpagsca->put(PAGSCA_ACCSAL, _deppagsca->get(PAGSCA_ACCSAL));  
 | ||
|     if (caso == 'a')  
 | ||
|       _tpagsca->put(PAGSCA_PASSATT, _deppagsca->get(PAGSCA_PASSATT));
 | ||
|     _tpagsca->put(PAGSCA_IMPORTO,    importo);
 | ||
|     _tpagsca->put(PAGSCA_IMPORTOVAL, valuta);
 | ||
|     _tpagsca->put(PAGSCA_ABBUONI,    abbuoni);
 | ||
|     _tpagsca->put(PAGSCA_DIFFCAM,    diffcam);
 | ||
|     _tpagsca->put(PAGSCA_RITENUTE,   ritenute);
 | ||
|     _tpagsca->put(PAGSCA_RITSOC,     ritsoc);
 | ||
|     
 | ||
|     _tpagsca->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _tpagsca->zero();
 | ||
|     _tpagsca->curr() = *_deppagsca;     
 | ||
|     _tpagsca->write();    
 | ||
|   }  
 | ||
| }
 | ||
| 
 | ||
| long TTransfer_file::determina_dimensione(FILE* f) 
 | ||
| {     
 | ||
|   CHECK(f, "Can't measure NULL file");
 | ||
|   fseek(f, 0, SEEK_END);
 | ||
|   const long s = ftell(f);
 | ||
|   fseek(f, 0, SEEK_SET);
 | ||
|   return s;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::new_key(TString& key, int tipo, TString& buffer)
 | ||
| {
 | ||
|   TString n_key = ""; 
 | ||
|   
 | ||
|   n_key << key.mid(0,2);
 | ||
|   if (tipo == 1)
 | ||
|     n_key << "1";
 | ||
|   else
 | ||
|     if (tipo == 2)
 | ||
|       n_key << "2";
 | ||
|     else
 | ||
|       if (tipo == 3 || tipo == 4 || tipo == 5 || tipo == 6)
 | ||
|         n_key << "3";
 | ||
|   n_key << key.mid(2,6);
 | ||
|   n_key << key.mid(8,2);
 | ||
|   n_key << buffer.mid(26,2); 
 | ||
|   n_key << buffer.mid(28,7); 
 | ||
|   n_key << buffer.mid(35,2);
 | ||
|   n_key << key.mid(10,3);
 | ||
|   
 | ||
|   key = n_key;      
 | ||
| }
 | ||
| 
 | ||
| //Trasforma un eventuale TRASFER composto da record con odinamento casuale
 | ||
| //in un file con record odinati in modo sequenziale
 | ||
| bool TTransfer_file::ordina_trasfer(const char* orig)
 | ||
| { 
 | ||
|   open(orig);
 | ||
|   
 | ||
|   FILE* i = fopen(orig, "rb");
 | ||
|   if (i == NULL) 
 | ||
|     return error_box(FR("Impossibile leggere il file %s"), orig);
 | ||
|  
 | ||
|   const long dim_t = determina_dimensione(i);  //Determina la dimensione del trasfer
 | ||
|   
 | ||
|   TString buffer(sizeT);
 | ||
|   
 | ||
|   int pos = 0;
 | ||
|   
 | ||
|   TFilename tmptab = "%";
 | ||
|   const long ditta = prefix().get_codditta();
 | ||
|   tmptab << firm2dir(ditta);
 | ||
|   tmptab.add(TEMP_TAB);
 | ||
|   _ttab = new TIsamtempfile(LF_TAB, tmptab, true);
 | ||
|   
 | ||
|   long cicli = dim_t / sizeT;  
 | ||
|   TProgind prog (cicli,TR("Ordinamento file TRASFER in corso\nPrego attendere"),false, true);    
 | ||
|   
 | ||
|   bool ok = true;          
 | ||
|     
 | ||
|   TRic_recfield recf (_ttab->curr(), "S0", 0, sizeT);
 | ||
|   
 | ||
|                                             
 | ||
|   TString80 key, app;
 | ||
|     
 | ||
|   while (ok)
 | ||
|   {
 | ||
|     const word letti = fread(buffer.get_buffer(), 1, sizeT, i);
 | ||
|     buffer.cut(sizeT);
 | ||
|     
 | ||
|     // A causa di errori di invio da parte del sistema
 | ||
|     // a volte si possono riscontrare GPF.
 | ||
|     // La righe commentate sottostanti vengono lasciate come
 | ||
|     // possibile correzione (che alla PRASSI ovviamente non vogliono)
 | ||
|     // 
 | ||
|     // if (buffer[0] == ' ' && buffer[1] == ' ')
 | ||
|     //   buffer.ltrim();
 | ||
|     
 | ||
|     ok = (letti == sizeT);
 | ||
|     if (!ok) break;
 | ||
|     
 | ||
|     prog.addstatus(1);
 | ||
|     
 | ||
|     key = buffer.left(15);
 | ||
|     
 | ||
|     if (buffer.starts_with("B1"))
 | ||
|     {               
 | ||
|       app = buffer.mid(28,7);                 // Modifica del 06-09-96 relativa all'allineamento
 | ||
|       app.trim();                             // del numero di riferimento partita che per i file
 | ||
|       app.format("%-7s", (const char*)app);   // temporanei deve essere sempre a sinistra 
 | ||
|       buffer.overwrite(app,28);               // indipendentemente da quello che c'e' sul trasfer
 | ||
|     
 | ||
|       int tipomov = atoi(buffer.mid(37,1));
 | ||
|       new_key(key,tipomov,buffer);
 | ||
|     }  
 | ||
| 
 | ||
|     _ttab->put("CODTAB", key);
 | ||
|     recf = buffer;  
 | ||
|     
 | ||
|     int rc = _ttab->write();
 | ||
|   }    
 | ||
|   
 | ||
|   fclose(i);       
 | ||
| 
 | ||
|   return ok;
 | ||
| }
 | ||
| 
 | ||
| //Scarica su file temp il contenuto del trasfer da SISTEMA
 | ||
| bool TTransfer_file::fcopytemp(const char* orig, const char* dest)
 | ||
| { 
 | ||
|   // conto i dischetti per l'apertura
 | ||
|   
 | ||
|   long          nrec_cau,nrec_clifo,nrec_pcon,nrec_mov,nrec_moviva,nrec_salda;
 | ||
|   bool          is_delete = false, tpcon_valid = false;
 | ||
| 
 | ||
|   const char* const rflag = "rb";
 | ||
|   const char* const wflag = "ab";
 | ||
| 
 | ||
|   TLocalisamfile tabella(LF_TAB);
 | ||
|   
 | ||
|   ordina_trasfer(orig);
 | ||
|   
 | ||
|   // Legge numero di rec. del transfer (per la progind)                  
 | ||
|   _ttab->first();
 | ||
|   TRic_recfield recf (_ttab->curr(), "S0", 0, 256);
 | ||
|   const TFixed_string rec((const char*)recf);
 | ||
|   
 | ||
|   const TString16 sigle = rec.sub(38,47); 
 | ||
|   const TString80 nrec = rec.sub(47,101);
 | ||
|   
 | ||
|   int pos = 0;
 | ||
|   
 | ||
|   if ( (pos = sigle.find('W')) >= 0)
 | ||
|   {
 | ||
|     _tmpcaus = "%";
 | ||
|     _tmpcaus << path();
 | ||
|     _tmpcaus.add(TEMP_CAUS);
 | ||
|     _tmprcaus = "%";
 | ||
|     _tmprcaus << path();
 | ||
|     _tmprcaus.add(TEMP_RCAUS);
 | ||
|     nrec_cau = atol(nrec.mid(pos*6,6));
 | ||
|   } 
 | ||
|   if ( (pos = sigle.find('A')) >= 0)
 | ||
|   {
 | ||
|     _tmpclifo = "%";
 | ||
|     _tmpclifo << path();
 | ||
|     _tmpclifo.add(TEMP_CLIFO);
 | ||
|     nrec_clifo = atol(nrec.mid(pos*6,6));
 | ||
|   }
 | ||
|   if ( (pos = sigle.find('P')) >= 0)
 | ||
|   {
 | ||
|     tpcon_valid = true;
 | ||
|     
 | ||
|     _tmppcon = "%";
 | ||
|     _tmppcon << path();
 | ||
|     _tmppcon.add(TEMP_PCON);
 | ||
|     nrec_pcon = atol(nrec.mid(pos*6,6));
 | ||
|   }
 | ||
|   if ( (pos = sigle.find('Z')) >= 0)
 | ||
|   {
 | ||
|     _tmpmov = "%";
 | ||
|     _tmpmov << path();
 | ||
|     _tmpmov.add(TEMP_MOV);
 | ||
|     _tmprmov = "%";
 | ||
|     _tmprmov << path();         
 | ||
|     _tmprmov.add(TEMP_RMOV);  
 | ||
|     nrec_mov = atol(nrec.mid(pos*6,6));
 | ||
|   }
 | ||
|   if ( (pos = sigle.find('U')) >= 0)
 | ||
|   { 
 | ||
|     is_delete = true;
 | ||
|     
 | ||
|     _tmpmov = "%";
 | ||
|     _tmpmov << path();
 | ||
|     _tmpmov.add(TEMP_MOV); 
 | ||
|     _tmprmoviva = "%";
 | ||
|     _tmprmoviva <<  path();     
 | ||
|     _tmprmoviva.add(TEMP_RMOVIVA);  
 | ||
|     nrec_moviva = atol(nrec.mid(pos*6,6));
 | ||
| 
 | ||
|     TFilename tmpocc = "%";
 | ||
|     tmpocc << path();
 | ||
|     tmpocc.add(TEMP_OCC);
 | ||
|     _toccas = new TIsamtempfile(LF_OCCAS, tmpocc, true);
 | ||
|   }
 | ||
|   if ( (pos = sigle.find('B')) >= 0)
 | ||
|   {
 | ||
|     TTrec trec;
 | ||
|     
 | ||
|     _tmppart = "%";
 | ||
|     _tmppart  << path();
 | ||
|     _tmppart.add(TEMP_PART);
 | ||
|     _tpart   = new TIsamtempfile(LF_PARTITE, _tmppart, true);
 | ||
|     //_deppart = new TRectype(LF_PARTITE);
 | ||
|     trec.get(LF_PARTITE);
 | ||
|     _deppart   = new TExtrectype (trec);
 | ||
|     _tmpscad  = "%";
 | ||
|     _tmpscad << path();         
 | ||
|     _tmpscad.add(TEMP_SCAD);   
 | ||
|     _tscad   = new TIsamtempfile(LF_SCADENZE, _tmpscad, true);
 | ||
|     //_depscad = new TRectype (LF_SCADENZE);
 | ||
|     trec.get(LF_SCADENZE);
 | ||
|     _depscad   = new TExtrectype (trec);    
 | ||
|     _tmppagsca = "%";
 | ||
|     _tmppagsca  << path();
 | ||
|     _tmppagsca << "\\" << TEMP_PAGSCA;          
 | ||
|     _tpagsca   = new TIsamtempfile(LF_PAGSCA, _tmppagsca, true);
 | ||
|     //_deppagsca = new TRectype (LF_PAGSCA);
 | ||
|     trec.get(LF_PAGSCA);
 | ||
|     _deppagsca = new TExtrectype (trec);    
 | ||
|     nrec_salda = atol(nrec.mid(pos*6,6));
 | ||
|   }
 | ||
|    
 | ||
|   close();
 | ||
|   
 | ||
|   bool ok = true;
 | ||
|    
 | ||
|   scrivi_header(dest,wflag);
 | ||
|   if (sigle.find('P') >= 0)  
 | ||
|     scrivi_pcon(nrec_pcon);  
 | ||
|   if (sigle.find('A') >= 0)    
 | ||
|     scrivi_clifo(nrec_clifo);
 | ||
| 
 | ||
|   _tpcon =  tpcon_valid ? new TIsamtempfile(LF_PCON, _tmppcon, false, false) : NULL; // Non crearlo, non cancellarlo
 | ||
|   
 | ||
|   if (sigle.find('W') >= 0)
 | ||
|     scrivi_causali(nrec_cau);
 | ||
|   if (sigle.find('Z') >= 0)  
 | ||
|     scrivi_PN(nrec_mov);     
 | ||
|   if (sigle.find('U') >= 0)  
 | ||
|     scrivi_IVA(nrec_moviva);
 | ||
|   if (sigle.find('B') >= 0)
 | ||
|     scrivi_SC(nrec_salda);
 | ||
|     
 | ||
|   if (is_delete) 
 | ||
|   {
 | ||
|     delete _toccas;
 | ||
|     _toccas = NULL;
 | ||
|   }
 | ||
|   
 | ||
|   if (tpcon_valid)
 | ||
|   {
 | ||
|     delete _tpcon;
 | ||
|     _tpcon = NULL;
 | ||
|   }
 | ||
|   
 | ||
|   delete _ttab;
 | ||
|   _ttab = NULL;
 | ||
|   
 | ||
|   return ok;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::ordina_file_da_elaborare(TString& buffer)
 | ||
| {
 | ||
|   TString16 sigle_app;
 | ||
|   TString80 numrec_app;
 | ||
|   int p;
 | ||
|   
 | ||
|   TString16 sigle  = buffer.sub(86,95);
 | ||
|   sigle.trim();
 | ||
|   TString80 numrec = buffer.sub(95,149);
 | ||
|   
 | ||
|   if ( (p = sigle.find('W')) >= 0)
 | ||
|   { 
 | ||
|     TString sigla = sigle.mid(p,1);
 | ||
|     TString num   = numrec.mid(p*6,6);
 | ||
|     sigle_app  << sigla;
 | ||
|     numrec_app << num;
 | ||
|   }
 | ||
|   if ( (p = sigle.find('A')) >= 0)
 | ||
|   {                  
 | ||
|     TString sigla = sigle.mid(p,1);
 | ||
|     TString num   = numrec.mid(p*6,6);
 | ||
|     sigle_app  << sigla;
 | ||
|     numrec_app << num;  
 | ||
|   }
 | ||
|   if ( (p = sigle.find('P')) >= 0)
 | ||
|   {   
 | ||
|     TString sigla = sigle.mid(p,1);
 | ||
|     TString num   = numrec.mid(p*6,6);
 | ||
|     sigle_app  << sigla;
 | ||
|     numrec_app << num;  
 | ||
|   }
 | ||
|   if ( (p = sigle.find('Z')) >= 0)
 | ||
|   {   
 | ||
|     TString sigla = sigle.mid(p,1);
 | ||
|     TString num   = numrec.mid(p*6,6);
 | ||
|     sigle_app  << sigla;
 | ||
|     numrec_app << num;  
 | ||
|   }
 | ||
|   if ( (p = sigle.find('U')) >= 0)
 | ||
|   {   
 | ||
|     TString sigla = sigle.mid(p,1);
 | ||
|     TString num   = numrec.mid(p*6,6);
 | ||
|     sigle_app  << sigla;
 | ||
|     numrec_app << num;  
 | ||
|   }
 | ||
|   if ( (p = sigle.find('B')) >= 0)
 | ||
|   {   
 | ||
|     TString sigla = sigle.mid(p,1);
 | ||
|     TString num   = numrec.mid(p*6,6);
 | ||
|     sigle_app  << sigla;
 | ||
|     numrec_app << num;  
 | ||
|   }                   
 | ||
|   buffer.overwrite(sigle_app,86);
 | ||
|   buffer.overwrite(numrec_app,95);
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::scrivi_header(const char* dest, const char* wflag)
 | ||
| {
 | ||
|   const word size  = 256;
 | ||
|   const int  sizeH = 1024;
 | ||
|   TString buffer(sizeH);
 | ||
|    
 | ||
|   FILE* o = fopen(dest, wflag);
 | ||
|   CHECKS(o, "Impossibile scrivere il file ", dest);
 | ||
| 
 | ||
|   TRic_recfield recf (_ttab->curr(), "S0", 0, 256);
 | ||
|   
 | ||
|   _ttab->zero();
 | ||
|   _ttab->put("CODTAB", " 1");
 | ||
|   _ttab->read();
 | ||
|   
 | ||
|   const TString& trec = _ttab->get("CODTAB").left(2);
 | ||
|   if (trec == " 1")  // Copio il record di controllo nel file di appoggio
 | ||
|   {                  // header. 
 | ||
|     TString rec = recf;
 | ||
|     buffer.spaces();
 | ||
|     buffer.overwrite(rec,0);
 | ||
|     
 | ||
|     TString app;
 | ||
|     app.spaces(234); 
 | ||
|     TString app1;
 | ||
|     app1 = buffer.mid(0,101);
 | ||
|     TString str(45);
 | ||
|     str.spaces(45);
 | ||
|     app1.insert(str,15);
 | ||
|     app1.insert("0",70); 
 | ||
|     int pre = atoi(app1.sub(78,80));
 | ||
|     if (pre < 80)
 | ||
|       app1.insert("20",78);
 | ||
|     else
 | ||
|       app1.insert("19",78);
 | ||
|     str = "";
 | ||
| //    str.format(85);
 | ||
| //    app.overwrite(str,149);
 | ||
|     ordina_file_da_elaborare(app1);
 | ||
|     app.overwrite(app1,0);
 | ||
|     buffer.overwrite(app,0);  
 | ||
|     buffer.cut(sizeH);
 | ||
|     fwrite((const char*)buffer, 1, sizeH, o);
 | ||
|     fclose(o);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::scrivi_causali(long nrec)
 | ||
| {   
 | ||
|   TString buffer(sizeT);
 | ||
|   bool    create = true;
 | ||
| 
 | ||
|   _prog = new TProgind (nrec,TR("Trasferimento Tabella Causali in corso\nPrego attendere"),false, true, 1); 
 | ||
|     
 | ||
|   TRic_recfield recf (_ttab->curr(), "S0", 0, sizeT);
 | ||
|     
 | ||
|   _ttab->zero();
 | ||
|   _ttab->put("CODTAB", "W1");
 | ||
|   for (_ttab->read(); !_ttab->eof(); _ttab->next())
 | ||
|   {
 | ||
|     const TString& trec = _ttab->get("CODTAB").left(2);
 | ||
|     if (trec != "W1") break;
 | ||
| 
 | ||
|     buffer = (const char*) recf;
 | ||
| 
 | ||
|     write_tmp_tabelle(buffer,create);
 | ||
|     create = false;
 | ||
|   }                         
 | ||
|   delete _prog;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::scrivi_clifo(long nrec)
 | ||
| {            
 | ||
|   TString    buffer(sizeT);
 | ||
|   bool       create = true;
 | ||
| 
 | ||
|   _prog = new TProgind (nrec,TR("Trasferimento Anagrafica Clienti/Fornitori in corso\nPrego attendere"),false, true, 1); 
 | ||
|     
 | ||
|   TRic_recfield recf (_ttab->curr(), "S0", 0, sizeT);
 | ||
|     
 | ||
|   _ttab->zero();
 | ||
|   _ttab->put("CODTAB", "A1");
 | ||
|   for (_ttab->read(); !_ttab->eof(); _ttab->next())
 | ||
|   {
 | ||
|     const TString& trec = _ttab->get("CODTAB").left(2);
 | ||
|     if (trec != "A1") break;
 | ||
|     
 | ||
|     buffer = (const char*) recf;
 | ||
|         
 | ||
|     write_tmp_tabelle(buffer,create);
 | ||
|     create = false;
 | ||
|   }                         
 | ||
|   delete _prog;
 | ||
| }
 | ||
| 
 | ||
| // Scrive piano dei conti da SISTEMA
 | ||
| void TTransfer_file::scrivi_pcon(long nrec)
 | ||
| {            
 | ||
|   TString    buffer(sizeT);
 | ||
|   bool       create = true;
 | ||
| 
 | ||
|   _prog = new TProgind (nrec,TR("Trasferimento Anagrafica Piano dei Conti in corso\nPrego attendere"),false, true, 1);  
 | ||
|   
 | ||
|   TRic_recfield recf (_ttab->curr(), "S0", 0, sizeT);
 | ||
|     
 | ||
|   _ttab->zero();
 | ||
|   _ttab->put("CODTAB", "P1");
 | ||
|   for (_ttab->read(); !_ttab->eof(); _ttab->next())
 | ||
|   {
 | ||
|     const TString& trec = (_ttab->get("CODTAB")).left(2);
 | ||
|     if (trec[0] != 'P') break;
 | ||
|     
 | ||
|     buffer = (const char*) recf;
 | ||
|         
 | ||
|     write_tmp_tabelle(buffer,create);
 | ||
|     create = false;
 | ||
|   }                         
 | ||
|   delete _prog;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::scrivi_PN(long nrec)
 | ||
| {            
 | ||
|   TString    buffer(sizeT);
 | ||
| 
 | ||
|   _prog = new TProgind (nrec,TR("Trasferimento Movimenti di Prima nota in corso\nPrego attendere"),false, true, 1); 
 | ||
|       
 | ||
|   TRic_recfield recf (_ttab->curr(), "S0", 0, sizeT);
 | ||
|     
 | ||
|   _ttab->zero();
 | ||
|   _ttab->put("CODTAB", "Z1");
 | ||
|   for (_ttab->read(); !_ttab->eof(); _ttab->next())
 | ||
|   {
 | ||
|     const TString& trec = (_ttab->get("CODTAB")).left(2);
 | ||
|     
 | ||
|     if (trec != "Z1") break;
 | ||
|     
 | ||
|     buffer = (const char*) recf;
 | ||
|         
 | ||
|     write_tmp_movPN(buffer);
 | ||
|   }                         
 | ||
|   delete _prog;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::scrivi_IVA(long nrec)
 | ||
| {            
 | ||
|   TString buffer(sizeT);
 | ||
| 
 | ||
|   _prog = new TProgind (nrec,TR("Trasferimento Movimenti Iva in corso\nPrego attendere"),false, true, 1); 
 | ||
|       
 | ||
|   const TRic_recfield recf(_ttab->curr(), "S0", 0, sizeT);
 | ||
|     
 | ||
|   _ttab->zero();
 | ||
|   _ttab->put("CODTAB", "U1");
 | ||
|   
 | ||
|   for (int err = _ttab->read(_isgteq); err == NOERR; err = _ttab->next())
 | ||
|   {
 | ||
|     const TString& trec = _ttab->get("CODTAB").left(2);
 | ||
|     if (trec != "U1") break;
 | ||
|     
 | ||
|     buffer = (const char*)recf;  
 | ||
|     write_tmp_movIVA(buffer);
 | ||
|   }                         
 | ||
|   delete _prog;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::scrivi_SC(long nrec)
 | ||
| {            
 | ||
|   TString    buffer(sizeT);
 | ||
|   
 | ||
|   _nregSC_p    = -1;
 | ||
|   _numrigSC_p  = -1;
 | ||
|   _annoSC_p    = -1;
 | ||
|   _numpartSC_p = "-1";
 | ||
|   
 | ||
|   _prog = new TProgind (nrec,TR("Trasferimento Movimenti saldaconto in corso\nPrego attendere"),false, true, 1); 
 | ||
|       
 | ||
|   TRic_recfield recf (_ttab->curr(), "S0", 0, sizeT);
 | ||
|     
 | ||
|   _ttab->zero();
 | ||
|   _ttab->put("CODTAB", "B1");
 | ||
|   for (_ttab->read(); !_ttab->eof(); _ttab->next())
 | ||
|   {
 | ||
|     const TString& trec = _ttab->get("CODTAB").left(2);
 | ||
|     if (trec != "B1") break;
 | ||
|     
 | ||
|     buffer = (const char*) recf;
 | ||
|     write_tmp_movSC(buffer);
 | ||
|   }                         
 | ||
|   delete _prog;
 | ||
|   delete _tpart;
 | ||
|   delete _deppart;
 | ||
|   delete _tscad;   
 | ||
|   delete _depscad;
 | ||
|   delete _tpagsca; 
 | ||
|   delete _deppagsca;
 | ||
| }
 | ||
|                     
 | ||
| //Scarica su file temp il contenuto del trasfer da PC
 | ||
| bool TTransfer_file::fcopytemp_PC(const char* orig, const char* dest)
 | ||
| { 
 | ||
|   // conto i dischetti per l'apertura
 | ||
|   TString       sigle;
 | ||
|   bool          is_delete = false;
 | ||
| 
 | ||
|   const char* const rflag = "rb";
 | ||
|   const char* const wflag = "ab";
 | ||
| 
 | ||
|   // Legge numero di rec. del trasfer (per la progind)                  
 | ||
|   open(orig);
 | ||
|   if (read_control_rec())
 | ||
|     sigle = sigle_file(); 
 | ||
|   
 | ||
|   FILE* i = fopen(orig, rflag);
 | ||
|   if (!i) return error_box(FR("Impossibile leggere il file %s"), orig);
 | ||
| 
 | ||
|   FILE* o = fopen(dest, wflag);
 | ||
|   CHECKS(o, FR("Impossibile scrivere il file "), dest);
 | ||
|   
 | ||
|   const word size = 1024;
 | ||
|   TString buffer(size);
 | ||
|   
 | ||
|   if (sigle.find('W') >= 0)
 | ||
|   {
 | ||
|     _tmpcaus = "%";
 | ||
|     _tmpcaus << path();
 | ||
|     _tmpcaus << "\\" << TEMP_CAUS;
 | ||
|     _tmprcaus = "%";
 | ||
|     _tmprcaus << path();
 | ||
|     _tmprcaus << "\\" << TEMP_RCAUS;
 | ||
|     _tcaus    = new TIsamtempfile(LF_CAUSALI, _tmpcaus, true);
 | ||
|     _depcaus  = new TRectype (LF_CAUSALI);    
 | ||
|     _trcaus   = new TIsamtempfile(LF_RCAUSALI, _tmprcaus, true);
 | ||
|     _deprcaus = new TRectype (LF_RCAUSALI);    
 | ||
|   } 
 | ||
|   if (sigle.find('A') >= 0)
 | ||
|   {
 | ||
|     _tmpclifo = "%";
 | ||
|     _tmpclifo << path();
 | ||
|     _tmpclifo << "\\" << TEMP_CLIFO;      
 | ||
|     _tclifo   = new TIsamtempfile(LF_CLIFO, _tmpclifo, true);
 | ||
|     _depclifo = new TRectype (LF_CLIFO);    
 | ||
|   }
 | ||
|   if (sigle.find('P') >= 0)
 | ||
|   {
 | ||
|     _tmppcon = "%";
 | ||
|     _tmppcon << path();
 | ||
|     _tmppcon << "\\" << TEMP_PCON;      
 | ||
|     _tpcon   = new TIsamtempfile(LF_PCON, _tmppcon, true);
 | ||
|     _deppcon = new TRectype (LF_PCON);        
 | ||
|   }
 | ||
|   if (sigle.find('Z') >= 0)
 | ||
|   {
 | ||
|     _tmpmov = "%";
 | ||
|     _tmpmov  << path();
 | ||
|     _tmpmov.add(TEMP_MOV);
 | ||
|     _tmprmov = "%";
 | ||
|     _tmprmov << path();         
 | ||
|     _tmprmov.add(TEMP_RMOV);  
 | ||
|     _tmov    = new TIsamtempfile(LF_MOV, _tmpmov, true);
 | ||
|     _depmov  = new TRectype (LF_MOV);        
 | ||
|     _trmov   = new TIsamtempfile(LF_RMOV, _tmprmov, true);
 | ||
|     _deprmov = new TRectype (LF_RMOV);    
 | ||
| 
 | ||
|     TFilename tmpocc = "%";
 | ||
|     const long ditta = prefix().get_codditta();
 | ||
|     tmpocc  << firm2dir(ditta);
 | ||
|     tmpocc.add(TEMP_OCC);
 | ||
|     _toccas   = new TIsamtempfile(LF_OCCAS, tmpocc, true);
 | ||
|     _depoccas = new TRectype (LF_OCCAS);    
 | ||
|   }
 | ||
|   if (sigle.find('U') >= 0)
 | ||
|   { 
 | ||
|     is_delete = true;
 | ||
|     
 | ||
|     _tmpmov = "%";
 | ||
|     _tmpmov  << path();
 | ||
|     _tmpmov.add(TEMP_MOV); 
 | ||
|     _tmprmoviva = "%";
 | ||
|     _tmprmoviva << path();     
 | ||
|     _tmprmoviva.add(TEMP_RMOVIVA);  
 | ||
|     _triva   = new TIsamtempfile(LF_RMOVIVA, _tmprmoviva, true);
 | ||
|     _depriva = new TRectype (LF_RMOVIVA);    
 | ||
|   }
 | ||
|   if (sigle.find('B') >= 0)
 | ||
|   {
 | ||
|     TTrec trec;
 | ||
|  
 | ||
|     _tmppart = "%";
 | ||
|     _tmppart << path();
 | ||
|     _tmppart.add(TEMP_PART);
 | ||
|     _tmpscad = "%";
 | ||
|     _tmpscad << path();         
 | ||
|     _tmpscad.add(TEMP_SCAD);  
 | ||
|     _tmppagsca = "%";
 | ||
|     _tmppagsca << path();
 | ||
|     _tmppagsca.add(TEMP_PAGSCA); 
 | ||
| 
 | ||
|     _tpart     = new TIsamtempfile(LF_PARTITE, _tmppart, true);
 | ||
|     //_deppart   = new TRectype (LF_PARTITE);        
 | ||
|     trec.get(LF_PARTITE);
 | ||
|     _deppart   = new TExtrectype (trec);        
 | ||
|     _tscad     = new TIsamtempfile(LF_SCADENZE, _tmpscad, true);
 | ||
|     //_depscad   = new TRectype (LF_SCADENZE);    
 | ||
|     trec.get(LF_SCADENZE);
 | ||
|     _depscad   = new TExtrectype (trec);    
 | ||
|     _tpagsca   = new TIsamtempfile(LF_PAGSCA, _tmppagsca, true);
 | ||
|     //_deppagsca = new TRectype (LF_PAGSCA);    
 | ||
|     trec.get(LF_PAGSCA);
 | ||
|     _deppagsca = new TExtrectype (trec);    
 | ||
|   }
 | ||
|    
 | ||
|   close();
 | ||
|    
 | ||
|   bool  ok          = true;          
 | ||
|   bool  prima_volta = true;
 | ||
|   
 | ||
|   long dim_t = determina_dimensione(i);  //Determina la dimensione del trasfer
 | ||
|   long cicli = dim_t / size;
 | ||
|   _prog = new TProgind (cicli,"Elaborazione file TRASFER in corso\nPrego attendere",false, true);   
 | ||
|   
 | ||
|   while (ok)
 | ||
|   {
 | ||
|     const word letti = fread(buffer.get_buffer(size), 1, size, i);
 | ||
| 
 | ||
|     const TString4 trec = buffer.left(2);
 | ||
|     
 | ||
|     if (trec == " 1")  // Copio il record di controllo nel file di appoggio
 | ||
|     {                  // header.
 | ||
|       ordina_file_da_elaborare(buffer);    
 | ||
|       ok = fwrite((char*)(const char*)buffer, 1, letti, o) == letti;
 | ||
|       fclose(o);
 | ||
|     }
 | ||
|     
 | ||
|     if (trec == "B1" || trec == "B2" || trec == "B3")
 | ||
|     {
 | ||
|       TString8 app = buffer.mid(19,7);   
 | ||
|       app.trim();                            // Modifica del 06-09-96 relativa all'allineamento
 | ||
|       app.format("%-7s", (const char*) app); // del numero di riferimento partita che per i file
 | ||
|       buffer.overwrite(app,19);              // temporanei deve essere sempre a sinistra
 | ||
|     }                                        // indipendentemente da quello che c'e' sul trasfer
 | ||
|       
 | ||
|     if (trec == "W1")
 | ||
|       write_testata_causali(buffer);
 | ||
|     
 | ||
|     if (trec == "W2")
 | ||
|       write_righe_causali(buffer);
 | ||
|       
 | ||
|     if (trec == "A1")                              // Clienti e Fornitori
 | ||
|       write_clienti_fornitori(buffer);
 | ||
| 
 | ||
|     if (trec == "P1" || trec == "P2" || trec == "P3")  // Piano dei conti
 | ||
|       write_piano_conti(buffer);
 | ||
| 
 | ||
|     if (trec == "Z1")                  
 | ||
|       write_testata_movimenti(buffer);
 | ||
|     
 | ||
|     if (trec == "Z2")
 | ||
|       write_righe_contabili(buffer);
 | ||
|       
 | ||
|     if (trec == "U1")    
 | ||
|       write_righe_IVA(buffer);
 | ||
|     
 | ||
|     if (trec == "B1")
 | ||
|       write_partite(buffer);
 | ||
|       
 | ||
|     if (trec == "B2")
 | ||
|       write_scadenze(buffer);
 | ||
|       
 | ||
|     if (trec == "B3")
 | ||
|       write_pagsca(buffer);
 | ||
|           
 | ||
|     ok = (letti == size);
 | ||
|   }    
 | ||
|   
 | ||
|   fclose(i);
 | ||
|   
 | ||
|   delete _prog;
 | ||
| 
 | ||
|   if (sigle.find('W') >= 0)
 | ||
|   {
 | ||
|     delete _tcaus;
 | ||
|     delete _depcaus;
 | ||
|     delete _trcaus;
 | ||
|     delete _deprcaus;
 | ||
|   } 
 | ||
|   if (sigle.find('A') >= 0)
 | ||
|   {
 | ||
|     delete _tclifo;
 | ||
|     delete _depclifo;
 | ||
|   }
 | ||
|   if (sigle.find('P') >= 0)
 | ||
|   {
 | ||
|     delete _tpcon; _tpcon = NULL;
 | ||
|     delete _deppcon; _deppcon = NULL;
 | ||
|   }
 | ||
|   if (sigle.find('Z') >= 0)
 | ||
|   {
 | ||
|     delete _tmov;
 | ||
|     delete _depmov;
 | ||
|     delete _trmov;
 | ||
|     delete _deprmov;
 | ||
|   }
 | ||
|   if (sigle.find('U') >= 0)
 | ||
|   { 
 | ||
|     delete _triva;
 | ||
|     delete _depriva;
 | ||
|   }
 | ||
|   if (sigle.find('B') >= 0)
 | ||
|   {
 | ||
|     delete _tpart;
 | ||
|     delete _deppart;
 | ||
|     delete _tscad;
 | ||
|     delete _depscad;
 | ||
|     delete _tpagsca;
 | ||
|     delete _deppagsca;
 | ||
|   }
 | ||
|   if (is_delete)
 | ||
|   {
 | ||
|     delete _toccas;
 | ||
|     delete _depoccas;
 | ||
|   }
 | ||
|   
 | ||
|   return ok;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_testata_causali(TString& record)
 | ||
| { 
 | ||
|   TString       key,str;
 | ||
|   int           numfield = 1;  
 | ||
|   const TMappa_trc&   trc  = mappa();
 | ||
|   
 | ||
|   const TString4 sigla = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
|            
 | ||
|   _depcaus->zero();  
 | ||
|              
 | ||
|   if (trc.is_key((const char*)key)) 
 | ||
|   {    
 | ||
|     do
 | ||
|     {  
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString fname = trc.field_name(key); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|       
 | ||
|       if (fname == CAU_TIPOMOV)
 | ||
|         if (field == "0")
 | ||
|           field = "";
 | ||
|             
 | ||
|       _depcaus->put(fname, (const char*)field);                      
 | ||
| 
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));
 | ||
|   } 
 | ||
| 
 | ||
|   _tcaus->zero();
 | ||
|   _tcaus->curr() = *_depcaus;
 | ||
|       
 | ||
|   if (_tcaus->read() == NOERR)     
 | ||
|   {   
 | ||
|     _tcaus->zero();
 | ||
|     _tcaus->curr() = *_depcaus;
 | ||
|     _tcaus->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _tcaus->zero();
 | ||
|     _tcaus->curr() = *_depcaus;     
 | ||
|     _tcaus->write();    
 | ||
|   } 
 | ||
|         
 | ||
|   _prog->addstatus(1);
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_righe_causali(TString& record)
 | ||
| { 
 | ||
|   TString       sigla,key,str;
 | ||
|   int           numfield = 1;  
 | ||
|   TMappa_trc&   trc  = mappa();
 | ||
|   int  gruppo,conto;
 | ||
|           
 | ||
|   sigla     = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
| 
 | ||
|   _deprcaus->zero();  
 | ||
|     
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     do
 | ||
|     {  
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString fname = trc.field_name(key); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|       
 | ||
|       if (fname == RCA_NRIGA)
 | ||
|       {
 | ||
|         int nriga = atoi(field);  
 | ||
|         field.format("%3d", nriga);
 | ||
|       }
 | ||
|       if (fname == RCA_GRUPPO || fname == RCA_CONTO) 
 | ||
|       {
 | ||
|         if (fname == RCA_GRUPPO) 
 | ||
|         {
 | ||
|           gruppo = atoi(field);  
 | ||
|           field.format("%3d", gruppo);
 | ||
|         }
 | ||
|         if (fname == RCA_CONTO) 
 | ||
|         {
 | ||
|           conto = atoi(field);
 | ||
|           field.format("%3d", conto);
 | ||
|           char tipo = TipoConto(gruppo,conto);
 | ||
|           _deprcaus->put(RCA_TIPOCF, tipo);          
 | ||
|         }            
 | ||
|       }
 | ||
|       if (fname == RCA_SOTTOCONTO)
 | ||
|       {
 | ||
|         long sottoc = atol(field);
 | ||
|         field.format("%6ld", sottoc);
 | ||
|       }
 | ||
|         
 | ||
|       _deprcaus->put(fname, (const char*)field);                      
 | ||
| 
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));
 | ||
|   } 
 | ||
| 
 | ||
|   _trcaus->zero();
 | ||
|   _trcaus->curr() = *_deprcaus;
 | ||
|       
 | ||
|   if (_trcaus->read() == NOERR)     
 | ||
|   {   
 | ||
|     _trcaus->zero();
 | ||
|     _trcaus->curr() = *_deprcaus;
 | ||
|     _trcaus->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _trcaus->zero();
 | ||
|     _trcaus->curr() = *_deprcaus;     
 | ||
|     _trcaus->write();    
 | ||
|   }      
 | ||
|   
 | ||
|   _prog->addstatus(1);
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_clienti_fornitori(TString& record)
 | ||
| { 
 | ||
|   TString sigla,key,com,comune,cap;
 | ||
|   int     numfield = 1;  
 | ||
|   bool    is_foreign=false;
 | ||
|   TMappa_trc&       trc  = mappa();
 | ||
|   
 | ||
|   sigla     = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
| 
 | ||
|   _depclifo->zero();  
 | ||
|   
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     do
 | ||
|     {
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString fname = trc.field_name(key); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|         
 | ||
|       if (fname == CLI_CODCF)
 | ||
|       {
 | ||
|         long codcf = atol(field);
 | ||
|         field.format("%6ld", codcf);
 | ||
|       }
 | ||
|       if (fname == CLI_ALLEG)
 | ||
|         if (field == "2") 
 | ||
|           _depclifo->put(CLI_OCCAS, "X");                      
 | ||
|         else
 | ||
|           if (field == "5") is_foreign = true;
 | ||
|       
 | ||
|       if (fname == CLI_CODALLEG)
 | ||
|       {
 | ||
|         long codalleg = atol(field); 
 | ||
|         field.format("%6ld", codalleg);
 | ||
|       }                                
 | ||
|       if (fname == CLI_GRUPPO || fname == CLI_GRUPPORIC)
 | ||
|       {
 | ||
|         int gruppo = atoi(field);
 | ||
|         field.format("%3d", gruppo);
 | ||
|       }
 | ||
|       if (fname == CLI_CONTO || fname == CLI_CONTORIC)
 | ||
|       {  
 | ||
|         int conto = atoi(field);
 | ||
|         field.format("%3d", conto);
 | ||
|       }
 | ||
|       if (fname == CLI_SOTTOCRIC)
 | ||
|       {
 | ||
|         long sottoc = atol(field);
 | ||
|         field.format("%6ld", sottoc);
 | ||
|       }                           
 | ||
|       if (fname == CLI_COMCF)  
 | ||
|       {
 | ||
|         com = field;  
 | ||
|         com.trim();
 | ||
|       } 
 | ||
|       if (fname == CLI_CAPCF)  
 | ||
|       { 
 | ||
|         field.trim();
 | ||
|         if (field == "00000")
 | ||
|           cap = "";
 | ||
|         else
 | ||
|           cap = field;      
 | ||
|       }
 | ||
|       if (fname == CLI_LOCCF)
 | ||
|       {
 | ||
|         comune = "";
 | ||
|         
 | ||
|         if (cap.empty())
 | ||
|           _depclifo->put(CLI_CAPCF,cerca_cap_comune(field));
 | ||
|         
 | ||
|         if (com.empty() && !is_foreign)
 | ||
|         {    
 | ||
|           if (cap.not_empty())
 | ||
|             comune = cerca_comune_cap(cap,field);
 | ||
|           if (comune.empty())
 | ||
|             comune = cerca_comune_den(field);
 | ||
|           if (comune.not_empty())
 | ||
|             _depclifo->put(CLI_COMCF, comune);
 | ||
|         }
 | ||
|       } 
 | ||
|       
 | ||
|       if (flag == 2)
 | ||
|       {
 | ||
|         TString f = converti(field,true);
 | ||
|         _depclifo->put(fname,f);      
 | ||
|       }
 | ||
|       else  
 | ||
|         _depclifo->put(fname, (const char*)field);                      
 | ||
| 
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));
 | ||
|   } 
 | ||
| 
 | ||
|   _tclifo->zero();
 | ||
|   _tclifo->curr() = *_depclifo;
 | ||
|       
 | ||
|   if (_tclifo->read() == NOERR)     
 | ||
|   {   
 | ||
|     _tclifo->zero();
 | ||
|     _tclifo->curr() = *_depclifo;
 | ||
|     _tclifo->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _tclifo->zero();
 | ||
|     _tclifo->curr() = *_depclifo;     
 | ||
|     _tclifo->write();    
 | ||
|   }
 | ||
|   
 | ||
|   _prog->addstatus(1);
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_piano_conti(TString& record)
 | ||
| { 
 | ||
|   TString8 key;
 | ||
|   int     numfield = 1;  
 | ||
|   const TMappa_trc& trc = mappa();
 | ||
|   
 | ||
|   const TString4 sigla = record.left(2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
| 
 | ||
|   _deppcon->zero();
 | ||
|     
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     do
 | ||
|     {  
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString fname = trc.field_name(key); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|         
 | ||
|       //Quando ricevo la IV direttiva del piano dei conti per evitare che nell'archivio,
 | ||
|       //in caso di numero romano vuoto, venga memorizzato la stringa letta sul trasfer ("000"),
 | ||
|       //vuoto la stringa prima di fare la put.
 | ||
|       if (fname == PCN_GRUPPO)
 | ||
|       {
 | ||
|         int gruppo = atoi(field);
 | ||
|         field.format("%3d", gruppo);
 | ||
|       }                             
 | ||
|       if (fname == PCN_CONTO) 
 | ||
|       {
 | ||
|         int conto = atoi(field);
 | ||
|         field.format("%3d", conto);
 | ||
|       }                            
 | ||
|       if (fname == PCN_SOTTOCONTO)
 | ||
|       {
 | ||
|         long sottoc = atol(field);
 | ||
|         field.format("%6ld", sottoc);
 | ||
|       }
 | ||
|       if (fname == PCN_SEZIVD || fname == PCN_SEZIVDOPP)
 | ||
|         if (field == " ")
 | ||
|           field = "0";
 | ||
|       
 | ||
|       _deppcon->put(fname, (const char*)field);                      
 | ||
| 
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));
 | ||
|   }
 | ||
| 
 | ||
|   _tpcon->zero();
 | ||
|   _tpcon->curr() = *_deppcon;
 | ||
|       
 | ||
|   if (_tpcon->read() == NOERR)     
 | ||
|   {   
 | ||
|     _tpcon->zero();
 | ||
|     _tpcon->curr() = *_deppcon;
 | ||
|     _tpcon->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _tpcon->zero();
 | ||
|     _tpcon->curr() = *_deppcon;     
 | ||
|     _tpcon->write();    
 | ||
|   }
 | ||
|   
 | ||
|   _prog->addstatus(1);  
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::annoes_PC(const TString& data) const
 | ||
| { 
 | ||
|   //TTable esc ("ESC");
 | ||
|   //int anno = 0;
 | ||
|   //int ae = datacomp.year();
 | ||
|   //TString dep = format("%04d", ae);
 | ||
|   //esc.zero();
 | ||
|   //esc.put("CODTAB", dep);
 | ||
|   //if (esc.read() == NOERR)
 | ||
|   //  anno = ae;
 | ||
|     
 | ||
|   const TDate datacomp (data);
 | ||
|   TEsercizi_contabili esc;
 | ||
|   const int anno = esc.date2esc(datacomp);
 | ||
|   
 | ||
|   return anno;
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::causale(TString& cau,TString& tipo,TString& descr)
 | ||
| {
 | ||
|   TLocalisamfile caus (LF_CAUSALI);
 | ||
|   
 | ||
|   caus.setkey(1);
 | ||
|   caus.zero();
 | ||
|   caus.put(CAU_CODCAUS, cau);
 | ||
|   if (caus.read() == NOERR)
 | ||
|   {
 | ||
|     descr = caus.get(CAU_DESCR);
 | ||
|     tipo  = caus.get(CAU_TIPODOC);
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     descr = "";
 | ||
|     tipo  = "";
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| int TTransfer_file::registro(const TString& reg, int anno) const
 | ||
| {
 | ||
| /*
 | ||
|   TTable  rg ("REG");
 | ||
|   TString dep;
 | ||
|   int     tipo = 0;
 | ||
|   
 | ||
|   dep.format("%04d%s", anno, (const char*) reg);
 | ||
|   
 | ||
|   rg.zero();  
 | ||
|   rg.put("CODTAB", dep);
 | ||
|   if (rg.read() == NOERR)
 | ||
|     tipo = rg.get_int("I0");
 | ||
| */
 | ||
|     
 | ||
|   TString8 dep; dep.format("%04d%s", anno, (const char*)reg);
 | ||
|   int tipo = atoi(cache().get("REG", dep, "I0"));
 | ||
| 
 | ||
|   return tipo;  
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_testata_movimenti(TString& record)
 | ||
| { 
 | ||
|   TString descr;
 | ||
|   int          numfield = 1;   
 | ||
|   const TMappa_trc& trc = mappa();
 | ||
|   int          annoiva;
 | ||
|   bool         registra_occas = false;
 | ||
|   bool         occas          = true;
 | ||
|   
 | ||
|   const TString4 sigla = record.mid(0,2);
 | ||
|   TString4 key; key.format("%2s%d", (const char*)sigla,numfield);
 | ||
| 
 | ||
|   _depmov->zero();    
 | ||
|       
 | ||
|   if (trc.is_key(key)) 
 | ||
|   {    
 | ||
|     _numreg = atol(record.sub(2,9));
 | ||
| 
 | ||
|     do
 | ||
|     {  
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       const TString16 fname = trc.field_name(key); 
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       int     dec   = trc.flag_bis(key);
 | ||
|       
 | ||
|       if (flag != 4)  //Xche' sono i campi degli occasionali e gli da fastidio costruire un
 | ||
|       {               //recfield con _depmov e un campo degli occasionali
 | ||
|         TRecfield campo (*_depmov,fname);
 | ||
|         if (campo.type() == _realfld)
 | ||
|         { 
 | ||
|           TString16 sign,importo;
 | ||
|                     
 | ||
|           importo = field;            
 | ||
|           strip_zero(importo);
 | ||
|           if (importo.not_empty())
 | ||
|           {
 | ||
|             if (fname == MOV_TOTDOC)
 | ||
|             {
 | ||
|               sign  = record.sub(180,181); 
 | ||
|               if (sign == "-")
 | ||
|                 field = sign << importo;
 | ||
|               else
 | ||
|                 field = importo;
 | ||
|             }                         
 | ||
|             if (fname == MOV_RITFIS)
 | ||
|             {
 | ||
|               sign  = record.sub(195,196);
 | ||
|               if (sign == "-")
 | ||
|                 field = sign << importo;        
 | ||
|               else
 | ||
|                 field = importo;
 | ||
|             }
 | ||
|             if (fname == MOV_RITSOC)
 | ||
|             {
 | ||
|               sign  = record.sub(210,211);
 | ||
|               if (sign == "-")
 | ||
|                 field = sign << importo;        
 | ||
|               else 
 | ||
|                 field = importo;
 | ||
|             }
 | ||
|             if (fname == MOV_CORRLIRE)
 | ||
|             {
 | ||
|               sign  = record.sub(242,243);
 | ||
|               if (sign == "-")
 | ||
|                 field = sign << importo;        
 | ||
|               else
 | ||
|                 field == importo;
 | ||
|             }
 | ||
|             if (fname == MOV_CORRVALUTA)
 | ||
|             {
 | ||
|               sign  = record.sub(257,258);
 | ||
|               if (sign == "-")
 | ||
|                 field = sign << importo;        
 | ||
|               else 
 | ||
|                 field = importo;
 | ||
|             }
 | ||
|           }
 | ||
|           else
 | ||
|             field = importo;  
 | ||
|         }  
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == MOV_NUMREG)
 | ||
|       {
 | ||
|         const long numreg = atol(field);
 | ||
|         field.format("%7ld", numreg);        
 | ||
|       }
 | ||
|       
 | ||
|       if (flag == 3)
 | ||
|       { 
 | ||
|         if (dec > 0)
 | ||
|           decimali(field,dec);
 | ||
|         const real appoggio = field;
 | ||
|         field = appoggio.string(0, dec);
 | ||
|       }
 | ||
| 
 | ||
|       if (fname == MOV_DESCR)
 | ||
|       {     
 | ||
|         field.trim();
 | ||
|         if (field.empty() && _scelta == 'S')
 | ||
|           field = descr;
 | ||
|       }
 | ||
| 
 | ||
|       if (fname == MOV_REG)
 | ||
|       {
 | ||
|         const int tipo = registro (field,annoiva);
 | ||
|         if (tipo == 1 || tipo == 2)
 | ||
|           _depmov->put(MOV_TIPO, tipo == 1 ? 'C' : 'F');
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == MOV_OCFPI)
 | ||
|       {
 | ||
|         field.trim();
 | ||
|         if (field.empty())  
 | ||
|         {
 | ||
|           const TString& rags = record.sub(290,340);
 | ||
|           if (rags.full())
 | ||
|           {
 | ||
|             TString16 app;
 | ||
|             field.format("RIC%13ld", ++_npoccas);  
 | ||
|           }
 | ||
|           else
 | ||
|             occas = false;
 | ||
|         }
 | ||
|       }
 | ||
|           
 | ||
|       if (flag == 2)
 | ||
|       {
 | ||
|         const TString16 f = converti(field, true);
 | ||
|         _depmov->put(fname,f);
 | ||
| 
 | ||
|         if (fname == MOV_DATACOMP)
 | ||
|         {
 | ||
|           _annoes = annoes_PC(f);
 | ||
|           _depmov->put(MOV_ANNOES, _annoes);
 | ||
|         }                                
 | ||
| 
 | ||
|         if (fname == MOV_DATAREG)
 | ||
|         {     
 | ||
|           const TDate datareg (f);
 | ||
|           annoiva = datareg.year();
 | ||
|           _depmov->put(MOV_ANNOIVA,  annoiva);
 | ||
|         }
 | ||
|       }
 | ||
|       else
 | ||
|         if (fname == MOV_CODCAUS)
 | ||
|         {
 | ||
|           TString4 tipodoc;     
 | ||
|           
 | ||
|           causale(field,tipodoc,descr);
 | ||
|           _depmov->put(MOV_CODCAUS, field);
 | ||
|           _depmov->put(MOV_TIPODOC, tipodoc);
 | ||
|         }
 | ||
|         else
 | ||
|           if (flag == 4 || fname == MOV_OCFPI)
 | ||
|           { 
 | ||
|             if (occas)
 | ||
|             {
 | ||
|               if (!registra_occas)
 | ||
|                 _depoccas->zero(); 
 | ||
|               if (fname == OCC_DNASC)
 | ||
|               {
 | ||
|                 field = converti(field,TRUE);
 | ||
|               }
 | ||
|               else
 | ||
|               if (fname == OCC_CFPI) 
 | ||
|               {
 | ||
|                 _depmov->put(fname,field);
 | ||
|                 _depoccas->put(OCC_CFPI, field);
 | ||
|               }
 | ||
|               else
 | ||
|                 if (fname == OCC_COM)
 | ||
|                 {
 | ||
|                   if (field.blank())
 | ||
|                   {
 | ||
|                     TString denominazione = record.sub(403,453);
 | ||
|                     denominazione.trim();
 | ||
|                     field = cerca_comune_den(denominazione);
 | ||
|                   }                
 | ||
|                   _depoccas->put(OCC_COM, field);
 | ||
|                 }  
 | ||
|                 else
 | ||
|                   if (fname == OCC_COMNASC)
 | ||
|                   {
 | ||
|                     if (field.blank())
 | ||
|                     {
 | ||
|                       TString denominazione = record.sub(473,523);
 | ||
|                       denominazione.trim();
 | ||
|                       field = cerca_comune_den(denominazione);
 | ||
|                     }                
 | ||
|                     _depoccas->put(OCC_COMNASC, field);
 | ||
|                   }  
 | ||
|                   else 
 | ||
|                     _depoccas->put(fname, field);
 | ||
|               registra_occas = true;
 | ||
|             }
 | ||
|           }
 | ||
|           else
 | ||
|             _depmov->put(fname, field);
 | ||
|           
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*)sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key(key));    
 | ||
|   }
 | ||
| 
 | ||
| /* // Vecchio modo cazzuto
 | ||
|   _tmov->zero();
 | ||
|   _tmov->curr() = *_depmov;
 | ||
|   if (_tmov->read() == NOERR)     
 | ||
|   {   
 | ||
|     _tmov->zero();
 | ||
|     _tmov->curr() = *_depmov;
 | ||
|     _tmov->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _tmov->zero();
 | ||
|     _tmov->curr() = *_depmov;     
 | ||
|     _tmov->write();    
 | ||
|   }
 | ||
| */
 | ||
|   _depmov->write_rewrite(*_tmov); // Nuovo modo per fare la stessa cosa
 | ||
|   
 | ||
|   if (registra_occas)
 | ||
|   {          
 | ||
| /*    
 | ||
|     _toccas->zero();
 | ||
|     _toccas->curr() = *_depoccas;
 | ||
|       
 | ||
|     if (_toccas->read() == NOERR)     
 | ||
|     {   
 | ||
|       _toccas->zero();
 | ||
|       _toccas->curr() = *_depoccas;
 | ||
|       _toccas->rewrite();
 | ||
|     }
 | ||
|     else
 | ||
|     {
 | ||
|       _toccas->zero();
 | ||
|       _toccas->curr() = *_depoccas;     
 | ||
|       _toccas->write();    
 | ||
|     }
 | ||
| */
 | ||
|     _depoccas->write_rewrite(*_toccas);
 | ||
|     
 | ||
|     registra_occas = false;
 | ||
|   }                 
 | ||
|   _prog->addstatus(1);  
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_righe_contabili(const TString& record)
 | ||
| { 
 | ||
|   const TMappa_trc& trc = mappa();
 | ||
| 
 | ||
|   int         numfield = 1;  
 | ||
|   real        importo = ZERO;
 | ||
|   int         gruppo = 0;
 | ||
|   
 | ||
|   
 | ||
|   const TString4 sigla = record.mid(0,2);
 | ||
|    TString16 key;
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
| 
 | ||
|   _deprmov->zero();
 | ||
|       
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     do
 | ||
|     {  
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       const TString16 fname = trc.field_name(key); 
 | ||
|       TString80 field = record.sub(from-1,to); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       int     dec   = trc.flag_bis(key);
 | ||
|           
 | ||
|       const TRecfield campo (*_deprmov,fname);
 | ||
|       if (campo.type() == _realfld)
 | ||
|       {                
 | ||
|         TString80 importo = field;            
 | ||
|         strip_zero(importo);
 | ||
|         if (importo.full())
 | ||
|         {
 | ||
|           if (fname == RMV_IMPORTO)
 | ||
|           {
 | ||
|             TString80 sign  = record.sub(143,144);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;
 | ||
|             else
 | ||
|               field = importo;
 | ||
|           }                         
 | ||
|         }
 | ||
|         else
 | ||
|           field = importo;
 | ||
|           
 | ||
|         // Cerco di riconoscere gli importi in euro  
 | ||
|         if (dec == 0 && (to-from) >= 8 && record.size()<1024 && ditta_in_euro())
 | ||
|         {
 | ||
|           flag = 3;
 | ||
|           dec = 2;
 | ||
|         }
 | ||
|       }  
 | ||
| 
 | ||
|       if (flag == 3)
 | ||
|       { 
 | ||
|         if (dec > 0)
 | ||
|           decimali(field,dec);
 | ||
|             
 | ||
|         const real appoggio = field;
 | ||
|         field = appoggio.string(0, dec);
 | ||
|       }
 | ||
|             
 | ||
|       if (fname == RMV_IMPORTO)
 | ||
|       {
 | ||
|         real imp = field;  
 | ||
|         importo = imp;
 | ||
|       }  
 | ||
|       
 | ||
|       if (fname == RMV_NUMRIG)
 | ||
|       {
 | ||
|         int nriga = atoi(field);
 | ||
|         field.format("%3d", nriga);
 | ||
|       }                            
 | ||
|       if (fname == RMV_GRUPPO || fname == RMV_GRUPPOC)
 | ||
|       {
 | ||
|         gruppo = atoi(field);
 | ||
|         field.format("%3d", gruppo);
 | ||
|       }        
 | ||
|       if (fname == RMV_CONTO || fname == RMV_CONTOC)
 | ||
|       {
 | ||
|         const int conto = atoi(field);
 | ||
|         field.format("%3d", conto);
 | ||
|         char tipo = TipoConto(gruppo,conto);
 | ||
|         if (fname == RMV_CONTO)
 | ||
|           _deprmov->put(RMV_TIPOC, tipo);
 | ||
|         if (fname == RMV_CONTOC)
 | ||
|           _deprmov->put(RMV_TIPOCC, tipo);
 | ||
|       }                            
 | ||
|       if (fname == RMV_SOTTOCONTO || fname == RMV_SOTTOCONTOC)
 | ||
|       {
 | ||
|         const long sottoc = atol(field);
 | ||
|         field.format("%6ld", sottoc);
 | ||
|       }
 | ||
| 
 | ||
|       if (flag == 2)
 | ||
|         _deprmov->put(fname,converti(field,true));
 | ||
|       else  
 | ||
|         if (fname == RMV_NUMREG)
 | ||
|         {                                 
 | ||
|           const long nreg = atol(field);
 | ||
|           field.format("%7ld", nreg);
 | ||
|           _deprmov->put(RMV_ANNOES, _annoes);                                     
 | ||
|           _deprmov->put(RMV_NUMREG, field);
 | ||
|         }
 | ||
|         else
 | ||
|           _deprmov->put(fname, field);
 | ||
|           
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));
 | ||
|   }     
 | ||
| 
 | ||
|   _trmov->curr() = *_deprmov;
 | ||
|   if (_trmov->read() == NOERR)     
 | ||
|   {   
 | ||
|     _trmov->curr() = *_deprmov;
 | ||
|     _trmov->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _trmov->curr() = *_deprmov;     
 | ||
|     _trmov->write();    
 | ||
|   }                 
 | ||
|   
 | ||
|   _prog->addstatus(1);  
 | ||
| }
 | ||
| 
 | ||
| // Scrive righe iva per ricezione PC
 | ||
| void TTransfer_file::write_righe_IVA(TString& record)
 | ||
| { 
 | ||
|   TString8    key;
 | ||
|   int         numfield = 1;   
 | ||
|   const TMappa_trc& trc = mappa();
 | ||
|   int         gruppo;
 | ||
|   
 | ||
|   long        nreg = 0;
 | ||
|   int         nriga = 1;
 | ||
| 
 | ||
|   _depriva->zero();
 | ||
| 
 | ||
|   const TString4 sigla = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
| 
 | ||
|   while (trc.is_key(key))
 | ||
|   {  
 | ||
|     const int from  = trc.from(key);
 | ||
|     const int to    = trc.to(key);
 | ||
|     const int logic = trc.logicnum(key);
 | ||
|     const TString16 fname = trc.field_name(key); 
 | ||
|     TString field = record.sub(from-1,to); 
 | ||
|     int flag  = trc.flag(key);
 | ||
|     int dec   = trc.flag_bis(key);
 | ||
|     
 | ||
|     if (logic == LF_RMOVIVA && _depriva->type(fname) == _realfld)
 | ||
|     { 
 | ||
|       TString80 sign,importo;
 | ||
|                     
 | ||
|       importo = field;            
 | ||
|       strip_zero(importo);
 | ||
|       if (importo.not_empty())
 | ||
|       {
 | ||
|         if (fname == RMI_IMPONIBILE)
 | ||
|         {
 | ||
|           sign  = record.sub(64,65);
 | ||
|           if (sign == "-")
 | ||
|             field = sign << importo;
 | ||
|           else
 | ||
|             field = importo;
 | ||
|         }
 | ||
|         if (fname == RMI_IMPOSTA)
 | ||
|         {
 | ||
|           sign  = record.sub(79,80);
 | ||
|           if (sign == "-")
 | ||
|             field = sign << importo;
 | ||
|           else
 | ||
|             field = importo;
 | ||
|         }
 | ||
|       }
 | ||
|       else
 | ||
|         field = importo;                                 
 | ||
|         
 | ||
|       // Cerco di riconoscere gli importi in euro  
 | ||
|       if (dec == 0 && (to-from) >= 8 && record.size()<1024 && ditta_in_euro())
 | ||
|       {
 | ||
|         flag = 3;
 | ||
|         dec = 2;
 | ||
|       }
 | ||
|     }  
 | ||
|                                                      
 | ||
|     if (flag == 3)
 | ||
|     {
 | ||
|       if (dec > 0)
 | ||
|         decimali(field,dec);
 | ||
|       const real appoggio = field;
 | ||
|       field = appoggio.string(0, dec);  
 | ||
|     }                           
 | ||
|     if (fname == RMI_NUMRIG)
 | ||
|     {
 | ||
|       nriga = atoi(field);
 | ||
|       field.format("%3d", nriga);
 | ||
|     }  
 | ||
|     if (fname == RMI_GRUPPO)
 | ||
|     {
 | ||
|       gruppo = atoi(field);
 | ||
|       field.format("%3d", gruppo);
 | ||
|     }  
 | ||
|     if (fname == RMI_CONTO)
 | ||
|     {
 | ||
|       int conto = atoi(field);
 | ||
|       field.format("%3d", conto);
 | ||
|       char tipo = TipoConto(gruppo,conto);
 | ||
|       _depriva->put(RMI_TIPOC, tipo);
 | ||
|     }
 | ||
|     if (fname == RMI_SOTTOCONTO)
 | ||
|     {
 | ||
|       long sottoc = atol(field);
 | ||
|       field.format("%6ld", sottoc);
 | ||
|     }  
 | ||
|     if (fname == RMI_TIPODET || fname == RMI_TIPOCR || fname == RMI_TIPOATT)
 | ||
|       if (field == "0")
 | ||
|         field = "";
 | ||
|          
 | ||
|     if (fname == RMI_NUMREG)
 | ||
|     {                               
 | ||
|       nreg = atol(field);
 | ||
|       field.format("%7ld", nreg);
 | ||
|       _depriva->put(RMI_ANNOES,   _annoes);                                     
 | ||
|       _depriva->put(RMI_NUMREG,   field);
 | ||
|     }
 | ||
|     else
 | ||
|     {
 | ||
|       if (logic == LF_RMOVIVA)
 | ||
|         _depriva->put(fname, field);
 | ||
|       
 | ||
|       // Devo trasferire un campo che in realta' e' in testata  
 | ||
|       if (logic == LF_RMOV && nriga == 1 && field.not_empty())  
 | ||
|       {              
 | ||
|         _tmov->put(MOV_NUMREG, nreg);
 | ||
|         if (_tmov->read() == NOERR)
 | ||
|         {
 | ||
|           *_depmov = _tmov->curr(); 
 | ||
|           _depmov->put(fname, field);
 | ||
|           _depmov->rewrite(*_tmov);
 | ||
|         }
 | ||
|       }
 | ||
|     }  
 | ||
|       
 | ||
|     numfield++;
 | ||
|     key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|   }
 | ||
| 
 | ||
|   _triva->curr() = *_depriva;  
 | ||
|   if (_triva->read() == NOERR)     
 | ||
|   {   
 | ||
|     _triva->curr() = *_depriva;
 | ||
|     _triva->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _triva->curr() = *_depriva;     
 | ||
|     _triva->write();    
 | ||
|   }
 | ||
|   _prog->addstatus(1);                                    
 | ||
| }
 | ||
| 
 | ||
| static void align_numpart(char tipocf, TString& numpart)
 | ||
| {
 | ||
|   const char all = TPartita::allineamento_richiesto(tipocf);
 | ||
|   if (all == 'R')
 | ||
|     numpart.right_just(7);
 | ||
|   else
 | ||
|     numpart.trim();
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_partite(TString& record)
 | ||
| { 
 | ||
|   TString      sigla,key;
 | ||
|   int          numfield = 1;   
 | ||
|   const TMappa_trc&  trc  = mappa();
 | ||
|   
 | ||
|   sigla     = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
| 
 | ||
|   _deppart->zero();    
 | ||
|       
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     do
 | ||
|     {  
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString fname = trc.field_name(key); 
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       int     dec   = trc.flag_bis(key);
 | ||
|       
 | ||
|       TRecfield campo (*_deppart,fname);
 | ||
|       if (campo.type() == _realfld)
 | ||
|       { 
 | ||
|         TString sign,importo;
 | ||
|                     
 | ||
|         importo = field;            
 | ||
|         strip_zero(importo);
 | ||
|         if (importo.not_empty())
 | ||
|         {
 | ||
|           if (fname == PART_IMPORTO)
 | ||
|           {
 | ||
|             sign  = record.sub(166,167); 
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;
 | ||
|             else
 | ||
|               field = importo;
 | ||
|           }                         
 | ||
|           if (fname == PART_IMPOSTA)
 | ||
|           {
 | ||
|             sign  = record.sub(181,182);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else
 | ||
|               field = importo;
 | ||
|           }
 | ||
|           if (fname == PART_SPESE)
 | ||
|           {
 | ||
|             sign  = record.sub(196,197);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           }
 | ||
|           if (fname == PART_IMPORTOVAL)
 | ||
|           {
 | ||
|             sign  = record.sub(228,229);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else
 | ||
|               field == importo;
 | ||
|           }
 | ||
|           if (fname == PART_IMPTOTDOC)
 | ||
|           {
 | ||
|             sign  = record.sub(253,254);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           } 
 | ||
|           if (fname == PART_IMPTOTVAL)
 | ||
|           {
 | ||
|             sign  = record.sub(268,269);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           }
 | ||
|           if (fname == PART_RITENUTE)
 | ||
|           {
 | ||
|             sign  = record.sub(285,286);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           }
 | ||
|           if (fname == PART_RITSOC)
 | ||
|           {
 | ||
|             sign  = record.sub(341,342);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           }
 | ||
|           if (fname == PART_ABBUONI)
 | ||
|           {
 | ||
|             sign  = record.sub(301,302);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           }
 | ||
|           if (fname == PART_DIFFCAM)
 | ||
|           {
 | ||
|             sign  = record.sub(319,320);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           }
 | ||
|         }
 | ||
|         else
 | ||
|           field = importo;  
 | ||
|           
 | ||
|         // Cerco di riconoscere gli importi in euro  
 | ||
|         if (dec == 0 && (to-from) >= 8 && record.size()<1024 && ditta_in_euro())
 | ||
|         {
 | ||
|           flag = 3;
 | ||
|           dec = 2;
 | ||
|         }
 | ||
|       }  
 | ||
| 
 | ||
|       if (flag == 3)
 | ||
|       { 
 | ||
|         if (dec > 0)
 | ||
|           decimali(field,dec);
 | ||
|         const real appoggio = field;
 | ||
|         field = appoggio.string(0, dec);
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == PART_NREG)
 | ||
|       {
 | ||
|         long numreg = atol(field);
 | ||
|         field.format("%7ld", numreg);        
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == PART_GRUPPO || fname == PART_CONTO || fname == PART_GRUPPOCL
 | ||
|           || fname == PART_CONTOCL || fname == PART_NUMRIG)
 | ||
|       {
 | ||
|         int app = atoi(field);
 | ||
|         field.format("%3d", app);
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == PART_ANNO || fname == PART_NRIGA)
 | ||
|       {
 | ||
|         int app = atoi(field);
 | ||
|         field.format("%4d", app);
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == PART_SOTTOCONTO)
 | ||
|       {
 | ||
|         long sottoc = atol(field);
 | ||
|         field.format("%6ld", sottoc);
 | ||
|       }
 | ||
| 
 | ||
|       if (fname == PART_NUMPART)
 | ||
|       {
 | ||
|         const char tipocf = _deppart->get_char(PART_TIPOCF);
 | ||
|         align_numpart(tipocf, field);
 | ||
|       }
 | ||
|       
 | ||
|       if (flag == 2)
 | ||
|       {
 | ||
|         TString f = converti(field,true);
 | ||
|         _deppart->put(fname,f);
 | ||
|       }
 | ||
|       else
 | ||
|         _deppart->put(fname, field);
 | ||
|           
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));    
 | ||
|   }
 | ||
| 
 | ||
|   _tpart->zero();
 | ||
|   _tpart->curr() = *_deppart;
 | ||
|       
 | ||
|   if (_tpart->read() == NOERR)     
 | ||
|   {   
 | ||
|     _tpart->zero();
 | ||
|     _tpart->curr() = *_deppart;
 | ||
|     _tpart->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _tpart->zero();
 | ||
|     _tpart->curr() = *_deppart;     
 | ||
|     _tpart->write();    
 | ||
|   }
 | ||
|   _prog->addstatus(1);  
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_scadenze(TString& record)
 | ||
| { 
 | ||
|   TString      sigla,key;
 | ||
|   int          numfield = 1;   
 | ||
|   const TMappa_trc&  trc  = mappa();
 | ||
|   
 | ||
|   sigla     = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
| 
 | ||
|   _depscad->zero();    
 | ||
|       
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     do
 | ||
|     {  
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString fname = trc.field_name(key); 
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       int     dec   = trc.flag_bis(key);
 | ||
|       
 | ||
|       TRecfield campo (*_depscad,fname);
 | ||
|       if (campo.type() == _realfld)
 | ||
|       { 
 | ||
|         TString sign,importo;
 | ||
|                     
 | ||
|         importo = field;            
 | ||
|         strip_zero(importo);
 | ||
|         if (importo.not_empty())
 | ||
|         {
 | ||
|           if (fname == SCAD_IMPORTO)
 | ||
|           {
 | ||
|             sign  = record.sub(116,117); 
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;
 | ||
|             else
 | ||
|               field = importo;
 | ||
|           }                         
 | ||
|           if (fname == SCAD_IMPORTOVAL)
 | ||
|           {
 | ||
|             sign  = record.sub(131,132);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else
 | ||
|               field = importo;
 | ||
|           }
 | ||
|           if (fname == SCAD_IMPORTOPAG)
 | ||
|           {
 | ||
|             sign  = record.sub(171,172);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           }
 | ||
|         }
 | ||
|         else
 | ||
|           field = importo;  
 | ||
|   
 | ||
|         // Cerco di riconoscere gli importi in euro  
 | ||
|         if (dec == 0 && (to-from) >= 8 && record.size()<1024 && ditta_in_euro())
 | ||
|         {
 | ||
|           flag = 3;
 | ||
|           dec = 2;
 | ||
|         }
 | ||
|       }  
 | ||
|       
 | ||
|       if (flag == 3)
 | ||
|       { 
 | ||
|         if (dec > 0)
 | ||
|           decimali(field,dec);
 | ||
|         const real appoggio = field;
 | ||
|         field = appoggio.string(0, dec);
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == SCAD_GRUPPO || fname == SCAD_CONTO)
 | ||
|       {
 | ||
|         int app = atoi(field);
 | ||
|         field.format("%3d", app);
 | ||
|       }                          
 | ||
|       
 | ||
|       if (fname == SCAD_ANNO || fname == SCAD_NRIGA || fname == SCAD_NRATA)
 | ||
|       {
 | ||
|         int app = atoi(field);
 | ||
|         field.format("%4d", app);
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == SCAD_SOTTOCONTO)
 | ||
|       {
 | ||
|         long app = atol(field);
 | ||
|         field.format("%6ld", app);
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == SCAD_NUMPART)
 | ||
|       {
 | ||
|         const char tipocf = _deppart->get_char(SCAD_TIPOCF);
 | ||
|         align_numpart(tipocf, field);
 | ||
|       }
 | ||
|       
 | ||
|       if (flag == 2)
 | ||
|       {
 | ||
|         TString f = converti(field,true);
 | ||
|         _depscad->put(fname,f);
 | ||
|       }
 | ||
|       else
 | ||
|         _depscad->put(fname, field);
 | ||
|           
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));    
 | ||
|   }
 | ||
| 
 | ||
|   _tscad->zero();
 | ||
|   _tscad->curr() = *_depscad;
 | ||
|       
 | ||
|   if (_tscad->read() == NOERR)     
 | ||
|   {   
 | ||
|     _tscad->zero();
 | ||
|     _tscad->curr() = *_depscad;
 | ||
|     _tscad->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _tscad->zero();
 | ||
|     _tscad->curr() = *_depscad;     
 | ||
|     _tscad->write();    
 | ||
|   }
 | ||
|   _prog->addstatus(1);  
 | ||
| }
 | ||
| 
 | ||
| void TTransfer_file::write_pagsca(TString& record)
 | ||
| { 
 | ||
|   TString      sigla,key;
 | ||
|   int          numfield = 1;   
 | ||
|   const TMappa_trc&  trc  = mappa();
 | ||
|   
 | ||
|   sigla     = record.mid(0,2);
 | ||
|   key.format("%2s%d", (const char*)sigla,numfield);
 | ||
| 
 | ||
|   _deppagsca->zero();    
 | ||
|       
 | ||
|   if (trc.is_key((const char *) key)) 
 | ||
|   {    
 | ||
|     do
 | ||
|     {  
 | ||
|       int     from  = trc.from(key);
 | ||
|       int     to    = trc.to(key);
 | ||
|       TString fname = trc.field_name(key); 
 | ||
|       TString field = record.sub(from-1,to); 
 | ||
|       int     flag  = trc.flag(key);
 | ||
|       int     dec   = trc.flag_bis(key);
 | ||
|       
 | ||
|       TRecfield campo (*_deppagsca,fname);
 | ||
|       if (campo.type() == _realfld)
 | ||
|       { 
 | ||
|         TString sign,importo;
 | ||
|  
 | ||
|         importo = field;            
 | ||
|         strip_zero(importo);
 | ||
|         if (importo.not_empty())
 | ||
|         {
 | ||
|           if (fname == PAGSCA_IMPORTO)
 | ||
|           {
 | ||
|             sign  = record.sub(61,62); 
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;
 | ||
|             else
 | ||
|               field = importo;
 | ||
|           }                         
 | ||
|           if (fname == PAGSCA_IMPORTOVAL)
 | ||
|           {
 | ||
|             sign  = record.sub(76,77);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else
 | ||
|               field = importo;
 | ||
|           }
 | ||
|           if (fname == PAGSCA_ABBUONI)
 | ||
|           {
 | ||
|             sign  = record.sub(94,95);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           }
 | ||
|           if (fname == PAGSCA_DIFFCAM)
 | ||
|           {
 | ||
|             sign  = record.sub(111,112);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else
 | ||
|               field == importo;
 | ||
|           }
 | ||
|           if (fname == PAGSCA_RITENUTE)
 | ||
|           {
 | ||
|             sign  = record.sub(126,127);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           }
 | ||
|           if (fname == PAGSCA_RITSOC)
 | ||
|           {
 | ||
|             sign  = record.sub(178,179);
 | ||
|             if (sign == "-")
 | ||
|               field = sign << importo;        
 | ||
|             else 
 | ||
|               field = importo;
 | ||
|           }
 | ||
|         }
 | ||
|         else
 | ||
|           field = importo;  
 | ||
|           
 | ||
|         // Cerco di riconoscere gli importi in euro  
 | ||
|         if (dec == 0 && (to-from) >= 8 && record.size()<1024 && ditta_in_euro())
 | ||
|         {
 | ||
|           flag = 3;
 | ||
|           dec = 2;
 | ||
|         }
 | ||
|       }  
 | ||
|       
 | ||
|       if (flag == 3)
 | ||
|       { 
 | ||
|         if (dec > 0)
 | ||
|           decimali(field,dec);
 | ||
|         const real appoggio = field;
 | ||
|         field = appoggio.string(0, dec);
 | ||
|       }
 | ||
|       
 | ||
|       if (fname == PAGSCA_GRUPPO || fname == PAGSCA_CONTO  ||
 | ||
|           fname == PAGSCA_GRUPPOC || fname == PAGSCA_CONTOC)
 | ||
|       {
 | ||
|         int app = atoi(field);
 | ||
|         field.format("%3d", app);
 | ||
|       }                          
 | ||
|       
 | ||
|       if (fname == PAGSCA_SOTTOCONTO || fname == PAGSCA_SOTTOCONTC)
 | ||
|       {
 | ||
|         long app = atol(field);
 | ||
|         field.format("%6ld", app);
 | ||
|       }                           
 | ||
|       
 | ||
|       if (fname == PAGSCA_ANNO || fname == PAGSCA_NRIGA ||
 | ||
|           fname == PAGSCA_NRATA || fname == PAGSCA_NRIGP)
 | ||
|       {
 | ||
|         int app = atoi(field);
 | ||
|         field.format("%4d", app);
 | ||
|       } 
 | ||
|       
 | ||
|       if (fname == PAGSCA_NUMPART)
 | ||
|       {
 | ||
|         const char tipocf = _deppart->get_char(PAGSCA_TIPOC);
 | ||
|         align_numpart(tipocf, field);
 | ||
|       }
 | ||
|       
 | ||
|       if (flag == 2)
 | ||
|       {
 | ||
|         TString f = converti(field,true);
 | ||
|         _depmov->put(fname,f);
 | ||
|       }
 | ||
|       else
 | ||
|         _deppagsca->put(fname, field);
 | ||
|           
 | ||
|       numfield++;
 | ||
|       key.format("%2s%d", (const char*) sigla,numfield);
 | ||
|     }
 | ||
|     while (trc.is_key((const char*) key));    
 | ||
|   }
 | ||
| 
 | ||
|   _tpagsca->zero();
 | ||
|   _tpagsca->curr() = *_deppagsca;
 | ||
|       
 | ||
|   if (_tpagsca->read() == NOERR)     
 | ||
|   {   
 | ||
|     _tpagsca->zero();
 | ||
|     _tpagsca->curr() = *_deppagsca;
 | ||
|     _tpagsca->rewrite();
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _tpagsca->zero();
 | ||
|     _tpagsca->curr() = *_deppagsca;     
 | ||
|     _tpagsca->write();    
 | ||
|   }
 | ||
|   _prog->addstatus(1);  
 | ||
| }
 | ||
| 
 | ||
| // -----------------------------------------------------------------------
 | ||
| // Mappa dei campi da trasferire
 | ||
| // -----------------------------------------------------------------------
 | ||
| 
 | ||
| bool TMappa_trc::leggi_modulo(const char* tracciato)
 | ||
| {
 | ||
|   TString16 key;
 | ||
|   TString4 sigla;
 | ||
|   TScanner s(tracciato);
 | ||
|   while (s.ok())
 | ||
|   {
 | ||
|     const TString& line = s.line();
 | ||
|     if (line[0] == '#') continue; //Perche' e' un commento
 | ||
| 
 | ||
|     TToken_string* record = new TToken_string(line);
 | ||
|     sigla  = record->get(0);
 | ||
|     long    numrec = record->get_long(1);
 | ||
|     key.format("%2s%d", (const char*)sigla,numrec);
 | ||
| 
 | ||
|     add(key, record);
 | ||
|   } 
 | ||
|   return items() > 0;
 | ||
| }
 | ||
| 
 | ||
| int TMappa_trc::from(const char* key) const
 | ||
| {
 | ||
|   TToken_string* data = (TToken_string*)objptr(key);
 | ||
|   return data->get_int(2);
 | ||
| }
 | ||
| 
 | ||
| int TMappa_trc::to(const char* key) const
 | ||
| {
 | ||
|   TToken_string* data = (TToken_string*)objptr(key);
 | ||
|   return data->get_int(3);
 | ||
| }
 | ||
| 
 | ||
| int TMappa_trc::logicnum(const char* key) const
 | ||
| {
 | ||
|   TToken_string* data = (TToken_string*)objptr(key);
 | ||
|   return data->get_int(4);
 | ||
| }
 | ||
| 
 | ||
| const char* TMappa_trc::field_name(const char* key) const
 | ||
| {
 | ||
|   TToken_string* data = (TToken_string*)objptr(key);
 | ||
|   return data->get(5);
 | ||
| }
 | ||
| 
 | ||
| int TMappa_trc::flag(const char* key) const
 | ||
| {
 | ||
|   TToken_string* data = (TToken_string*)objptr(key);
 | ||
|   return data->get_int(6);
 | ||
| }
 | ||
| 
 | ||
| int TMappa_trc::flag_bis(const char* key) const
 | ||
| {
 | ||
|   TToken_string* data = (TToken_string*)objptr(key);
 | ||
|   return data->get_int(7);
 | ||
| }
 | ||
| 
 | ||
| extern int get_error(int err);
 | ||
| 
 | ||
| int packfile(bool vis, int num, TString& name)
 | ||
| {
 | ||
|   TDir d;
 | ||
|   d.get(num,_nolock, _nordir,_sysdirop);
 | ||
|   d.get(num,_nolock, (d.is_com()) ? _comdir : _nordir);
 | ||
| 
 | ||
|   int err=DB_packfile(vis, name, d.eod());
 | ||
|   if (err != NOERR) err = get_error(err);
 | ||
| #ifdef DBG  
 | ||
|   if (err != NOERR) error_box("Errore in compattamento dati.\nFile %d : %d", d.num(),err);
 | ||
| #endif
 | ||
|   return err;
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| int packindex(bool vis, int num, TString& name)
 | ||
| {
 | ||
|   int err = NOERR;
 | ||
|   TRecnotype peod;
 | ||
|   TTrec r;
 | ||
|   TDir d;
 | ||
|   
 | ||
|   d.get(num,_nolock, _nordir, _sysdirop);
 | ||
|   d.get(num,_nolock, (d.is_com()) ? _comdir : _nordir);
 | ||
|   r.get(num);                
 | ||
|   err = DB_packindex(vis, name, &r.rec(), &peod,0);
 | ||
|   if (err != NOERR) err = get_error(err);
 | ||
| 
 | ||
| #ifdef DBG
 | ||
|   if (err != NOERR) error_box("Errore in compattamento indici.\nFile %d : %d", d.num(),err);
 | ||
| #endif
 | ||
|   return err;
 | ||
| }
 | ||
| 
 | ||
| int pack(bool vis, int num, TString& name)
 | ||
| {
 | ||
|   int err=NOERR;
 | ||
|   
 | ||
|   if ((err=packfile(vis, num, name))==NOERR)
 | ||
|     err=packindex(vis, num, name); 
 | ||
|   return err;
 | ||
| }
 | ||
| 
 | ||
| const char* converti(const TString& data_AS400, bool anno_di_quattro)
 | ||
| { 
 | ||
|   // if (data_AS400 == "000000" || data_AS400 == "00000000") 
 | ||
|   if (real::is_null(data_AS400))
 | ||
|     return EMPTY_STRING;
 | ||
|   
 | ||
|   TString& TEMP = get_tmp_string();
 | ||
|   if (anno_di_quattro)
 | ||
|   {
 | ||
|     TEMP = data_AS400.mid(6,2);
 | ||
|     TEMP << '-' << data_AS400.mid(4,2);
 | ||
|     TEMP << '-' << data_AS400.mid(0,4);  
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     TEMP = data_AS400.mid(4,2);
 | ||
|     TEMP << "-" << data_AS400.mid(2,2);
 | ||
|     TEMP << "-" << (data_AS400[0] < '8' ? "20" : "19") << data_AS400.mid(0,2);
 | ||
|   }  
 | ||
|   return TEMP;
 | ||
| }
 | ||
| 
 | ||
| const char* riconverti (const TString& data_PC,bool anno_di_quattro)
 | ||
| {                                           
 | ||
|   TString& TEMP = get_tmp_string();
 | ||
| 
 | ||
|   if (anno_di_quattro)
 | ||
|   {
 | ||
|     TEMP = data_PC.mid(6,4);
 | ||
|     TEMP << data_PC.mid(3,2);
 | ||
|     TEMP << data_PC.mid(0,2);
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     TEMP = data_PC.mid(8,2);
 | ||
|     TEMP << data_PC.mid(3,2);
 | ||
|     TEMP << data_PC.mid(0,2);  
 | ||
|   }
 | ||
|   return TEMP;
 | ||
| }
 | ||
| 
 | ||
| TDate TTransfer_file::data_fine_esercizio(int aep) const
 | ||
| {
 | ||
|   TDate datacomp;
 | ||
|   TEsercizi_contabili esc;
 | ||
|   if (esc.exist(aep))
 | ||
|     datacomp = esc[aep].fine();
 | ||
|   return datacomp;
 | ||
| }
 | ||
|                
 | ||
| int date2esc(const TDate& d, int* prevesc)
 | ||
| {                  
 | ||
|   TEsercizi_contabili esc;
 | ||
|   const int anno = esc.date2esc(d);
 | ||
|   if (prevesc)
 | ||
|     *prevesc = esc.pred(anno);
 | ||
|   return anno;
 | ||
| } |