spostamento prematuro tabelle LIA e PLA by Guido Il commit si inquadra in una visione pluralista della programmazione illuminata da un concetto nel quale tutte le forze in campo sono chiamate a dare un contributo in un'ottica autenticamente collaborativa e caratterizzata dalla massima trasparenza dell'operato. git-svn-id: svn://10.65.10.50/trunk@994 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			366 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			366 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| // cg5300.cpp
 | |
| // modifica parametri contabilita' relativi alla liquidazione
 | |
| 
 | |
| #include <config.h>
 | |
| #include <msksheet.h>
 | |
| #include <relapp.h>
 | |
| #include <tabutil.h>
 | |
| #include <urldefid.h>
 | |
| #include <utility.h>   
 | |
| 
 | |
| #include "cg5.h"
 | |
| #include "cg5300a.h"
 | |
| 
 | |
| #include <attiv.h>
 | |
| #include <nditte.h>
 | |
|                                 
 | |
| #define TAB_LIA "%LIA"                                
 | |
| #define TAB_PLA "%PLA"                                
 | |
|                                 
 | |
| class TParaliq_app : public TRelation_application
 | |
| { 
 | |
|   TRelation *       _rel;
 | |
|   TMask *           _msk;
 | |
|   TLocalisamfile *  _attiv;
 | |
|   TLocalisamfile *  _ditte;
 | |
|   int               _yearliq;
 | |
|   TTable *          _pla;
 | |
|   TString_array     _atts;  // array di stringhe con i codici attivita'
 | |
|   TString_array     _tips;  // array di stringhe con i tipi attivita'
 | |
|   long              _lastditta;
 | |
|   TString16         _freqiva;
 | |
| 
 | |
|   void              check_registers(int year);
 | |
| 
 | |
| protected:
 | |
| 
 | |
|   virtual bool         user_create();
 | |
|   virtual bool         user_destroy();
 | |
|   
 | |
|   // minchia di cristo
 | |
|   virtual TRelation*   get_relation() const    { return _rel;  }
 | |
|   virtual TMask*       get_mask(int mode)      { return _msk;  }
 | |
|   virtual bool         changing_mask(int mode) { return FALSE; }
 | |
| 
 | |
|   // file intertface
 | |
|   virtual bool         remove()                    { return TRUE;  }
 | |
|   virtual bool         protected_record(TRectype&) { return TRUE;  }
 | |
|   virtual void         init_query_mode(TMask&);
 | |
|   virtual void         init_insert_mode(TMask& m);
 | |
|   virtual int          rewrite(const TMask& m);
 | |
|   // non si possono aggiungere record, se non ci sono vengono
 | |
|   // creati automaticamente
 | |
|   virtual int          write(const TMask& m) { return rewrite(m);}
 | |
|   virtual int          read(TMask& m);  
 | |
| 
 | |
|   void                 init_array(TMask& m);
 | |
|                      
 | |
|   // notifier
 | |
|   static bool          sheet_action(int r, KEY k);
 | |
|   
 | |
| public:
 | |
|   
 | |
|   TParaliq_app() { _lastditta = 0L;}
 | |
|   virtual ~TParaliq_app() {}	
 | |
| };
 | |
|                                       
 | |
| 
 | |
| void TParaliq_app::check_registers(int year)
 | |
