balzanerie di GPF. git-svn-id: svn://10.65.10.50/trunk@3080 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1681 lines
		
	
	
		
			43 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1681 lines
		
	
	
		
			43 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| // Variazione movimenti Primanota   --> cg6 -7 P
 | |
| // Variazione movimenti Iva         --> cg6 -7 I
 | |
| // Variazione movimenti Saldaconto  --> cg6 -7 B
 | |
| // Visualizzazione stato ricezione  --> cg6 -7 V
 | |
| // Scelta ditta per ricezione       --> cg6 -7 S
 | |
| // Annullo movimenti ricezione      --> cg6 -7 A
 | |
| 
 | |
| #include <mask.h>
 | |
| #include <relation.h>
 | |
| #include <tabutil.h>
 | |
| #include <utility.h>
 | |
| #include <config.h>
 | |
| #include <mailbox.h>
 | |
| #include <prefix.h>
 | |
| 
 | |
| #include <nditte.h>  
 | |
| #include <mov.h>
 | |
| #include <rmov.h>
 | |
| #include <rmoviva.h>  
 | |
| #include <pconti.h>
 | |
| #include <occas.h>
 | |
| #include <comuni.h>
 | |
| 
 | |
| #include "cglib04.h"
 | |
| #include "cglib.h"   
 | |
| #include "cg2103.h"
 | |
| #include "conto.h"
 | |
| 
 | |
| #include "cg6800.h"
 | |
| #include "cg6801.h"
 | |
| #include "cg6802.h"
 | |
| #include "cg6803.h"
 | |
| #include "cg6804.h"
 | |
| 
 | |
| class TVar_mov : public TApplication
 | |
| {
 | |
|   TIsamtempfile*   _tmov, *_trmov, *_tiva, *_toccas;
 | |
|   TLocalisamfile*  _pcon, *_clifo, *_mov, *_rmov, *_rmoviva, *_occas;
 | |
|   TTable*          _tab_reg;
 | |
|   TRectype*        _rec_mov,* _rec_rmov,* _rec_riva;
 | |
|   TTransfer_file   _tras_file;
 | |
|   char             _scelta;
 | |
|   
 | |
|   TString _trasf,_std,_descr_civa;
 | |
|   long    _dittaric,_numreg;      
 | |
|   TString _control_rec,_record;         
 | |
|   bool    _righe,_corrisp, _is_exist;          
 | |
|   int     _numrig,_tiporeg;
 | |
|   bool    _registrato;
 | |
|   
 | |
| public:        
 | |
|   TString     _titolo;
 | |
|   
 | |
|   virtual bool create();
 | |
|   virtual bool destroy();
 | |
|   virtual bool menu(MENU_TAG m);         
 | |
|   bool    main_loop();
 | |
|   void    apri_temp_file();
 | |
|   bool    esegui_controlli();
 | |
|   bool    leggi_trasfer();
 | |
|   bool    controlli();
 | |
|   void    leggi_record_controllo();
 | |
|   bool    video_PN();
 | |
|   bool    video_IVA();  
 | |
|   void    registra_PN(TMask& m);                
 | |
|   void    registra_IVA(TMask& m);                  
 | |
|   bool    esiste_testata_mov(TMask& m);
 | |
|   bool    ricerca_movimento(TMask& m);
 | |
| 
 | |
|   bool    esiste_riga_mov(TMask& m);
 | |
|   bool    esiste_riga_iva(TMask& m);  
 | |
| 
 | |
|   void    ricerca_codcaus(const TString& codcaus);
 | |
|   void    setta_campi_maschera(TMask& m);                                  
 | |
|   bool    setta_campi_maschera_iva(TMask& m);                                    
 | |
| 
 | |
|   void    registra_file_temp_mov(int,long,const TDate&,const TDate&,const TDate&,const TString&,TString&,long,long,const TString&,TString&);
 | |
|   void    registra_file_temp_rmov(long,int,int,int,long,char,const TString&,int,int,long,const real&);
 | |
|   void    registra_file_temp_riva(long,int,const real&,const TString&,const real&,int,int,int,int,long);
 | |
| 
 | |
|   void    setta_parametri_record(const TString& sigla,const TString& flag);
 | |
|   
 | |
|   char    TipoConto (int g, int c);    
 | |
|   void    ricerca_localita(TString& com, TString& den, TString& cap, TString& prov);
 | |
|   
 | |
|   void    datacompetenza(int anno, TString& datacomp);
 | |
|   
 | |
|   static bool codice_registro_hnd   (TMask_field& f, KEY k);
 | |
|   static bool codice_causale_hnd    (TMask_field& f, KEY k);
 | |
|   static bool numero_protocollo_hnd (TMask_field& f, KEY k);
 | |
|   static bool ultimo_protocollo_hnd (TMask_field& f, KEY k);
 | |
|   static bool codice_pagamento_hnd  (TMask_field& f, KEY k);  
 | |
|   static bool data_stampa           (TMask_field& f, KEY k);  
 | |
|   static bool data_competenza_hnd   (TMask_field& f, KEY k);
 | |
|   
 | |
|   static bool controllo_partita       (TMask_field& f, KEY k);    
 | |
|   static bool controllo_contropartita (TMask_field& f, KEY k);    
 | |
|   static bool controllo_importo       (TMask_field& f, KEY k);    
 | |
|   
 | |
|   static bool localita_occasionali  (TMask_field& f, KEY k);
 | |
|   static bool cap_occasionali       (TMask_field& f, KEY k);  
 | |
|   static bool codice_clifo_hnd      (TMask_field& f, KEY k);
 | |
|   static bool codice_iva_hnd        (TMask_field& f, KEY k);  
 | |
|   static bool imposta_hnd           (TMask_field& f, KEY k);  
 | |
|   static bool detraibilita_hnd      (TMask_field& f, KEY k);  
 | |
|   static bool tipocr_hnd            (TMask_field& f, KEY k);
 | |
|   static bool data                  (TMask_field& f, KEY k);
 | |
| 
 | |
|   bool   decodifica_codiva(const TString& codiva);
 | |
|   
 | |
|   TVar_mov(char mov);
 | |
| };                                      
 | |
| 
 | |
| HIDDEN TVar_mov& app() { return (TVar_mov &) main_app(); }
 | |
| 
 | |
| char TVar_mov::TipoConto(int g, int c)
 | |
| {
 | |
|   TLocalisamfile pcon (LF_PCON);
 | |
|   char tipo = ' ';
 | |
|   
 | |
|   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);
 | |
| 
 | |
|   return tipo;
 | |
| }
 | |
| 
 | |
| TVar_mov::TVar_mov(char mov) : _scelta(toupper(mov))
 | |
| {
 | |
|   _tiva = NULL;
 | |
|   _toccas = NULL;
 | |
|   _tmov = NULL;
 | |
|   _trmov = NULL;
 | |
|   switch (_scelta)
 | |
|   {
 | |
|   case 'P':
 | |
|     _titolo = "Variazione movimenti prima nota";
 | |
|     break;
 | |
|     
 | |
|   case 'I':
 | |
|     _titolo = "Variazione movimenti iva";
 | |
|     break;
 | |
|     
 | |
|   default:
 | |
|     break;
 | |
|   }
 | |
| }
 | |
| 
 | |
| bool TVar_mov::create()
 | |
