Files correlati : ce1.exe ce2.exe Ricompilazione Demo : [ ] Commento : Corretta funzione amminit_get_real, che inspiegabilmente chiamava se stessa, blocando tutto. git-svn-id: svn://10.65.10.50/trunk@12277 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			476 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			476 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <automask.h>
 | ||
| #include <recarray.h>
 | ||
| #include <relapp.h>
 | ||
| #include <defmask.h>
 | ||
| 
 | ||
| #include "celib.h"
 | ||
| #include "ce1400a.h"
 | ||
| 
 | ||
| #include "catdi.h"
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // Applicazione principale
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| class TScelta_amm_cat : public TRelation_application
 | ||
| {         
 | ||
|   TRelation* _rel;
 | ||
|   TAutomask* _msk[4];
 | ||
|   int _tipo;
 | ||
| 
 | ||
| protected:
 | ||
|   virtual bool user_create();
 | ||
|   virtual bool user_destroy();
 | ||
|   virtual TRelation* get_relation() const { return _rel; }
 | ||
|   virtual bool changing_mask(int) { return TRUE; }
 | ||
|   virtual TMask* get_mask(int mode);
 | ||
|   virtual bool protected_record(TRelation& rel);
 | ||
|   
 | ||
|   void init_mask(TMask& m);
 | ||
|   virtual void init_query_mode(TMask& m);
 | ||
|   virtual void init_query_insert_mode(TMask& m);
 | ||
|   virtual void init_insert_mode(TMask& m);
 | ||
|   virtual void init_modify_mode(TMask& m);
 | ||
| 
 | ||
| public:
 | ||
|   void set_tipo_beni(int t)  { _tipo = t; }
 | ||
| };
 | ||
| 
 | ||
| inline TScelta_amm_cat& app() { return (TScelta_amm_cat&)main_app(); }
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // Maschera di query
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| class TSac_mask : public TAutomask
 | ||
| {      
 | ||
| protected:
 | ||
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | ||
| 
 | ||
| public:  
 | ||
|   TSac_mask() : TAutomask("ce1400a") { }
 | ||
| };
 | ||
| 
 | ||