| {
 | |
| 	// controlla che per ogni data attivita' esistano almeno un registro
 | |
| 	// acquisti, vendite e giornale; warning appropriato in caso negativo 
 | |
| 	TTable reg("REG");
 | |
| 	TRecfield reg_year(reg.curr(), "CODTAB", 0,3);
 | |
| 	
 | |
| 	const byte R_ACQ = 0x01;
 | |
| 	const byte R_VEN = 0x02;
 | |
| 	const byte R_ALL = R_ACQ | R_VEN;
 | |
| 
 | |
| 	bool is_giornale = FALSE;       
 | |
|   byte flags = 0x00;      
 | |
| 
 | |
| 	for (int i = 0; i < _atts.items(); i++)
 | |
| 	{
 | |
| 	  TString& att = (TString&)_atts[i];
 | |
| 	  for (reg.first(); !reg.eof(); reg.next())
 | |
| 	  {	   
 | |
| 	   	 if (atoi(reg_year) == year && reg.get_int("I0") == 5) 
 | |
| 	   	 {
 | |
| 	   	 	is_giornale = TRUE;
 | |
| 	   	    continue;
 | |
| 	   	 }
 | |
| 		 if (atoi(reg_year) != year || att != reg.get("S8")) 
 | |
| 		   	continue;
 | |
| 				
 | |
| 		 switch (reg.get_int("I0"))
 | |
| 		 {
 | |
| 			case 1:    // vendite 
 | |
| 				flags |= R_VEN;
 | |
| 				break;
 | |
| 			case 2:    // acquisti
 | |
| 				flags |= R_ACQ;
 | |
| 				break;
 | |
| 		 }
 | |
| 		 if (flags ==  R_ALL && is_giornale) break;
 | |
|       } 
 | |
|       if (flags < R_ALL)
 | |
|       {      
 | |
| 		 TString wrn("I seguenti registri non esistono per l'attivita' "); 
 | |
|          wrn << att << "(" << year << "):";
 | |
|          if ((flags & R_VEN) == 0x00) wrn << "\n\tregistro vendite";
 | |
|          if ((flags & R_ACQ) == 0x00) wrn << "\n\tregistro acquisti";
 | |
|          warning_box(wrn);
 | |
|        }
 | |
|     } 
 | |
| 
 | |
|     // libro giornale non si controlla per attivita'
 | |
|     if(!is_giornale)
 | |
|       warning_box("Non esiste probabilmente nessun "
 | |
|       	          "libro giornale per l'anno %d", year);
 | |
| }                                      
 | |
|                                            
 | |
| 
 | |
| void TParaliq_app::init_array(TMask& m)
 | |
| {     
 | |
|   const long newditta = m.get_long(F_CODDITTA);
 | |
| 
 | |
|   if (newditta != _lastditta)
 | |
|   {
 | |
|     _lastditta = newditta;
 | |
|     _atts.destroy(); 
 | |
|     _tips.destroy();
 | |
|     
 | |
|     _attiv->zero();
 | |
|     _attiv->put(ATT_CODDITTA, newditta);
 | |
|     TRectype r(_attiv->curr());
 | |
| 
 | |
|     for(_attiv->read(_isgteq); 
 | |
|         _attiv->status() == NOERR && _attiv->curr() == r; 
 | |
| 	      _attiv->next())
 | |
|     {
 | |
|       // istanzia array _atts on le attivita' della ditta corrente
 | |
|       _atts.add(_attiv->get(ATT_CODATT));
 | |
|       _tips.add(_attiv->get(ATT_TIPOATT));
 | |
|     }
 | |
|     _ditte->put(NDT_CODDITTA, _lastditta);
 | |
|     if (_ditte->read() == NOERR)
 | |
|       _freqiva = _ditte->get(NDT_FREQVIVA);
 | |
|     else
 | |
|       _freqiva = "";
 | |
|   }                                
 | |
| }
 | |
| 
 | |
| bool TParaliq_app::user_create()
 | |