| {
 | |
|   TApplication::create();
 | |
| 
 | |
|   _pcon     = new TLocalisamfile (LF_PCON);
 | |
|   _clifo    = new TLocalisamfile (LF_CLIFO);
 | |
|   _rec_mov  = new TRectype (LF_MOV);
 | |
|   _mov      = new TLocalisamfile (LF_MOV);
 | |
|   _rmov     = new TLocalisamfile (LF_RMOV);
 | |
|   _rmoviva  = new TLocalisamfile (LF_RMOVIVA); 
 | |
|   _occas    = new TLocalisamfile (LF_OCCAS);
 | |
|   _tab_reg  = new TTable ("REG");
 | |
|   
 | |
|   _rec_rmov = new TRectype (LF_RMOV);
 | |
|   _rec_riva = new TRectype (LF_RMOVIVA);
 | |
|   
 | |
|   _registrato = FALSE;
 | |
|   
 | |
|   dispatch_e_menu (BAR_ITEM(1));
 | |
| 
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::destroy()
 | |
| { 
 | |
|   delete _rec_mov;
 | |
|   delete _pcon;
 | |
|   delete _clifo;
 | |
|   delete _mov;
 | |
|   delete _rmov;
 | |
|   delete _rmoviva;                          
 | |
|   delete _occas;
 | |
|   delete _tab_reg;
 | |
|   delete _rec_rmov;                         
 | |
|   delete _rec_riva;
 | |
|   if (_trmov)
 | |
|     delete _trmov;
 | |
|   if (_tiva)
 | |
|     delete _tiva;
 | |
|   if (_toccas)
 | |
|     delete _toccas;
 | |
|   if (_tmov)
 | |
|     delete _tmov;                               
 | |
|   
 | |
|   return TApplication::destroy();
 | |
| }                                
 | |
| 
 | |
| void TVar_mov::apri_temp_file()
 | |
| {
 | |
|   TString80 tmpmov = "%";
 | |
|   tmpmov  << get_firm_dir();
 | |
|   tmpmov << "\\" << TEMP_MOV;
 | |
|   TString80 tmprmov = "%";
 | |
|   tmprmov << get_firm_dir();         
 | |
|   tmprmov << "\\" << TEMP_RMOV;  
 | |
|     
 | |
|   _tmov     = new TIsamtempfile(LF_MOV, tmpmov, 0);
 | |
|   _trmov    = new TIsamtempfile(LF_RMOV, tmprmov, 0);
 | |
| 
 | |
|   TString80 tmprmoviva = "%";
 | |
|   tmprmoviva << get_firm_dir();     
 | |
|   tmprmoviva << "\\" << TEMP_RMOVIVA;                     
 | |
|   TString80 tmpoccas = "%";
 | |
|   tmpoccas << get_firm_dir();     
 | |
|   tmpoccas << "\\" << TEMP_OCC;                     
 | |
|   
 | |
|   _is_exist = FALSE;
 | |
|   TString tmp = tmprmoviva.mid(1);
 | |
|   tmp << ".dbf";
 | |
|   if (fexist(tmp))
 | |
|   {
 | |
|     _tiva     = new TIsamtempfile(LF_RMOVIVA, tmprmoviva, 0);
 | |
|     _toccas   = new TIsamtempfile(LF_OCCAS, tmpoccas, 0);
 | |
|     _is_exist = TRUE;
 | |
|   }
 | |
| }
 | |
| 
 | |
| void TVar_mov::leggi_record_controllo()
 | |
| {
 | |
|   _tras_file.read_control_rec();
 | |
|   _control_rec = _tras_file.record();
 | |
| }
 | |
| 
 | |
| bool TVar_mov::main_loop()
 | |
| {      
 | |
|   _dittaric = get_firm();
 | |
|   
 | |
|   if (!esegui_controlli()) return FALSE;
 | |
| 
 | |
|   apri_temp_file();
 | |
| 
 | |
|   if (_scelta == 'I' && !_is_exist)
 | |
|     return error_box("I movimenti iva non sono stati ricevuti: impossibile variarli");
 | |
|       
 | |
|   if (_scelta == 'P')
 | |
|   {
 | |
|     if (!video_PN())
 | |
|     {
 | |
|       if (_registrato)
 | |
|       {
 | |
|         setta_parametri_record(" ","C");
 | |
|         leggi_record_controllo();
 | |
|         TString str;
 | |
|         str.spaces(60);
 | |
|         _control_rec.overwrite(str,241);
 | |
|         _tras_file.write_control_rec(_control_rec,1024);
 | |
|       }
 | |
|       return FALSE;                                       
 | |
|     }  
 | |
|   }
 | |
|   else
 | |
|   {
 | |
|     if (_scelta == 'I')
 | |
|       if (!video_IVA())
 | |
|       {
 | |
|         if (_registrato)
 | |
|         {
 | |
|           setta_parametri_record(" ","C");
 | |
|           leggi_record_controllo();
 | |
|           TString str;
 | |
|           str.spaces(60);
 | |
|           _control_rec.overwrite(str,241);
 | |
|           _tras_file.write_control_rec(_control_rec,1024);
 | |
|         }
 | |
|         return FALSE;  
 | |
|       }
 | |
|   }
 | |
|   
 | |
|   return FALSE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::video_PN()
 | |
| {   
 | |
|   TMask* msk = new TMask("cg6800a");
 | |
|   KEY     tasto;
 | |
|   
 | |
|   do
 | |
|   { 
 | |
|     tasto = msk->run();     
 | |
|     
 | |
|     if (tasto != K_ENTER)
 | |
|     {
 | |
|       delete msk;
 | |
|       return FALSE;
 | |
|     }
 | |
|     
 | |
|     if (ricerca_movimento(*msk))
 | |
|     {
 | |
|       TMask* mask = new TMask("cg6800b");
 | |
|       
 | |
|       mask->set_handler(F_REGIVA,    codice_registro_hnd);
 | |
|       mask->set_handler(F_CODCAUS,   codice_causale_hnd);  
 | |
|       mask->set_handler(F_PROTIVA,   numero_protocollo_hnd);
 | |
|       mask->set_handler(F_NUPROTIVA, ultimo_protocollo_hnd);
 | |
|       mask->set_handler(F_CODPAG,    codice_pagamento_hnd);
 | |
|       mask->set_handler(F_DATAREG,   data_stampa);      
 | |
|       mask->set_handler(F_DATACOMP,  data_competenza_hnd);
 | |
|       //mask->set_handler(F_DATADOC,   data);
 | |
|             
 | |
|       if (_righe)                    
 | |
|       {
 | |
|         mask->set_handler(F_SOTTOCONTO, controllo_partita);
 | |
|         mask->set_handler(F_SOTTOC,     controllo_contropartita);
 | |
|         mask->set_handler(F_IMPORTO   , controllo_importo);
 | |
|       }
 | |
|       
 | |
|       setta_campi_maschera(*mask);
 | |
|       
 | |
|       tasto = mask->run();
 | |
|       
 | |
|       switch (tasto)
 | |
|       {
 | |
|       case K_ESC :
 | |
|         break;
 | |
|         
 | |
|       case K_QUIT :
 | |
|         break;       
 | |
|         
 | |
|       case K_SAVE :
 | |
|       {
 | |
|         registra_PN(*mask);
 | |
|         _registrato = TRUE;
 | |
|       }
 | |
|         break;
 | |
|         
 | |
|       default:
 | |
|         break;
 | |
|       }
 | |
|       delete mask;
 | |
|     }
 | |
|   }
 | |
|   while (tasto != K_QUIT);                              //K_ENTER
 | |
| 
 | |
|   delete msk;
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| void TVar_mov::ricerca_codcaus(const TString& codcaus)
 | |
| {
 | |
|   TLocalisamfile cau (LF_CAUSALI);
 | |
|   TString tipodoc;
 | |
|   
 | |
|   cau.setkey(1);
 | |
|   cau.zero();
 | |
|   cau.put("CODCAUS", (const char*) codcaus);
 | |
|   if (cau.read() == NOERR)
 | |
|     tipodoc = cau.get("TIPODOC");
 | |
|   
 | |
|   TTable tpd ("%TPD");
 | |
|   
 | |
|   tpd.zero();
 | |
|   tpd.put("CODTAB", (const char*) tipodoc);
 | |
|   if (tpd.read() == NOERR)
 | |
|     _corrisp = tpd.get_bool("B0");
 | |
| }
 | |
| 
 | |
| bool TVar_mov::video_IVA()
 | |
| {   
 | |
|   TMask* msk = new TMask("cg6800a");
 | |
|   KEY     tasto;
 | |
|   
 | |
|   do
 | |
|   { 
 | |
|     tasto = msk->run();
 | |
|     
 | |
|     if (tasto != K_ENTER)
 | |
|     {
 | |
|       delete msk;
 | |
|       return FALSE;
 | |
|     }
 | |
|     
 | |
|     if (ricerca_movimento(*msk))
 | |
|     {
 | |
|       TMask* mask = new TMask("cg6800c");                    
 | |
|       
 | |
|       TString regiva = _rec_mov->get(MOV_REG);
 | |
|       
 | |
|       if (!setta_campi_maschera_iva(*mask))
 | |
|       {
 | |
|         delete msk;
 | |
|         delete mask;
 | |
|         return FALSE;
 | |
|       }
 | |
|       
 | |
|       mask->set_handler(F_CODCF,     codice_clifo_hnd);              
 | |
|       //mask->set_handler(F_DATA74TER, data);
 | |
|       mask->set_handler(F_LOCALITA,  localita_occasionali);
 | |
|       mask->set_handler(F_CAPOCC,    cap_occasionali);
 | |
|       
 | |
|       if (_righe)                    
 | |
|       {
 | |
|         mask->set_handler(F_SOTTOCONTO, controllo_partita);
 | |
|         mask->set_handler(F_CODIVA,     codice_iva_hnd);
 | |
|         mask->set_handler(F_IMPOSTA,    imposta_hnd);
 | |
|         mask->set_handler(F_TIPODET,    detraibilita_hnd);
 | |
|         mask->set_handler(F_TIPOCR,     tipocr_hnd);
 | |
|       }
 | |
|       
 | |
|       tasto = mask->run();
 | |
|       
 | |
|       switch (tasto)
 | |
|       {
 | |
|       case K_ESC :
 | |
|         break;
 | |
|         
 | |
|       case K_QUIT :
 | |
|         break;       
 | |
|         
 | |
|       case K_SAVE :
 | |
|       {
 | |
|         registra_IVA(*mask);
 | |
|         _registrato = TRUE;
 | |
|       }
 | |
|         break;
 | |
|         
 | |
|       default:
 | |
|         break;
 | |
|       }
 | |
|       delete mask;
 | |
|     }
 | |
|   }
 | |
|   while (tasto != K_QUIT);                              //K_ENTER
 | |
| 
 | |
|   delete msk;
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::ricerca_movimento(TMask& m)
 | |
| {   
 | |
|   _numrig = atoi(m.get(F_NUMRIG));
 | |
|   
 | |
|   if (_numrig == 0)
 | |
|   {
 | |
|     _righe = FALSE;
 | |
|     return esiste_testata_mov(m);
 | |
|   }
 | |
|   else
 | |
|   {
 | |
|     _righe = TRUE;               
 | |
|     
 | |
|     bool annullato = esiste_testata_mov(m);
 | |
|     
 | |
|     if (!annullato) return FALSE;
 | |
|     
 | |
|     if (_scelta == 'P')
 | |
|       return esiste_riga_mov(m);
 | |
|     else
 | |
|       return esiste_riga_iva(m);
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::esiste_testata_mov(TMask& m)
 | |
| {
 | |
|   _numreg = m.get_long(F_NUMREG);
 | |
|   
 | |
|   _tmov->setkey(1);
 | |
|   _tmov->zero();
 | |
|   _tmov->put(MOV_NUMREG, _numreg);
 | |
|   
 | |
|   if (_tmov->read() == NOERR)
 | |
|   { 
 | |
|     if (_scelta == 'P')
 | |
|     {
 | |
|       _trmov->setkey(1);
 | |
|       _trmov->zero();
 | |
|       _trmov->put(RMI_NUMREG, _numreg);
 | |
|       _trmov->read();  
 | |
|       long nr = _trmov->get_long(RMV_NUMREG);
 | |
|       if (_numreg != nr)
 | |
|         return error_box("Registrazione richiesta NON PRESENTE tra i movimenti in trasferimento");
 | |
|     }
 | |
|     else
 | |
|       if (_scelta == 'I')
 | |
|       { 
 | |
|         _tiva->setkey(1);
 | |
|         _tiva->zero();
 | |
|         _tiva->put(RMI_NUMREG, _numreg);
 | |
|         _tiva->read();  
 | |
|         long nr = _tiva->get_long(RMI_NUMREG);
 | |
|         if (_numreg != nr)
 | |
|           return error_box("Registrazione richiesta NON PRESENTE tra i movimenti in trasferimento");
 | |
|       }
 | |
|     
 | |
|     *_rec_mov = _tmov->curr();  
 | |
|   }
 | |
|   else
 | |
|     return error_box("Registrazione richiesta NON PRESENTE tra i movimenti in trasferimento");
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::esiste_riga_mov(TMask& m)
 | |
| {
 | |
|   _numreg = m.get_long(F_NUMREG);
 | |
|   _numrig = m.get_int (F_NUMRIG);
 | |
|   
 | |
|   _trmov->setkey(1);
 | |
|   _trmov->zero();
 | |
|   _trmov->put(RMV_NUMREG, _numreg);
 | |
|   _trmov->put(RMV_NUMRIG, _numrig);  
 | |
|   
 | |
|   if (_trmov->read() == NOERR)
 | |
|     *_rec_rmov = _trmov->curr();  
 | |
|   else
 | |
|     return error_box("Registrazione richiesta NON PRESENTE tra i movimenti in trasferimento");
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::esiste_riga_iva(TMask& m)
 | |
| {
 | |
|   _numreg = m.get_long(F_NUMREG);
 | |
|   _numrig = m.get_int (F_NUMRIG);
 | |
|   
 | |
|   _tiva->setkey(1);
 | |
|   _tiva->zero();
 | |
|   _tiva->put(RMI_NUMREG, _numreg);
 | |
|   _tiva->put(RMI_NUMRIG, _numrig);  
 | |
|   
 | |
|   if (_tiva->read() == NOERR)
 | |
|     *_rec_riva = _tiva->curr();  
 | |
|   else
 | |
|     return error_box("Registrazione richiesta NON PRESENTE tra i movimenti in trasferimento");
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| void TVar_mov::setta_campi_maschera(TMask& m)
 | |
| {                                                     
 | |
|   TDate   datareg (_rec_mov->get_date(MOV_DATAREG));
 | |
|   TDate   datadoc (_rec_mov->get_date(MOV_DATADOC));
 | |
|   TDate   datacomp(_rec_mov->get_date(MOV_DATACOMP));
 | |
|   int     anno   = _rec_mov->get_int (MOV_ANNOES);
 | |
|   
 | |
|   TString numdoc    = _rec_mov->get     (MOV_NUMDOC);
 | |
|   TString regiva    = _rec_mov->get     (MOV_REG);
 | |
|   regiva.trim();
 | |
|   long    protiva   = _rec_mov->get_long(MOV_PROTIVA);
 | |
|   long    nuprotiva = _rec_mov->get_long(MOV_UPROTIVA);
 | |
|   TString codcaus   = _rec_mov->get     (MOV_CODCAUS);
 | |
|   TString codpag    = _rec_mov->get     (MOV_CODPAG);
 | |
|   codpag.trim();
 | |
|   
 | |
|   m.set(F_NUMREG,    _numreg);
 | |
|   m.set(F_NUMRIG,    _numrig); 
 | |
|   m.set(F_DATAREG,   datareg.string());
 | |
|   m.set(F_DATACOMP,  datacomp.string());
 | |
|   m.set(F_ANNO,      anno);
 | |
|   m.set(F_DATADOC,   datadoc.string());
 | |
|   m.set(F_NUMDOC,    numdoc);
 | |
|   m.set(F_REGIVA,    regiva);
 | |
|   m.set(F_PROTIVA,   protiva);
 | |
|   m.set(F_NUPROTIVA, nuprotiva);
 | |
|   m.set(F_CODCAUS,   codcaus);
 | |
|   m.set(F_CODPAG,    codpag);
 | |
| 
 | |
|   m.disable(F_NUMREG);
 | |
|   m.disable(F_NUMRIG);       
 | |
|   
 | |
|   if (!_righe)
 | |
|   {    
 | |
|     m.enable(F_DATAREG);    
 | |
|     m.enable(F_DATACOMP);
 | |
|     m.enable(F_DATADOC);
 | |
|     m.enable(F_NUMDOC);
 | |
|     m.enable(F_REGIVA);
 | |
|     m.enable(F_PROTIVA);
 | |
|     m.enable(F_NUPROTIVA);
 | |
|     m.enable(F_CODCAUS);
 | |
|     m.enable(F_CODPAG);
 | |
|     m.disable(F_GRUPPO);
 | |
|     m.disable(F_CONTO);
 | |
|     m.disable(F_SOTTOCONTO);
 | |
|     m.disable(F_SEZIONE);
 | |
|     m.disable(F_IMPORTO);
 | |
|     m.disable(F_DESCR);
 | |
|     m.disable(F_GRUPPOC);
 | |
|     m.disable(F_CONTOC);
 | |
|     m.disable(F_SOTTOC);
 | |
|   }
 | |
|   else    
 | |
|     if (_righe)
 | |
|     {
 | |
|       int     gruppo   = _trmov->get_int (RMV_GRUPPO);
 | |
|       int     conto    = _trmov->get_int (RMV_CONTO);
 | |
|       long    sottocon = _trmov->get_long(RMV_SOTTOCONTO);
 | |
|       TString sezione  = _trmov->get     (RMV_SEZIONE);
 | |
|       TString descr    = _trmov->get     (RMV_DESCR);
 | |
|       int     gruppoc  = _trmov->get_int (RMV_GRUPPOC);
 | |
|       int     contoc   = _trmov->get_int (RMV_CONTOC);
 | |
|       long    sottoc   = _trmov->get_long(RMV_SOTTOCONTOC);
 | |
|       real    importo  = _trmov->get_real(RMV_IMPORTO);  
 | |
|       
 | |
|       m.set(F_GRUPPO,     gruppo);
 | |
|       m.set(F_CONTO,      conto);
 | |
|       m.set(F_SOTTOCONTO, sottocon);
 | |
|       m.set(F_SEZIONE,    sezione);
 | |
|       m.set(F_DESCR,      descr);
 | |
|       m.set(F_GRUPPOC,    gruppoc);
 | |
|       m.set(F_CONTOC,     contoc);
 | |
|       m.set(F_SOTTOC,     sottoc);
 | |
|       m.set(F_IMPORTO,    importo.string());
 | |
|       
 | |
|       m.disable(F_DATAREG);           
 | |
|       m.disable(F_DATACOMP);
 | |
|       m.disable(F_DATADOC);
 | |
|       m.disable(F_NUMDOC);
 | |
|       m.disable(F_REGIVA);
 | |
|       m.disable(F_PROTIVA);
 | |
|       m.disable(F_NUPROTIVA);
 | |
|       m.disable(F_CODCAUS);
 | |
|       m.disable(F_CODPAG);
 | |
|       
 | |
|       m.enable(F_GRUPPO);
 | |
|       m.enable(F_CONTO);
 | |
|       m.enable(F_SOTTOCONTO);
 | |
|       m.enable(F_SEZIONE);
 | |
|       m.enable(F_IMPORTO);
 | |
|       m.enable(F_DESCR);
 | |
|       m.enable(F_GRUPPOC);
 | |
|       m.enable(F_CONTOC);
 | |
|       m.enable(F_SOTTOC);
 | |
|     }
 | |
| }
 | |
| 
 | |
| bool TVar_mov::setta_campi_maschera_iva(TMask& m)
 | |
| {  
 | |
|   TDate   datareg   (_rec_mov->get_date(MOV_DATAREG));
 | |
|   TDate   data74ter (_rec_mov->get_date(MOV_DATA74TER));
 | |
|   TString regiva    = _rec_mov->get     (MOV_REG);
 | |
|   regiva.trim();
 | |
|   TString codcaus   = _rec_mov->get     (MOV_CODCAUS);
 | |
|   long    codcf     = _rec_mov->get_long(MOV_CODCF); 
 | |
|   TString ocfpi     = _rec_mov->get     (MOV_OCFPI);
 | |
|   
 | |
| /*****************************************************
 | |
|  *****           CLIENTI OCCASIONALI             *****
 | |
|  *****************************************************/
 | |
| 
 | |
|   TString ragsoc,ind,com,cap,localita,prov,civ;  
 | |
|   
 | |
|   if (ocfpi.not_empty())
 | |
|   {              
 | |
|     _toccas->setkey(1);            
 | |
|     _toccas->zero();
 | |
|     _toccas->put(OCC_CFPI, ocfpi);
 | |
|     if (_toccas->read() == NOERR)
 | |
|     {
 | |
|       ragsoc    = _toccas->get(OCC_RAGSOC);
 | |
|       ind       = _toccas->get(OCC_INDIR);
 | |
|       civ       = _toccas->get(OCC_CIV);
 | |
|       com       = _toccas->get(OCC_COM);
 | |
|       cap       = _toccas->get(OCC_CAP);
 | |
|     
 | |
|       TLocalisamfile comuni (LF_COMUNI);
 | |
|     
 | |
|       comuni.setkey(1);
 | |
|       comuni.zero();
 | |
|       comuni.put(COM_COM, com);
 | |
|       if (comuni.read() == NOERR)
 | |
|       {                      
 | |
|         localita  = comuni.get(COM_DENCOM);
 | |
|         prov      = comuni.get(COM_PROVCOM);
 | |
|       }
 | |
|     }
 | |
|   }
 | |
|   
 | |
| /*****************************************************/
 | |
|   
 | |
|   if (codcaus.not_empty())
 | |
|     ricerca_codcaus(codcaus);
 | |
|   
 | |
|   int anno = date2esc(datareg);
 | |
|   
 | |
|   TRegistro rg (regiva, anno); 
 | |
|   _tiporeg = rg.tipo();
 | |
|   
 | |
|   if (regiva.not_empty())
 | |
|   {
 | |
|     if (!rg.ok())  
 | |
|       return error_box("Registrazione presente ma con PRIMANOTA ERRATA: correggerla prima");
 | |
|   }
 | |
|   else
 | |
|     return error_box("Campo NON VALIDO o codice NON PRESENTE in archivio");    
 | |
|   
 | |
|   m.set(F_NUMREG,    _numreg);
 | |
|   m.set(F_NUMRIG,    _numrig); 
 | |
|   m.set(F_DATA74TER, data74ter.string());
 | |
|   m.set(F_CODCF,     codcf);       
 | |
|   m.set(F_RAGSOCOCC, ragsoc);
 | |
|   m.set(F_INDOCC,    ind);   
 | |
|   m.set(F_CIVOCC,    civ);
 | |
|   m.set(F_LOCALITA,  localita);
 | |
|   m.set(F_CAPOCC,    cap);
 | |
|   m.set(F_PROVOCC,   prov);          
 | |
|   m.set(F_COMOCC,    com);
 | |
|   m.set(F_CFPI,      ocfpi);
 | |
| 
 | |
|   m.disable(F_NUMREG);
 | |
|   m.disable(F_NUMRIG);       
 | |
|   
 | |
|   if (!_righe)
 | |
|   {    
 | |
|     m.enable(F_DATA74TER);
 | |
|     m.enable(F_CODCF);
 | |
|     m.enable(F_RAGSOCOCC);
 | |
|     m.enable(F_INDOCC);
 | |
|     m.enable(F_CIVOCC);
 | |
|     m.enable(F_LOCALITA);
 | |
|     m.enable(F_CAPOCC);
 | |
|     m.enable(F_PROVOCC);
 | |
|     m.disable(F_IMPONIBILE);
 | |
|     m.disable(F_CODIVA);
 | |
|     m.disable(F_IMPOSTA);
 | |
|     m.disable(F_TIPODET);
 | |
|     m.disable(F_TIPOCR);
 | |
|     m.disable(F_GRUPPO);
 | |
|     m.disable(F_CONTO);
 | |
|     m.disable(F_SOTTOCONTO);
 | |
|   }
 | |
|   else
 | |
|     if (_righe)
 | |
|     {
 | |
|       real    imponibile (_tiva->get_real(RMI_IMPONIBILE));
 | |
|       TString codiva     (_tiva->get     (RMI_CODIVA));
 | |
|       real    imposta    (_tiva->get_real(RMI_IMPOSTA));
 | |
|       int     tipodet   = _tiva->get_int (RMI_TIPODET);
 | |
|       int     tipocr    = _tiva->get_int (RMI_TIPOCR);
 | |
|       int     gruppo    = _tiva->get_int (RMI_GRUPPO);
 | |
|       int     conto     = _tiva->get_int (RMI_CONTO);
 | |
|       long    sottoc    = _tiva->get_long(RMI_SOTTOCONTO);
 | |
|       
 | |
|       m.set(F_IMPONIBILE, imponibile.string());
 | |
|       m.set(F_CODIVA,     codiva);
 | |
|       m.set(F_IMPOSTA,    imposta.string());
 | |
|       m.set(F_TIPODET,    tipodet);
 | |
|       m.set(F_TIPOCR,     tipocr);
 | |
|       m.set(F_GRUPPO,     gruppo);
 | |
|       m.set(F_CONTO,      conto);
 | |
|       m.set(F_SOTTOCONTO, sottoc);
 | |
|       
 | |
|       m.disable(F_DATA74TER);
 | |
|       m.disable(F_CODCF);
 | |
|       m.disable(F_RAGSOCOCC);
 | |
|       m.disable(F_INDOCC);
 | |
|       m.disable(F_CIVOCC);
 | |
|       m.disable(F_LOCALITA);
 | |
|       m.disable(F_CAPOCC);
 | |
|       m.disable(F_PROVOCC);
 | |
|       
 | |
|       m.enable(F_IMPONIBILE);
 | |
|       m.enable(F_CODIVA);
 | |
|       m.enable(F_IMPOSTA);
 | |
|       m.enable(F_TIPODET);
 | |
|       m.enable(F_TIPOCR);
 | |
|       m.enable(F_GRUPPO);
 | |
|       m.enable(F_CONTO);
 | |
|       m.enable(F_SOTTOCONTO);
 | |
|     }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::codice_registro_hnd(TMask_field& f, KEY k)
 | |
| { 
 | |
|   TTable reg ("REG");
 | |
|   TString descr,dep;
 | |
|   
 | |
|   if (k == K_TAB || k == K_ENTER)
 | |
|   {              
 | |
|     TString codreg = f.get();
 | |
|     TDate   datareg (f.mask().get(F_DATAREG));
 | |
|     int     anno   = date2esc(datareg);
 | |
|     
 | |
|     dep.format("%04d%-3s", anno, (const char*) codreg);
 | |
|     
 | |
|     reg.zero();
 | |
|     reg.put("CODTAB", dep);
 | |
|     if (reg.read() == NOERR)
 | |
|     {
 | |
|       descr = reg.get("S0");
 | |
|       f.mask().set(F_DESCRREG, descr);
 | |
|     }
 | |
|     else
 | |
|       if (codreg.not_empty() && f.mask().is_running())
 | |
|       {
 | |
|         descr = "";
 | |
|         f.mask().set(F_DESCRREG, descr);
 | |
|         return warning_box("Codice registro IVA non presente in tabella");                               
 | |
|       }
 | |
|   } 
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::codice_causale_hnd(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k == K_TAB || k == K_ENTER)
 | |
|   {         
 | |
|     TString codcau = f.get();
 | |
|     
 | |
|     if (f.mask().is_running())
 | |
|     {
 | |
|       TString codreg = f.mask().get(F_REGIVA);
 | |
|       
 | |
|       if (codreg.not_empty())
 | |
|         if (codcau.empty())
 | |
|           return warning_box("Il codice registro IVA e' significativo: deve essere significativo anche il codice causale");
 | |
|     }
 | |
|     
 | |
|     TLocalisamfile cau (LF_CAUSALI);
 | |
|     cau.setkey(1);
 | |
|     cau.zero();
 | |
|     cau.put("CODCAUS", codcau);
 | |
|     if (cau.read() == NOERR)
 | |
|     {
 | |
|       const TString& descr = cau.get("DESCR");
 | |
|       f.mask().set(F_DESCRCAU, descr);
 | |
|     }                                 
 | |
|     else           
 | |
|       if (f.mask().is_running())
 | |
|       {
 | |
|         const TString& descr = "";
 | |
|         f.mask().set(F_DESCRCAU, descr);  
 | |
|         return warning_box("Codice causale non presente in tabella");
 | |
|       }
 | |
|   }            
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::numero_protocollo_hnd(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k != K_ENTER) return FALSE;
 | |
|   
 | |
|   TString codreg   = f.mask().get(F_REGIVA);
 | |
|   long    protiva  = atol(f.mask().get(F_PROTIVA));
 | |
|   long    uprotiva = atol(f.mask().get(F_NUPROTIVA));
 | |
|   
 | |
|   if (codreg.empty())
 | |
|     if (protiva != 0)
 | |
|       return warning_box("Il codice registro IVA non e' significativo: non e' possibile compilare il numero protocollo IVA");
 | |
|   
 | |
|   return TRUE;    
 | |
| }
 | |
| 
 | |
| bool TVar_mov::ultimo_protocollo_hnd(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k != K_ENTER) return FALSE;
 | |
|   
 | |
|   TString codreg   = f.mask().get(F_REGIVA);
 | |
|   long    protiva  = atol(f.mask().get(F_PROTIVA));
 | |
|   long    uprotiva = atol(f.mask().get(F_NUPROTIVA));
 | |
|   
 | |
|   if (codreg.empty())
 | |
|     if (uprotiva != 0)  
 | |
|       return warning_box("Il codice registro IVA non e' significativo: non e' possibile compilare l' ultimo numero protocollo IVA");
 | |
|   
 | |
|   if (protiva == 0)
 | |
|     if (uprotiva != 0)
 | |
|       return warning_box("Numero protocollo IVA non significativo: non e' possibile compilare il numero protocollo IVA riepilogato"); 
 | |
|   
 | |
|   return TRUE;    
 | |
| }
 | |
| 
 | |
| bool TVar_mov::codice_pagamento_hnd(TMask_field& f, KEY k)
 | |
| { 
 | |
|   TTable pag ("%CPG");
 | |
|   TString descr,codpag,dep;
 | |
|   
 | |
|   if (k == K_TAB || k == K_ENTER)
 | |
|   {              
 | |
|     codpag = f.get();
 | |
|     dep.format("%04s", (const char*)codpag);
 | |
|     
 | |
|     pag.zero();
 | |
|     pag.put("CODTAB", dep);
 | |
|     if (pag.read() == NOERR)
 | |
|     {
 | |
|       descr = pag.get("S0");
 | |
|       f.mask().set(F_DESCRPAG, descr);
 | |
|     }
 | |
|     else
 | |
|       if (codpag.not_empty() && k == K_ENTER)
 | |
|       {
 | |
|         descr = "";
 | |
|         f.mask().set(F_DESCRPAG, descr);  
 | |
|         return warning_box("Codice pagamento non presente in tabella");                               
 | |
|       }
 | |
|   } 
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
|                                                             
 | |
| bool TVar_mov::data_competenza_hnd(TMask_field& f, KEY k)
 | |
| {             
 | |
|   if (k == K_TAB || k == K_ENTER)
 | |
|   {
 | |
|     const TDate dr(f.mask().get(F_DATAREG));      // Data operazione
 | |
|                     
 | |
|     if (f.mask().is_running())                
 | |
|       if ( !(TDate::isdate(f.get())) )
 | |
|         return warning_box("Data errata o formato non valido");
 | |
|       
 | |
|     TString16 datacomp = f.get();
 | |
|     if (datacomp.empty())
 | |
|     {                           
 | |
|       int anno = atoi(f.mask().get(F_ANNO));
 | |
|       app().datacompetenza(anno,datacomp);
 | |
|       f.set(datacomp);
 | |
|     }
 | |
| 
 | |
|     TDate dc (f.get());
 | |
|     
 | |
|     int ae = date2esc(dc);
 | |
|     
 | |
|     if (ae)
 | |
|     {                     
 | |
|       int pr;                             // Esercizio precedente
 | |
|       const int ar = date2esc(dr, &pr);   // Esercizio in corso
 | |
|       if (ae != ar && ae != pr)
 | |
|       {
 | |
|         TString80 e; 
 | |
|         e << "La data di competenza deve appartenere all'esercizio " << ar; 
 | |
|         if (pr > 0) e << " o al " << pr;
 | |
|         return f.error_box(e);
 | |
|       }
 | |
|       f.mask().set(F_ANNO, ae);
 | |
|     }  
 | |
|     else  
 | |
|     {
 | |
|       if (f.mask().is_running())
 | |
|         return f.error_box("La data non appartiene a nessun esercizio");
 | |
|     }
 | |
|   }
 | |
|    
 | |
|   return TRUE;
 | |
| }
 | |
|                                                             
 | |
| bool TVar_mov::data_stampa(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k == K_ENTER)
 | |
|   {     
 | |
|     if (f.mask().is_running())
 | |
|       if ( !(TDate::isdate(f.get())) )
 | |
|         return warning_box("Data errata o formato non valido");
 | |
|       
 | |
|     TDate datareg (f.mask().get(F_DATAREG));                               
 | |
|     const int ae = date2esc(datareg);         
 | |
|   
 | |
|     TLibro_giornale gio;
 | |
|     gio.read(ae);  //se _ae e' zero la read considera come anno quello corrente
 | |
|   
 | |
|     if (datareg < gio.last_print())
 | |
|       return warning_box("La data di registrazione e' minore della data di stampa del Libro Giornale");  
 | |
| 
 | |
|     TString codreg = f.mask().get(F_REGIVA);
 | |
| 
 | |
|     if (!codreg.blank()) //movimento iva (fattura)
 | |
|     {
 | |
|       TRegistro rg (codreg, ae);   
 | |
|     
 | |
|       if (datareg < rg.last_print())
 | |
|         return error_box("La data di registrazione e' minore della data stampa del registro IVA");
 | |
|     }
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::controllo_partita(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k == K_TAB || k == K_ENTER)
 | |
|   {  
 | |
|     int  gruppo = f.mask().get_int (F_GRUPPO);
 | |
|     int  conto  = f.mask().get_int (F_CONTO);
 | |
|     long sottoc = f.mask().get_long(F_SOTTOCONTO);
 | |
|     
 | |
|     char tipo = app().TipoConto(gruppo,conto);
 | |
|     
 | |
|     TConto tc (gruppo,conto,sottoc,tipo); 
 | |
|     
 | |
|     TString descr = tc.descrizione();          
 | |
|     f.mask().set(F_DESCRPARTITA, descr);
 | |
|     
 | |
|     if (k == K_ENTER)
 | |
|       if (!tc.find())
 | |
|         return warning_box("Sottoconto partita non presente in anagrafica Piano dei Conti oppure anagrafica Clienti / Fornitori");
 | |
|   }     
 | |
|   
 | |
|   return TRUE; 
 | |
| }
 | |
| 
 | |
| bool TVar_mov::controllo_contropartita(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k == K_TAB || k == K_ENTER)
 | |
|   { 
 | |
|     int  gruppo = f.mask().get_int (F_GRUPPOC);
 | |
|     int  conto  = f.mask().get_int (F_CONTOC);
 | |
|     long sottoc = f.mask().get_long(F_SOTTOC);
 | |
|     
 | |
|     char tipo = app().TipoConto(gruppo,conto);
 | |
|     
 | |
|     TConto tc (gruppo,conto,sottoc,tipo); 
 | |
|     
 | |
|     TString descr = tc.descrizione();          
 | |
|     f.mask().set(F_DESCRCPARTITA, descr);
 | |
|     
 | |
|     if (k == K_ENTER)
 | |
|       if (gruppo != 0 && conto != 0 && sottoc != 0)
 | |
|         if (!tc.find())
 | |
|           return warning_box("Sottoconto contropartita non presente in anagrafica Piano dei Conti oppure anagrafica Clienti / Fornitori");
 | |
|   }     
 | |
|   
 | |
|   return TRUE; 
 | |
| }
 | |
| 
 | |
| bool TVar_mov::controllo_importo(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k == K_ENTER)
 | |
|   {
 | |
|     real importo (f.mask().get(F_IMPORTO));
 | |
|     char sezione = f.mask().get(F_SEZIONE)[0];
 | |
|     
 | |
|     if (importo == ZERO && (sezione == 'A' || sezione == 'D') )
 | |
|       return warning_box("L' importo deve essere significativo");
 | |
|     if (sezione == '\0' && importo != ZERO)
 | |
|       return warning_box("La sezione e' nulla: l'importo non puo' essere significativo");
 | |
|   }     
 | |
|   
 | |
|   return TRUE; 
 | |
| }
 | |
| 
 | |
| bool TVar_mov::codice_clifo_hnd(TMask_field& f, KEY k)
 | |
| {   
 | |
|   char tipo;
 | |
|   
 | |
|   if (k == K_TAB || k == K_ENTER) 
 | |
|   {
 | |
|     long codcf = atol(f.get());
 | |
|     if (app()._tiporeg == 1)
 | |
|       tipo = 'C';
 | |
|     else
 | |
|       if (app()._tiporeg == 2)
 | |
|         tipo = 'F';
 | |
|     
 | |
|     TConto tc (0,0,codcf,tipo);
 | |
|     
 | |
|     if (tc.find())
 | |
|     {
 | |
|       TString descr = tc.descrizione();
 | |
|       f.mask().set(F_RAGSOCCF, descr);
 | |
|     }                                 
 | |
|     else
 | |
|       if (k == K_ENTER)
 | |
|       {
 | |
|         TString descr = "";
 | |
|         f.mask().set(F_RAGSOCCF, descr);  
 | |
|         return warning_box("Campo NON VALIDO o codice non presente in archivio");
 | |
|       }
 | |
|   }
 | |
|   
 | |
|   return TRUE;  
 | |
| }
 | |
| 
 | |
| bool TVar_mov::localita_occasionali(TMask_field& f, KEY k)
 | |
| {             
 | |
|   if (k == K_TAB)
 | |
|   {  
 | |
|     TString com,den,prov,cap;  
 | |
|     
 | |
|     com  = "";
 | |
|     den  = "";
 | |
|     prov = "";
 | |
|     cap  = "";
 | |
|           
 | |
|     TString localita = f.mask().get(F_LOCALITA);
 | |
|     
 | |
|     com = app()._tras_file.cerca_comune_den(localita);
 | |
|       
 | |
|     if (com.not_empty())           
 | |
|       app().ricerca_localita(com,den,cap,prov);  
 | |
| 
 | |
|     f.mask().set(F_COMOCC,   com);
 | |
|     f.mask().set(F_LOCALITA, den);
 | |
|     f.mask().set(F_CAPOCC,   cap);
 | |
|     f.mask().set(F_PROVOCC,  prov);
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::cap_occasionali(TMask_field& f, KEY k)
 | |
| {             
 | |
|   if (k == K_TAB)
 | |
|   { 
 | |
|     TString com,den,prov,cap;
 | |
|     
 | |
|     den  = "";
 | |
|     prov = "";
 | |
|     cap  = "";
 | |
|     com  = "";
 | |
|             
 | |
|     TString capocc = f.mask().get(F_CAPOCC);    
 | |
|     
 | |
|     if (capocc.not_empty())
 | |
|       com = app()._tras_file.cerca_comune_cap(capocc,den);
 | |
| 
 | |
|     if (com.not_empty())           
 | |
|       app().ricerca_localita(com,den,cap,prov);  
 | |
| 
 | |
|     f.mask().set(F_COMOCC,   com);
 | |
|     f.mask().set(F_LOCALITA, den);
 | |
|     f.mask().set(F_CAPOCC,   cap);
 | |
|     f.mask().set(F_PROVOCC,  prov);
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::codice_iva_hnd(TMask_field& f, KEY k)
 | |
| {   
 | |
|   if (k == K_TAB || k == K_ENTER) 
 | |
|   {
 | |
|     TString codiva = f.get();
 | |
|     
 | |
|     bool ok = app().decodifica_codiva(codiva);
 | |
|     
 | |
|     f.mask().set(F_DESCRCODIVA, app()._descr_civa);
 | |
|     
 | |
|     if (k == K_ENTER)
 | |
|     {
 | |
|       real imponibile (f.mask().get(F_IMPONIBILE));
 | |
|       real imposta    (f.mask().get(F_IMPOSTA));
 | |
|       
 | |
|       if ( (imponibile != ZERO || imposta != ZERO) && codiva.empty() )
 | |
|         return warning_box("Il codice IVA deve essere indicato obbligatoriamente");
 | |
|       
 | |
|       if (codiva.not_empty())
 | |
|         if (!ok)
 | |
|           return warning_box("Codice non presente in tabella");  
 | |
|     }
 | |
|   }
 | |
|   
 | |
|   return TRUE;  
 | |
| }
 | |
| 
 | |
| bool TVar_mov::decodifica_codiva(const TString& codiva)
 | |
| {
 | |
|   TTable iva ("%IVA");
 | |
|   TString dep;
 | |
|   
 | |
|   dep.format("%-4s", (const char*)codiva);
 | |
|   
 | |
|   iva.zero();
 | |
|   iva.put("CODTAB", dep);
 | |
|   if (iva.read() == NOERR)
 | |
|   {
 | |
|     _descr_civa = iva.get("S0");
 | |
|     return TRUE;
 | |
|   }  
 | |
|   else        
 | |
|   {
 | |
|     _descr_civa = "";
 | |
|     return FALSE;
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::imposta_hnd(TMask_field& f, KEY k)
 | |
| {   
 | |
|   if (k == K_ENTER) 
 | |
|   {
 | |
|     real imposta    (f.mask().get(F_IMPOSTA));
 | |
|     
 | |
|     if (app()._corrisp && imposta != ZERO)
 | |
|       return warning_box("Il movimento e' relativo ad un corrispettivo: l'imposta deve essere uguale a 0");
 | |
|   }
 | |
|   
 | |
|   return TRUE;  
 | |
| }
 | |
| 
 | |
| bool TVar_mov::detraibilita_hnd(TMask_field& f, KEY k)
 | |
| {   
 | |
|   if (k == K_ENTER) 
 | |
|   {
 | |
|     int det = atoi(f.get());
 | |
|     
 | |
|     if (det != 0 && det != 1 && det != 3 && det != 9)
 | |
|       return warning_box("Valore non ammesso per il tipo detraibilita'");
 | |
|   }
 | |
|   
 | |
|   return TRUE;  
 | |
| }
 | |
| 
 | |
| bool TVar_mov::tipocr_hnd(TMask_field& f, KEY k)
 | |
| {   
 | |
|   if (k == K_ENTER) 
 | |
|   {
 | |
|     int tcr = atoi(f.get());
 | |
|     
 | |
|     if (tcr != 0 && tcr != 1 && tcr != 2 && tcr != 3 
 | |
|         && tcr != 4 && tcr != 5 && tcr != 8 && tcr != 9)
 | |
|       return warning_box("Valore non ammesso per il tipo costo/ricavo");
 | |
|   }
 | |
|   
 | |
|   return TRUE;  
 | |
| }                                   
 | |
| 
 | |
| bool TVar_mov::data(TMask_field& f, KEY k)
 | |
| {   
 | |
|   if (k == K_ENTER) 
 | |
|   { 
 | |
|     if ( !(TDate::isdate(f.get())) )
 | |
|       return warning_box("Data errata o formato non valido");
 | |
|   }
 | |
|   
 | |
|   return TRUE;  
 | |
| }                                   
 | |
| 
 | |
| void TVar_mov::datacompetenza(int anno, TString& datacomp)
 | |
| {
 | |
|   TTable esc ("ESC");
 | |
|   
 | |
|   TString dep (format("%04d", anno));
 | |
|   
 | |
|   esc.zero();
 | |
|   esc.put("CODTAB", dep);
 | |
|   if (esc.read() == NOERR)
 | |
|     datacomp = esc.get("D1");
 | |
|   else
 | |
|     datacomp = "";
 | |
| }
 | |
| 
 | |
| void TVar_mov::ricerca_localita(TString& codcom, TString& den, TString& cap, TString& prov)
 | |
| {
 | |
|   TLocalisamfile com (LF_COMUNI);
 | |
|   
 | |
|   com.setkey(1);
 | |
|   com.zero();
 | |
|   com.put(COM_COM, codcom);
 | |
|   if (com.read() == NOERR)
 | |
|   {
 | |
|     den  = com.get(COM_DENCOM);
 | |
|     cap  = com.get(COM_CAPCOM);
 | |
|     prov = com.get(COM_PROVCOM);
 | |
|   }                             
 | |
|   else
 | |
|   {
 | |
|     den  = "";                 
 | |
|     cap  = "";
 | |
|     prov = "";
 | |
|   }
 | |
| }
 | |
| 
 | |
| void TVar_mov::registra_PN(TMask& m)
 | |
| { 
 | |
|   if (!_righe)
 | |
|   {
 | |
|     long    numreg    = m.get_long(F_NUMREG);
 | |
|     int     anno      = m.get_int (F_ANNO);    
 | |
|     TDate   datareg    (m.get(F_DATAREG));
 | |
|     TDate   datacomp   (m.get(F_DATACOMP));        
 | |
|     TDate   datadoc    (m.get(F_DATADOC));
 | |
|     TString numdoc    = m.get     (F_NUMDOC);
 | |
|     TString regiva    = m.get     (F_REGIVA);
 | |
|     long    protiva   = m.get_long(F_PROTIVA);
 | |
|     long    nuprotiva = m.get_long(F_NUPROTIVA);
 | |
|     TString codcaus   = m.get     (F_CODCAUS);
 | |
|     TString codpag    = m.get     (F_CODPAG);
 | |
|     
 | |
|     registra_file_temp_mov(anno,numreg,datareg,datacomp,datadoc,numdoc,regiva,protiva,nuprotiva,codcaus,codpag);
 | |
|   }
 | |
|   else
 | |
|     if (_righe)
 | |
|     {                                    
 | |
|       long    numreg   = m.get_long(F_NUMREG);
 | |
|       int     numrig   = m.get_int (F_NUMRIG);
 | |
|       int     gruppo   = m.get_int (F_GRUPPO);
 | |
|       int     conto    = m.get_int (F_CONTO);      
 | |
|       long    sottoc   = m.get_long(F_SOTTOCONTO);
 | |
|       char    sezione  = m.get     (F_SEZIONE)[0];
 | |
|       TString descr    = m.get     (F_DESCR);
 | |
|       int     gruppoc  = m.get_int (F_GRUPPOC);
 | |
|       int     contoc   = m.get_int (F_CONTOC);
 | |
|       long    sottocc  = m.get_long(F_SOTTOC);
 | |
|       real    importo  (m.get(F_IMPORTO));  
 | |
|       
 | |
|       registra_file_temp_rmov(numreg,numrig,gruppo,conto,sottoc,sezione,descr,gruppoc,contoc,sottocc,importo);
 | |
|     }
 | |
| }
 | |
| 
 | |
| void TVar_mov::registra_file_temp_mov(int ae,long nr,const TDate& dr,const TDate& dc,const TDate& dd,
 | |
|                                       const TString& nd,TString& ri,long pi,long upi,const TString& cc,TString& cp)
 | |
| {
 | |
|   _tmov->setkey(1);
 | |
|   _tmov->zero();
 | |
|   _tmov->put(MOV_NUMREG, nr);
 | |
|   if (_tmov->read() == NOERR)
 | |
|   {                              
 | |
|     _tmov->put(MOV_NUMREG,   nr);
 | |
|     _tmov->put(MOV_ANNOES,   ae);
 | |
|     _tmov->put(MOV_DATAREG,  dr);
 | |
|     _tmov->put(MOV_DATACOMP, dc);
 | |
|     _tmov->put(MOV_DATADOC,  dd);
 | |
|     _tmov->put(MOV_NUMDOC,   nd);  
 | |
|     _tmov->put(MOV_REG,      ri);
 | |
|     _tmov->put(MOV_PROTIVA,  pi);
 | |
|     _tmov->put(MOV_UPROTIVA, upi);
 | |
|     _tmov->put(MOV_CODCAUS,  cc);
 | |
|     _tmov->put(MOV_CODPAG,   cp);
 | |
|     int ai = dr.year();
 | |
|     _tmov->put(MOV_ANNOIVA,  ai);
 | |
|     
 | |
|     _tmov->rewrite();
 | |
|   }
 | |
|   
 | |
|   TRectype* rec_rmov,* rec_riva;
 | |
|   rec_rmov = new TRectype (LF_RMOV);
 | |
| 
 | |
|   _trmov->setkey(1);
 | |
|   _trmov->zero();
 | |
|   _trmov->put(RMV_NUMREG, nr); 
 | |
|   *rec_rmov = _trmov->curr();
 | |
|   
 | |
|   for (_trmov->read(); !_trmov->eof(); _trmov->next())
 | |
|   {
 | |
|     if (_trmov->curr() > *rec_rmov) break;
 | |
|     
 | |
|     _trmov->put(RMV_ANNOES,  ae);
 | |
|     _trmov->put(RMV_DATAREG, dr);
 | |
|     
 | |
|     _trmov->rewrite();
 | |
|   }
 | |
|   
 | |
|   delete rec_rmov;
 | |
|   
 | |
|   rec_riva = new TRectype (LF_RMOVIVA);
 | |
| 
 | |
|   _tiva->setkey(1);
 | |
|   _tiva->zero();
 | |
|   _tiva->put(RMI_NUMREG, nr); 
 | |
|   *rec_riva = _tiva->curr();
 | |
|   
 | |
|   for (_tiva->read(); !_tiva->eof(); _tiva->next())
 | |
|   {
 | |
|     if (_tiva->curr() > *rec_riva) break;
 | |
|     
 | |
|     _tiva->put(RMI_ANNOES, ae);
 | |
|     
 | |
|     _tiva->rewrite();
 | |
|   }
 | |
|   
 | |
|   delete rec_riva;
 | |
| }
 | |
| 
 | |
| void TVar_mov::registra_file_temp_rmov(long nr,int nri,int g,int c,long s,char sez,const TString& desc,
 | |
|                                        int gc,int cc,long sc,const real& imp)
 | |
| {
 | |
|   _trmov->setkey(1);
 | |
|   _trmov->zero();
 | |
|   _trmov->put(RMV_NUMREG, nr);
 | |
|   _trmov->put(RMV_NUMRIG, nri);  
 | |
|   if (_trmov->read() == NOERR)
 | |
|   {
 | |
|     _trmov->put(RMV_GRUPPO,      g);
 | |
|     _trmov->put(RMV_CONTO,       c);
 | |
|     _trmov->put(RMV_SOTTOCONTO,  s);
 | |
|     _trmov->put(RMV_SEZIONE,     sez);
 | |
|     _trmov->put(RMV_DESCR,       desc);
 | |
|     _trmov->put(RMV_GRUPPOC,     gc);
 | |
|     _trmov->put(RMV_CONTOC,      cc);
 | |
|     _trmov->put(RMV_SOTTOCONTOC, sc);
 | |
|     _trmov->put(RMV_IMPORTO,     imp);     
 | |
|     
 | |
|     _trmov->rewrite();
 | |
|   }
 | |
| }
 | |
| 
 | |
| void TVar_mov::registra_IVA(TMask& m)
 | |
| {     
 | |
|   TString ocfpi;
 | |
|   
 | |
|   if (!_righe)
 | |
|   {
 | |
|     long    numreg    = m.get_long(F_NUMREG);
 | |
|     TDate   data74ter  (m.get(F_DATA74TER));
 | |
|     long    codcf     = m.get_long(F_CODCF);
 | |
| 
 | |
| /*****************************************************
 | |
|  *****            CLIENTI OCCASIONALI            *****
 | |
|  *****************************************************/
 | |
|       
 | |
|     TString ragsococc = m.get     (F_RAGSOCOCC);
 | |
|     TString indocc    = m.get     (F_INDOCC);
 | |
|     TString civocc    = m.get     (F_CIVOCC);
 | |
|     TString localita  = m.get     (F_LOCALITA);
 | |
|     TString capocc    = m.get     (F_CAPOCC);  
 | |
|     TString comocc    = m.get     (F_COMOCC);
 | |
|     
 | |
|     TString com;
 | |
|     
 | |
|     if (ragsococc.not_empty())
 | |
|     {
 | |
|       ocfpi     = m.get     (F_CFPI);    
 | |
|       
 | |
|       // Se il cliente occasionale non esisteva su questo movimento e da maschera l'ho
 | |
|       // aggiunto devo determinare con quale codice memorizzarlo sul file dove non esiste
 | |
|       // Sara' il successivo all'ultimo esistente sul file.
 | |
|       
 | |
|       if (ocfpi.empty())                     
 | |
|       { 
 | |
|         TString app;
 | |
|         long    progr;
 | |
|         
 | |
|         _toccas->last();
 | |
|         ocfpi = _toccas->get(OCC_CFPI);
 | |
|         app = ocfpi.mid(0,3);
 | |
|         if (app == "RIC")
 | |
|           progr = atol(ocfpi.mid(3,6));
 | |
|         else
 | |
|           progr = 0;
 | |
|           
 | |
|         progr++;
 | |
|         ocfpi = format("%3s%6d", (const char*) "RIC", progr);  
 | |
|       }
 | |
|       
 | |
|       // Se invece gia' esisteva sul movimento il campo della maschera nascosto contiene gia'
 | |
|       // il valore e mi basta fare una rewrite().
 | |
|       
 | |
|       _toccas->setkey(1);
 | |
|       _toccas->zero();
 | |
|       _toccas->put(OCC_CFPI, ocfpi);
 | |
|       if (_toccas->read() == NOERR)
 | |
|       {
 | |
|         _toccas->put(OCC_RAGSOC, ragsococc);
 | |
|         _toccas->put(OCC_INDIR,  indocc);
 | |
|         _toccas->put(OCC_CIV,    civocc);
 | |
|         _toccas->put(OCC_COM,    comocc);
 | |
|         _toccas->put(OCC_CAP,    capocc);
 | |
|                           
 | |
|         _toccas->rewrite();
 | |
|       }
 | |
|       else
 | |
|       {                 
 | |
|         _toccas->put(OCC_CFPI,   ocfpi);
 | |
|         _toccas->put(OCC_RAGSOC, ragsococc);
 | |
|         _toccas->put(OCC_INDIR,  indocc);
 | |
|         _toccas->put(OCC_CIV,    civocc);
 | |
|         _toccas->put(OCC_COM,    comocc);
 | |
|         _toccas->put(OCC_CAP,    capocc);
 | |
|         
 | |
|         _toccas->write();      
 | |
|       }
 | |
|     }
 | |
|     else
 | |
|     { 
 | |
|       // Se esisteva e lo voglio cancellare devo toglierlo fisicamente dal file
 | |
|       
 | |
|       ocfpi     = m.get     (F_CFPI);    
 | |
|       
 | |
|       if (ocfpi.not_empty())
 | |
|       {
 | |
|         _toccas->setkey(1);
 | |
|         _toccas->zero();
 | |
|         _toccas->put(OCC_CFPI, ocfpi);
 | |
|         if (_toccas->read() == NOERR)
 | |
|         {
 | |
|           _toccas->remove();
 | |
|           ocfpi = "";
 | |
|         }
 | |
|       }
 | |
|     }
 | |
| /*****************************************************/    
 | |
| 
 | |
|     _tmov->setkey(1);
 | |
|     _tmov->zero();
 | |
|     _tmov->put(MOV_NUMREG, numreg);
 | |
|     if (_tmov->read() == NOERR)
 | |
|     {
 | |
|       _tmov->put(MOV_DATA74TER, data74ter);
 | |
|       _tmov->put(MOV_CODCF,     codcf);
 | |
|       _tmov->put(MOV_OCFPI,     ocfpi);
 | |
|       
 | |
|       _tmov->rewrite();
 | |
|     }
 | |
|   }
 | |
|   else
 | |
|     if (_righe)
 | |
|     {                                    
 | |
|       long    numreg    = m.get_long(F_NUMREG);
 | |
|       int     numrig    = m.get_int (F_NUMRIG);
 | |
|       real    imponibile (m.get     (F_IMPONIBILE));
 | |
|       TString codiva    = m.get     (F_CODIVA);      
 | |
|       real    imposta    (m.get     (F_IMPOSTA));
 | |
|       int     tipodet   = m.get_int (F_TIPODET);
 | |
|       int     tipocr    = m.get_int (F_TIPOCR);
 | |
|       int     gruppo    = m.get_int (F_GRUPPO);
 | |
|       int     conto     = m.get_int (F_CONTO);
 | |
|       long    sottoc    = m.get_long(F_SOTTOCONTO);
 | |
|       
 | |
|       registra_file_temp_riva(numreg,numrig,imponibile,codiva,imposta,tipodet,tipocr,gruppo,conto,sottoc);
 | |
|     }
 | |
| }
 | |
| 
 | |
| void TVar_mov::registra_file_temp_riva(long nr,int nri,const real& imp,const TString& civa,const real& imposta,
 | |
|                                        int tdet,int tcr,int g,int c,long s)
 | |
| {
 | |
|   _tiva->setkey(1);
 | |
|   _tiva->zero();
 | |
|   _tiva->put(RMI_NUMREG, nr);
 | |
|   _tiva->put(RMI_NUMRIG, nri);  
 | |
|   if (_tiva->read() == NOERR)
 | |
|   {
 | |
|     _tiva->put(RMI_IMPONIBILE, imp);
 | |
|     _tiva->put(RMI_CODIVA,     civa);
 | |
|     _tiva->put(RMI_IMPOSTA,    imposta);
 | |
|     _tiva->put(RMI_TIPODET,    tdet);
 | |
|     _tiva->put(RMI_TIPOCR,     tcr);
 | |
|     _tiva->put(RMI_GRUPPO,     g);
 | |
|     _tiva->put(RMI_CONTO,      c);
 | |
|     _tiva->put(RMI_SOTTOCONTO, s);
 | |
|     
 | |
|     _tiva->rewrite();
 | |
|   }
 | |
| }                                       
 | |
| 
 | |
| bool TVar_mov::leggi_trasfer()
 | |
| { 
 | |
|   _trasf = _tras_file.path(_dittaric);
 | |
|   _trasf << HEADER;
 | |
|   
 | |
|   _tras_file.open(_trasf);
 | |
|   
 | |
|   if (_tras_file.exist())
 | |
|   {  
 | |
|     if (_tras_file.read_control_rec())
 | |
|       _control_rec = _tras_file.record();
 | |
|     else
 | |
|       return error_box("Rilevati gravi errori negli archivi:procedura interrotta");
 | |
|   } 
 | |
|   else
 | |
|     return error_box("Al momento non presenti trasferimenti attivi sulla ditta selezionata");
 | |
|   
 | |
|   return TRUE; 
 | |
| }
 | |
| 
 | |
| bool TVar_mov::esegui_controlli()
 | |
| {                    
 | |
|   TConfig conf(CONFIG_DITTA);           
 | |
|   
 | |
|   _std = conf.get("FlStTra");
 | |
| 
 | |
|   if (!prefix().exist(_dittaric))
 | |
|     return error_box("Rilevati gravi errori negli archivi: procedura interrotta");
 | |
|   
 | |
|   if (!leggi_trasfer())
 | |
|     return FALSE;
 | |
| 
 | |
|   if (!controlli())
 | |
|     return FALSE;     
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| void TVar_mov::setta_parametri_record(const TString& sigla,const TString& flag)
 | |
| { 
 | |
|   TConfig conf (CONFIG_DITTA);
 | |
|   
 | |
|   conf.set("FlStTra", flag);
 | |
|   
 | |
|   leggi_record_controllo();
 | |
|   _control_rec.overwrite(sigla,240);
 | |
|   
 | |
|   const int size = 1024;
 | |
|   
 | |
|   _tras_file.write_control_rec(_control_rec, size);
 | |
| }
 | |
| 
 | |
| bool TVar_mov::controlli()
 | |
| { 
 | |
|   TString16 chiave,sigla;
 | |
|   
 | |
|   chiave = _control_rec.sub(241,256);
 | |
|   chiave.trim();        
 | |
|   sigla  = _control_rec.sub(240,241);
 | |
|   sigla.trim();
 | |
| 
 | |
|   if (_std == "M" && sigla == "Z" && chiave != "")
 | |
|     return error_box("Variazione NON POSSIBILE: trasferimento movimenti gia' iniziato");           
 | |
|   
 | |
|   if (_std == "M" && sigla == "U")
 | |
|     return error_box("Variazione NON POSSIBILE: trasferimento movimenti gia' iniziato");           
 | |
| 
 | |
|   if (_std == "*") 
 | |
|   {
 | |
|     warning_box("Trasferimento interamente completato: proseguire per cancellare il file");    
 | |
|     _tras_file.remove_all();
 | |
|     setta_parametri_record(" "," ");
 | |
|     return FALSE;
 | |
|   }
 | |
| 
 | |
|   if (_std == "T")
 | |
|     return error_box("Variazione NON POSSIBILE: eseguire prima la ricezione delle tabelle");           
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TVar_mov::menu(MENU_TAG m)
 | |
| {
 | |
|   if (m == BAR_ITEM(1))
 | |
|     return main_loop(); 
 | |
|   return FALSE;
 | |
| }
 | |
| 
 | |
| int cg6800 (int argc, char* argv[])
 | |
| {                                
 | |
|   switch (*argv[2])
 | |
|   {
 | |
|     case 'P':
 | |
|     {
 | |
|       TVar_mov* main_app = new TVar_mov(*argv[2]);       
 | |
|       main_app->run(argc, argv,main_app->_titolo);
 | |
|       delete main_app;
 | |
|     }
 | |
|     break;
 | |
|     case 'I':
 | |
|     {
 | |
|       TVar_mov* main_app = new TVar_mov(*argv[2]);       
 | |
|       main_app->run(argc, argv,main_app->_titolo);
 | |
|       delete main_app;
 | |
|     }
 | |
|     break;
 | |
|     case 'B':
 | |
|     {   
 | |
|       TVar_sc* a = new TVar_sc;       
 | |
|       a->run(argc, argv,"Variazione movimenti Saldaconto");
 | |
|       delete a;
 | |
|     }
 | |
|     break;
 | |
|     case 'S':
 | |
|     {   
 | |
|       TDitta_ric* a = new TDitta_ric;       
 | |
|       a->run(argc, argv,"Scelta ditta per ricezione");
 | |
|       delete a;
 | |
|     }
 | |
|     break;
 | |
|     case 'A':
 | |
|     {   
 | |
|       TAnn_mov* a = new TAnn_mov;       
 | |
|       a->run(argc, argv,"Annullamento movimenti da ricevere");
 | |
|       delete a;
 | |
|     }
 | |
|     break;
 | |
|     case 'V':
 | |
|     {   
 | |
|       TVis_ric* a = new TVis_ric;       
 | |
|       a->run(argc, argv,"Visualizzazione stato ricezione");
 | |
|       delete a;
 | |
|     }
 | |
|     break;    
 | |
|     default:
 | |
|     break;
 | |
|   }
 | |
| //main_app.run(argc, argv,main_app._titolo);
 | |
|   return TRUE;
 | |
| }
 |