| bool TSac_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | ||
| {
 | ||
|   switch (o.dlg())
 | ||
|   {
 | ||
|   case F_ESERCIZIO:
 | ||
|   case F_GRUPPO:
 | ||
|   case F_SPECIE:
 | ||
|     if (e == fe_init || e == fe_modify)
 | ||
|     {                                    
 | ||
|       const int ese = get_int(F_ESERCIZIO);
 | ||
|       const int gru = get_int(F_GRUPPO);
 | ||
|       const char* spe = get(F_SPECIE);
 | ||
|       TString16 str;  
 | ||
|       str.format("%04d%02d%-4s", ese, gru, spe);
 | ||
|       const TRectype& curr_ccb = cache().get("CCB", str);
 | ||
|       const bool can_create = !curr_ccb.get_bool("B1"); // Bollato stampato
 | ||
|       enable(DLG_NEWREC, can_create);
 | ||
|       enable(DLG_DELREC, can_create);
 | ||
|    }
 | ||
|    break;
 | ||
|   case F_CATEGORIA:
 | ||
|   case F_DESC_CAT:
 | ||
|     {
 | ||
|       TDitta_cespiti& dc = ditta_cespiti();
 | ||
|       bool ok = dc.on_category_event(o, e, jolly);
 | ||
|       if (ok)
 | ||
|         set(F_CATEGORIA2, get(F_CATEGORIA));
 | ||
|       else
 | ||
|         return FALSE;
 | ||
|     }
 | ||
|   case F_CATEGORIA2:
 | ||
|   case F_DESC_CAT2:
 | ||
|     if (e == fe_modify || e == fe_close)
 | ||
|     {               
 | ||
|       TDitta_cespiti& dc = ditta_cespiti();
 | ||
|       const int gr = get_int(F_GRUPPO);
 | ||
|       const char* sp = get(F_SPECIE);
 | ||
|       const int ca = get_int(F_CATEGORIA2);
 | ||
|       const TRectype& cac = dc.categoria(gr, sp, ca);  
 | ||
|       bool ok = !cac.empty();
 | ||
|       if (ok && (o.dlg() == F_CATEGORIA || o.dlg() == F_CATEGORIA2))
 | ||
|       {
 | ||
|         set(o.dlg() == F_CATEGORIA ? F_DESC_CAT : F_DESC_CAT2, cac.get("S0"));
 | ||
|       
 | ||
|         if (cac.get_bool("B0"))
 | ||
|           return error_box(TR("Categoria non ammortizzabile"));
 | ||
|           
 | ||
|         const int tb = cac.get_int("I0");
 | ||
|         app().set_tipo_beni(tb);
 | ||
|         switch (tb)
 | ||
|         {
 | ||
|         case 1:  // Beni immateriali            
 | ||
|           {
 | ||
|             const bool amm_per_anni = cac.get_int("I1") <= 1;
 | ||
|             if (amm_per_anni)
 | ||
|               return error_box(TR("La categoria prevede un ammortamento per anni:\n"
 | ||
|                                "Effettuare le scelte sul cespite"));
 | ||
|           }
 | ||
|           break;
 | ||
|         case 2:  // Costi pluriennali
 | ||
|           {
 | ||
|             const int vincolo = cac.get_int("I2");
 | ||
|             if (vincolo == 3)  // Quote
 | ||
|               return error_box(TR("La categoria prevede un ammortamento per quote costanti:\n"
 | ||
|                                "Effettuare le scelte sul cespite"));
 | ||
|           }
 | ||
|           break;
 | ||
|         default:
 | ||
|           break;  
 | ||
|         }
 | ||
|       }
 | ||
|       if (!ok && !o.empty() && o.dlg() == F_CATEGORIA2)
 | ||
|         return error_box(TR("E' neccessario specificare una categoria valida"));
 | ||
|       if (ok && e == fe_button && o.dlg() == F_CATEGORIA)
 | ||
|         send_key(K_ENTER, 0);
 | ||
|     }
 | ||
|     break;
 | ||
|   default:
 | ||
|     break;  
 | ||
|   }
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // Maschera di beni materiali
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| class TMat_mask : public TAutomask
 | ||
| {      
 | ||
| protected:
 | ||
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | ||
| 
 | ||
|   bool test_min(short quota, short minimo) const;
 | ||
|   bool test_max(short nor, short ant, short acc) const;
 | ||
|   bool test_rit(short quota, short minimo) const;
 | ||
|   bool is_max(short quota, short massimo) const;
 | ||
| 
 | ||
| public:  
 | ||
|   TMat_mask() : TAutomask("ce1400b") { }
 | ||
| };
 | ||
| 
 | ||
| bool TMat_mask::test_min(short quota, short minimo) const
 | ||
| {
 | ||
|   bool warning = FALSE;
 | ||
|   const bool ammrit = get_bool(F_AMMRIT);
 | ||
|   if (!ammrit)
 | ||
|   {
 | ||
|     const real perq(get(quota));
 | ||
|     const real minq(get(minimo));
 | ||
|     warning = perq < minq;
 | ||
|   }
 | ||
|   return warning;
 | ||
| }
 | ||
| 
 | ||
| bool TMat_mask::test_rit(short quota, short minimo) const
 | ||
| {
 | ||
|   bool warning = FALSE;
 | ||
|   const bool ammrit = get_bool(F_AMMRIT);
 | ||
|   if (ammrit)
 | ||
|   {
 | ||
|     const real perq(get(quota));
 | ||
|     const real minq(get(minimo));
 | ||
|     warning = perq >= minq;
 | ||
|   }
 | ||
|   return warning;
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| bool TMat_mask::test_max(short nor, short ant, short acc) const
 | ||
| {
 | ||
|   real tot;
 | ||
|   tot += get_real(nor);
 | ||
|   tot += get_real(ant);
 | ||
|   tot += get_real(acc);
 | ||
|   return tot > 100.0;
 | ||
| }
 | ||
| 
 | ||
| bool TMat_mask::is_max(short quota, short massima) const
 | ||
| {
 | ||
|   const real perq(get(quota));
 | ||
|   const real maxq(get(massima));
 | ||
|   return perq >= maxq;
 | ||
| }
 | ||
| 
 | ||
| bool TMat_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | ||
| {
 | ||
|   switch (o.dlg())
 | ||
|   {
 | ||
|   case F_CATEGORIA:
 | ||
|     {
 | ||
|       TDitta_cespiti& dc = ditta_cespiti();
 | ||
|       dc.on_category_event(o, e, jolly);
 | ||
|     }
 | ||
|     break;
 | ||
|   case F_NORFIS_87:
 | ||
|     if (e == fe_modify || e == fe_close)
 | ||
|     {
 | ||
|       if (test_min(F_NORFIS_87, F_MIN_87))
 | ||
|         warning_box(TR("L'ammortamento normale <20> inferiore al minimo della tabella ministeriale:\n"
 | ||
|                     "Se non si seleziona l'ammortamento ritardato verrano generate delle quote perse"));
 | ||
|       if (test_max(F_NORFIS_87, F_ANTFIS_87, F_ACCFIS))
 | ||
|         return error_box(TR("Il totale delle percentuali di ammortamento supera il 100%"));
 | ||
|       if (test_rit(F_NORFIS_87, F_MIN_87))
 | ||
|         return error_box(TR("In caso di ammortamento ritardato si deve specificare una quota inferiore al minimo ministeriale"));
 | ||
|     }
 | ||
|     break;
 | ||
|   case F_NORFIS_88:
 | ||
|     if (e == fe_modify || e == fe_close)
 | ||
|     {
 | ||
|       if (test_min(F_NORFIS_88, F_MIN_88))
 | ||
|         warning_box(TR("L'ammortamento normale <20> inferiore al minimo della tabella ministeriale:\n"
 | ||
|                     "Se non si seleziona l'ammortamento ritardato verrano generate delle quote perse"));
 | ||
|       if (test_max(F_NORFIS_88, F_ANTFIS_88, F_ACCFIS))
 | ||
|         return error_box(TR("Il totale delle percentuali di ammortamento supera il 100%"));
 | ||
|       if (test_rit(F_NORFIS_88, F_MIN_88))
 | ||
|         return error_box(TR("In caso di ammortamento ritardato si deve specificare una quota inferiore al minimo ministeriale"));
 | ||
|     }
 | ||
|     break;  
 | ||
|   case F_NORFIS_89:
 | ||
|     if (e == fe_modify || e == fe_close)
 | ||
|     {
 | ||
|       if (test_min(F_NORFIS_89, F_MIN_89))
 | ||
|         warning_box(TR("L'ammortamento normale <20> inferiore al minimo della tabella ministeriale:\n"
 | ||
|                     "Se non si seleziona l'ammortamento ritardato verrano generate delle quote perse"));
 | ||
|       if (test_max(F_NORFIS_89, F_ANTFIS_89, F_ACCFIS))
 | ||
|         return error_box(TR("Il totale delle percentuali di ammortamento supera il 100%"));
 | ||
|       if (test_rit(F_NORFIS_89, F_MIN_89))
 | ||
|         return error_box(TR("In caso di ammortamento ritardato si deve specificare una quota inferiore al minimo ministeriale"));
 | ||
|     }
 | ||
|     break;  
 | ||
|   case F_ANTFIS_87:
 | ||
|     if (e == fe_modify || e == fe_close)
 | ||
|     {
 | ||
|       if (!o.empty() && !is_max(F_NORFIS_87, F_MAX_87))
 | ||
|         return error_box(TR("E' necessario completare l'ammortamento normale prima di calcolare quello anticipato"));
 | ||
|     }
 | ||
|     break;
 | ||
|   case F_ANTFIS_88:
 | ||
|     if (e == fe_modify || e == fe_close)
 | ||
|     {
 | ||
|       if (!o.empty() && !is_max(F_NORFIS_88, F_MAX_88))
 | ||
|         return error_box(TR("E' necessario completare l'ammortamento normale prima di calcolare quello anticipato"));
 | ||
|     }
 | ||
|     break;
 | ||
|   case F_ANTFIS_89:
 | ||
|     if (e == fe_modify || e == fe_close)
 | ||
|     {
 | ||
|       if (!o.empty() && !is_max(F_NORFIS_89, F_MAX_89))
 | ||
|         return error_box(TR("E' necessario completare l'ammortamento normale prima di calcolare quello anticipato"));
 | ||
|     }
 | ||
|     break;
 | ||
|   default:
 | ||
|     break;
 | ||
|   }  
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // Maschera di beni immateriali
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| class TImm_mask : public TAutomask
 | ||
| {      
 | ||
| protected:
 | ||
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | ||
| 
 | ||
| public:  
 | ||
|   TImm_mask() : TAutomask("ce1400c") { }
 | ||
| };
 | ||
| 
 | ||
| bool TImm_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | ||
| {
 | ||
|   switch (o.dlg())
 | ||
|   {
 | ||
|   case F_CATEGORIA:
 | ||
|     {
 | ||
|       TDitta_cespiti& dc = ditta_cespiti();
 | ||
|       return dc.on_category_event(o, e, jolly);
 | ||
|     }
 | ||
|     break;
 | ||
|   default:
 | ||
|     break;
 | ||
|   }  
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // Maschera di costi pluriennali
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| class TPlu_mask : public TAutomask
 | ||
| {      
 | ||
| protected:
 | ||
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | ||
| 
 | ||
| public:  
 | ||
|   TPlu_mask() : TAutomask("ce1400d") { }
 | ||
| };
 | ||
| 
 | ||
| bool TPlu_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | ||
| {
 | ||
|   switch (o.dlg())
 | ||
|   {                       
 | ||
|   case F_CATEGORIA:
 | ||
|     {
 | ||
|       TDitta_cespiti& dc = ditta_cespiti();
 | ||
|       return dc.on_category_event(o, e, jolly);
 | ||
|     }
 | ||
|     break;
 | ||
|   default:
 | ||
|     break;
 | ||
|   }  
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // Applicazione principale
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| TMask* TScelta_amm_cat::get_mask(int mode)
 | ||
| {   
 | ||
|   TMask* m = NULL;
 | ||
|   if (mode == MODE_QUERY || mode == MODE_QUERYINS)
 | ||
|   {
 | ||
|     if (_msk[0] == NULL)
 | ||
|        _msk[0] = new TSac_mask;
 | ||
|     m = _msk[0];
 | ||
|   }  
 | ||
|   else
 | ||
|   {
 | ||
|     switch(_tipo)
 | ||
|     {
 | ||
|     case 1: 
 | ||
|       if (_msk[2] == NULL)
 | ||
|         _msk[2] = new TImm_mask;
 | ||
|       break;
 | ||
|     case 2:
 | ||
|       if (_msk[3] == NULL)
 | ||
|         _msk[3] = new TPlu_mask;
 | ||
|       break;
 | ||
|     default:
 | ||
|       if (_msk[1] == NULL)
 | ||
|         _msk[1] = new TMat_mask;
 | ||
|       _tipo = 0;
 | ||
|       break;
 | ||
|     }
 | ||
|     m = _msk[_tipo+1];
 | ||
|   }
 | ||
|   return m;
 | ||
| }
 | ||
| 
 | ||
| bool TScelta_amm_cat::user_create()
 | ||
| {                                
 | ||
|   open_files(LF_TABCOM, LF_CATDI, 0);
 | ||
|   _rel = new TRelation(LF_CATDI);   
 | ||
|   memset(_msk, 0, sizeof(_msk));
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| bool TScelta_amm_cat::user_destroy()
 | ||
| {                                
 | ||
|   for (int m = 3; m >= 0; m--)
 | ||
|     if (_msk[m]) delete _msk[m];
 | ||
|   delete _rel;
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| bool TScelta_amm_cat::protected_record(TRelation& rel)
 | ||
| { 
 | ||
|   const TRectype& curr = rel.curr();
 | ||
|   const int annoes = curr.get_int(CATDI_CODES);
 | ||
|   int gruppo = curr.get_int(CATDI_CODCGRA);
 | ||
|   if (gruppo <= 0) gruppo = curr.get_int(CATDI_CODCGR);
 | ||
|   TString4 specie = curr.get(CATDI_CODSPA);
 | ||
|   if (specie.blank())                     
 | ||
|     specie = curr.get(CATDI_CODSP);
 | ||
|     
 | ||
|   TString16 str;  
 | ||
|   str.format("%04d%02d%-4s", annoes, gruppo, (const char*)specie);
 | ||
|   const TRectype& curr_ccb = cache().get("CCB", str);
 | ||
|   const bool protect = curr_ccb.get_bool("B1"); // Bollato stampato
 | ||
|   return protect;
 | ||
| }
 | ||
| 
 | ||
| void TScelta_amm_cat::init_query_mode(TMask& m)
 | ||
| {
 | ||
|   ditta_cespiti().init_mask(m);
 | ||
|   set_search_field(F_CATEGORIA2);
 | ||
|   m.show(F_CATEGORIA2); m.show(F_DESC_CAT2);
 | ||
|   m.hide(F_CATEGORIA); m.hide(F_DESC_CAT);
 | ||
| }
 | ||
| 
 | ||
| void TScelta_amm_cat::init_query_insert_mode(TMask& m)
 | ||
| {
 | ||
|   ditta_cespiti().init_mask(m);
 | ||
|   set_search_field(F_CATEGORIA);
 | ||
|   m.show(F_CATEGORIA); m.show(F_DESC_CAT);
 | ||
|   m.hide(F_CATEGORIA2); m.hide(F_DESC_CAT2);
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| void TScelta_amm_cat::init_mask(TMask& m)
 | ||
| {
 | ||
|   TDitta_cespiti& dc = ditta_cespiti();
 | ||
|   const int ese = _msk[0]->get_int(F_ESERCIZIO);
 | ||
|   const int gru = _msk[0]->get_int(F_GRUPPO);
 | ||
|   const char* spe = _msk[0]->get(F_SPECIE);
 | ||
|   const int cat = _msk[0]->get_int(F_CATEGORIA2);
 | ||
|   dc.set_attivita(ese, gru, spe);
 | ||
|   dc.init_mask(m);
 | ||
|   m.set(F_CATEGORIA, cat);
 | ||
|   
 | ||
|   const TRectype& cac = dc.categoria(gru, spe, cat);
 | ||
|   switch (_tipo)
 | ||
|   {
 | ||
|   case 1:  // Immateriali
 | ||
|     m.set(F_TIPOAMM, cac.get("I1"));
 | ||
|     m.set(F_MAX_AMM, cac.get("R13"));
 | ||
|     m.set(F_ANNI, cac.get("I3"));
 | ||
|     break;
 | ||
|   case 2:  // Pluriennali
 | ||
|     m.set(F_TIPOVINC, cac.get("I2"));
 | ||
|     m.set(F_MIN_AMM, cac.get("R14"));
 | ||
|     m.set(F_MAX_AMM, cac.get("R15"));
 | ||
|     m.set(F_ANNI, cac.get("I3"));
 | ||
|     break;
 | ||
|   default: // Materiali   
 | ||
|     {
 | ||
|       const real r11 = cac.get_real("R11");
 | ||
|       const real r12 = cac.get_real("R12");
 | ||
|       m.set(F_MIN_87, real(r12/2.0));
 | ||
|       m.set(F_MIN_88, real(r12/2.0));
 | ||
|       m.set(F_MIN_89, real(r11/2.0));
 | ||
|       m.set(F_MAX_87, r12);
 | ||
|       m.set(F_MAX_88, r12);
 | ||
|       m.set(F_MAX_89, r11);
 | ||
|     }
 | ||
|     break;
 | ||
|   }
 | ||
|  
 | ||
|   const bool can_edit = !dc.bollato_stampato();
 | ||
|   m.enable(DLG_SAVEREC, can_edit);
 | ||
|   m.enable(DLG_NEWREC, can_edit);
 | ||
|   m.enable(DLG_DELREC, can_edit);
 | ||
| }
 | ||
| 
 | ||
| void TScelta_amm_cat::init_insert_mode(TMask& m)
 | ||
| {
 | ||
|   init_mask(m);      
 | ||
| }
 | ||
| 
 | ||
| void TScelta_amm_cat::init_modify_mode(TMask& m)
 | ||
| {
 | ||
|   init_mask(m);
 | ||
| }
 | ||
| 
 | ||
| int ce1400(int argc, char* argv[])
 | ||
| {
 | ||
|   TScelta_amm_cat sac;
 | ||
|   sac.run(argc, argv, TR("Scelta ammortamento per categoria"));
 | ||
|   return 0;
 | ||
| }               
 |