| {
 | |
|   TConfig d(CONFIG_DITTA);
 | |
|   
 | |
|   _yearliq = (int)d.get_long("AnLiIv");
 | |
|   _rel     = new TRelation(TAB_LIA);
 | |
|   _pla     = new TTable(TAB_PLA);
 | |
|   _attiv   = new TLocalisamfile(LF_ATTIV);
 | |
|   _ditte   = new TLocalisamfile(LF_NDITTE);
 | |
|   _msk     = new TMask("cg5300a");
 | |
|   
 | |
|   ((TSheet_field&)_msk->field(F_SHEET_PLA)).set_notify(sheet_action);
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TParaliq_app::user_destroy()  
 | |
| {               
 | |
|   delete _rel;
 | |
|   delete _attiv;
 | |
|   delete _ditte;
 | |
|   delete _msk;
 | |
|   delete _pla;
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TParaliq_app::sheet_action(int r, KEY k)  
 | |
| {                    
 | |
|   // non si possono cancellare o aggiungere righe in PLA
 | |
|   return (k != K_DEL && k != K_INS);
 | |
| }
 | |
| 
 | |
| void  TParaliq_app::init_query_mode(TMask& m)
 | |
| {
 | |
|   // svuota tutto
 | |
|   TSheet_field& sh = (TSheet_field&)m.field(F_SHEET_PLA);
 | |
|   sh.reset();
 | |
| }
 | |
| 
 | |
| void  TParaliq_app::init_insert_mode(TMask& m)
 | |
| {
 | |
|   TSheet_field& sf = (TSheet_field&)m.field(F_SHEET_PLA);
 | |
|   TToken_string tt(60);
 | |
|                              
 | |
|   init_array(m);
 | |
|                              
 | |
|   m.set(F_FREQ_VERS, _freqiva);
 | |
| 
 | |
|   for (int i = 0; i < _atts.items(); i++)
 | |
|   {
 | |
|     TString& att  = _atts.row(i);
 | |
|     TString& tips = _tips.row(i);
 | |
| 
 | |
|     // cerca l'attivita' in pla   
 | |
|     tt = "";    
 | |
|     tt.add(att);
 | |
|     tt.add(tips);
 | |
|     tt.add("");
 | |
|     tt.add("");
 | |
|     tt.add("");
 | |
|     tt.add("");
 | |
|     sf.row(-1) = tt;
 | |
|   }
 | |
| }
 | |
|                                     
 | |
| int TParaliq_app::rewrite(const TMask& m)
 | |
| {                  
 | |
|   // scrive %LIA
 | |
|   // scrive tutte le righe di %PLA a partire dalle righe sheet  
 | |
|   static int oldyear;
 | |
|   
 | |
|   TSheet_field& sf = (TSheet_field&)m.field(F_SHEET_PLA);
 | |
|   const long firm = m.get_long(F_CODDITTA);
 | |
|   const int year = m.get_int(F_YEAR);
 | |
|   
 | |
|   int err = NOERR;
 | |
| 	bool was = FALSE;
 | |
|   
 | |
|   for (int i = 0; err == NOERR && i < _atts.items(); i++)
 | |
|   {                      
 | |
|     TToken_string&  tt = sf.row(i);
 | |
|     const TString&  att = (TString&) _atts[i];
 | |
|     const TString16 tips(tt.get(1));
 | |
|     const TString16 codtab(format("%05ld%4d%s1", firm, year, (const char *)att));
 | |
|     
 | |
|     _pla->zero();
 | |
|     _pla->put("CODTAB", codtab);
 | |
|      was =_pla->read() == NOERR; 
 | |
|      if (!was) _pla->zero();
 | |
|      
 | |
|      real prorata = _pla->get_real("R8");
 | |
|      real es_a8   = _pla->get_real("R5");
 | |
|      real es_a8b  = _pla->get_real("R6");
 | |
|      real es_a9   = _pla->get_real("R7");
 | |
|     
 | |
|     _pla->put("CODTAB", codtab);
 | |
|     // scrive i campi (vedi a read() per i nomi) 
 | |
|     // in base alla riga sheet	
 | |
|     _pla->put("S7", tips);         // tipo attivita'
 | |
|     _pla->put("R8", tt.get());     // prorata
 | |
|     _pla->put("R5", tt.get());     // plafond art. 8
 | |
|     _pla->put("R6", tt.get());     // plafond art. 8bis
 | |
|     _pla->put("R7", tt.get());     // plafond art. 9
 | |
|     
 | |
|     err = (was ? _pla->rewrite() : _pla->write());  
 | |
|     
 | |
|     // se si e' cambiato qualcosa..
 | |
|     if (prorata != _pla->get_real("R8") ||
 | |
|      	es_a8   != _pla->get_real("R5") ||
 | |
|      	es_a8b  != _pla->get_real("R6") ||
 | |
|      	es_a9   != _pla->get_real("R7") ||
 | |
|      	m.field(F_CRED_PREC).dirty())
 | |
|     {
 | |
|      	// invalida la prima liquidazione calcolata se ce n'e'
 | |
|      	TTable lim("LIM");
 | |
| 
 | |
| 	    TRecfield lim_anno(lim.curr(),"CODTAB",0,3);
 | |
| 
 | |
|      	for (lim.first(); !lim.eof(); lim.next())
 | |
|      	{
 | |
|      		if (year == atoi(lim_anno))
 | |
|      		{
 | |
|      			lim.put("B0","");
 | |
|      			lim.rewrite();
 | |
|      			break;
 | |
|      		}
 | |
|      	}
 | |
|     }
 | |
|   }
 | |
|   
 | |
|   TTable& lia = (TTable&)_rel->lfile();
 | |
|   lia.put("CODTAB", format("%05ld%d", firm, year));
 | |
|   was = lia.read() == NOERR;
 | |
|   if (!was) lia.zero();
 | |
|   m.autosave(_rel);
 | |
|   if (err == NOERR) err = (was ? lia.rewrite() : lia.write());
 | |
|   if (err == NOERR && year == _yearliq) 
 | |
|   {
 | |
|     _ditte->put(NDT_CODDITTA, _lastditta);
 | |
|     if (_ditte->read() == NOERR)
 | |
|     {
 | |
|       _ditte->put(NDT_FREQVIVA, m.get(F_FREQ_VERS));
 | |
|       _ditte->rewrite();
 | |
|     }
 | |
|   }              
 | |
|                
 | |
|   // per ogni anno liquidazione controlla (una volta) l'esistenza
 | |
|   // dei registri fondamentali
 | |
|   if (year != oldyear && err == NOERR)
 | |
|   	 check_registers(year);
 | |
|   oldyear = year;
 | |
|   
 | |
|   return err;
 | |
| }
 | |
| 
 | |
| int   TParaliq_app::read(TMask& m)
 | |
| {
 | |
|   // legge da LIA (si istanziano i campi credito prec. e Freq. Vers
 | |
|   // prende le attivita' una per una da _atts e 
 | |
|   // crea le righe sheet
 | |
|   m.autoload(get_relation()); 
 | |
|   TSheet_field& sf = (TSheet_field&)m.field(F_SHEET_PLA);
 | |
|   TToken_string tt(60);
 | |
|   const long firm = m.get_long(F_CODDITTA);
 | |
|   const int year  = m.get_int(F_YEAR);
 | |
|   
 | |
|   sf.reset();
 | |
|   const TString16 ctab = format("%05ld%d", firm, year);
 | |
|   _pla->zero();
 | |
|   _pla->put("CODTAB", ctab);
 | |
|   
 | |
|   for (int err = _pla->read(_isgteq); err == NOERR; _pla->next())
 | |
|   {
 | |
|     if (ctab == _pla->get("CODTAB").left(9))
 | |
|     {
 | |
|       tt = "";    
 | |
|       tt.add(ctab.mid(9,5));
 | |
|       tt.add(_pla->get("S7"));          // tipo attivita'
 | |
|       tt.add(_pla->get("R8"));          // prorata
 | |
|       tt.add(_pla->get("R5"));          // plafond art. 8
 | |
|       tt.add(_pla->get("R6"));          // plafond art. 8bis
 | |
|       tt.add(_pla->get("R7"));          // plafond art. 9
 | |
|     }
 | |
|     else break;
 | |
|     sf.row(-1) = tt;
 | |
|   }
 | |
|   
 | |
|   return NOERR;
 | |
| }
 | |
| 
 | |
| 
 | |
| int cg5300(int argc, char* argv[])
 | |
| {
 | |
|   TParaliq_app a;
 | |
|   a.run(argc, argv, "Parametri liquidazione");
 | |
|   return 0;
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|                     
 |