Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione AGA patch 218 sul main trunk git-svn-id: svn://10.65.10.50/trunk@10087 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			791 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			791 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <defmask.h>
 | 
						|
#include <recarray.h>
 | 
						|
#include <relapp.h>
 | 
						|
#include <sheet.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include "ce1.h"
 | 
						|
#include "ce2101.h"
 | 
						|
#include "celib.h"
 | 
						|
 | 
						|
#include "ce1301a.h"
 | 
						|
#include "../cg/cglib01.h"
 | 
						|
 | 
						|
 | 
						|
#include "cespi.h"
 | 
						|
#include "salce.h"
 | 
						|
#include "ammce.h"
 | 
						|
#include "catdi.h"
 | 
						|
 | 
						|
/////////////////////////////////////////////////////////
 | 
						|
//Applicazione principale: prima puntata...
 | 
						|
/////////////////////////////////////////////////////////
 | 
						|
class TSelect_ammoces : public TRelation_application
 | 
						|
{
 | 
						|
  TRelation* _rel;
 | 
						|
  TAutomask* _msk[4];
 | 
						|
  int _tipo;  
 | 
						|
  real _aliqmax, _aliqmin, _aliqant;
 | 
						|
    
 | 
						|
private:
 | 
						|
  
 | 
						|
protected:
 | 
						|
  virtual bool user_create();
 | 
						|
  virtual bool user_destroy();
 | 
						|
  virtual TRelation* get_relation() const { return _rel; };
 | 
						|
  virtual bool changing_mask(int mode) { return TRUE; }
 | 
						|
  virtual TMask* get_mask(int mode);
 | 
						|
  
 | 
						|
  void init_mask(TMask& m);
 | 
						|
  virtual void init_query_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 TSelect_ammoces& app() { return (TSelect_ammoces&)main_app(); }
 | 
						|
//Continua piú avanti...
 | 
						|
//-----------------------------------------------------------------------------------------------------------------------//
 | 
						|
/////////////////////////////////////
 | 
						|
//Maschera di query
 | 
						|
/////////////////////////////////////
 | 
						|
class TSelam_qmask : public TAutomask
 | 
						|
{      
 | 
						|
  int _staat;
 | 
						|
  real _residuof, _residuoc, _uniprice;
 | 
						|
  bool _ammo100;
 | 
						|
 
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
  void on_search_event(TOperable_field& o);
 | 
						|
 | 
						|
  int calcola_stato_attivita();
 | 
						|
  bool cespite_ok() const;
 | 
						|
  
 | 
						|
public:
 | 
						|
   int stato_attivita() const { return _staat; }
 | 
						|
   real get_residuof() const { return _residuof; }
 | 
						|
   real get_residuoc() const { return _residuoc; }
 | 
						|
   void calc_res(bool prec);
 | 
						|
   
 | 
						|
  TSelam_qmask();
 | 
						|
};
 | 
						|
 | 
						|
//scelta tipo ordinamento
 | 
						|
void TSelam_qmask::on_search_event(TOperable_field& o)
 | 
						|
{
 | 
						|
  TToken_string order, fields, header;
 | 
						|
  if (o.dlg() >= F_SEARCH3)
 | 
						|
  {
 | 
						|
    order.add(CESPI_STABILIM); header.add("Stabilimento");
 | 
						|
    order.add(CESPI_REPARTO); header.add("Reparto@10");
 | 
						|
  }
 | 
						|
  if (o.dlg() >= F_SEARCH2) 
 | 
						|
  {
 | 
						|
    order.add(CESPI_CODIMP); header.add("Impianto@10");
 | 
						|
  }
 | 
						|
  if (o.dlg() >= F_SEARCH1)
 | 
						|
  {
 | 
						|
    order.add(CESPI_CODCAT); header.add("Cat");
 | 
						|
    order.add(CESPI_DTCOMP); header.add("Data Acq.@10");
 | 
						|
  }
 | 
						|
 | 
						|
  order.add(CESPI_IDCESPITE); header.add("Codice@10");
 | 
						|
  
 | 
						|
  fields = order;
 | 
						|
  fields.add(CESPI_DESC); header.add("Descrizione@50");
 | 
						|
  
 | 
						|
  TRelation rel(LF_CESPI);
 | 
						|
  
 | 
						|
  TString filter;
 | 
						|
  if (!field(F_IMPIANTO).empty())
 | 
						|
    filter << CESPI_CODIMP << "==" << get(F_IMPIANTO);
 | 
						|
  
 | 
						|
  TSorted_cursor cur(&rel, order, filter);
 | 
						|
  TCursor_sheet sht(&cur, fields, "Cespiti", header, 0, 1);
 | 
						|
  if (sht.run() == K_ENTER)
 | 
						|
  { 
 | 
						|
    TToken_string& row = sht.row();
 | 
						|
    const int cod_pos = row.items()-2;
 | 
						|
    set(F_IDCESPITE, row.get(cod_pos), TRUE);
 | 
						|
    stop_run(K_AUTO_ENTER);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
int TSelam_qmask::calcola_stato_attivita()
 | 
						|
{
 | 
						|
  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);
 | 
						|
  if (curr_ccb.get_bool("B1")) // Bollato stampato
 | 
						|
    _staat = 1;
 | 
						|
  
 | 
						|
  TDitta_cespiti& dc = ditta_cespiti();
 | 
						|
  dc.set_attivita(ese, gru, spe);
 | 
						|
  
 | 
						|
  return _staat;
 | 
						|
}
 | 
						|
 | 
						|
bool TSelam_qmask::cespite_ok() const
 | 
						|
{
 | 
						|
  TLocalisamfile cespi(LF_CESPI);
 | 
						|
  cespi.put(CESPI_IDCESPITE, get(F_IDCESPITE));
 | 
						|
  bool ok = cespi.read() == NOERR;
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
void TSelam_qmask::calc_res(bool prec)
 | 
						|
{
 | 
						|
  TCespite ces (get(F_IDCESPITE));                
 | 
						|
// calcolo ammortamento sul cespite (per sit. fiscale(1) e civilistica(2))        
 | 
						|
  TDate fine_es = get(F_FINE_ES);  
 | 
						|
  ces.calc_amm(1, fine_es);
 | 
						|
  const TRectype& salce2=ces.sal_pro();    //rectype giá di "tipo fiscale"
 | 
						|
  const TRectype& ammce2=ces.amm_pro();
 | 
						|
// determinazione del residuo fiscale
 | 
						|
  _residuof = ZERO;
 | 
						|
  _residuof = salce2.get_real(SALCE_CSTO)-salce2.get_real(SALCE_VNONAMM)+salce2.get_real(SALCE_RIV75)+salce2.get_real(SALCE_RIV83)+salce2.get_real(SALCE_RIV90)+salce2.get_real(SALCE_RIV91)+salce2.get_real(SALCE_RIVGF);
 | 
						|
  _residuof -= ammce2.get_real(AMMCE_QNORP)+ammce2.get_real(AMMCE_QACCP)+ammce2.get_real(AMMCE_QANTP)+ammce2.get_real(AMMCE_QPERSEP)+ammce2.get_real(AMMCE_FPRIVATOP)+ammce2.get_real(AMMCE_QPPRIVATEP);
 | 
						|
  if (!prec)
 | 
						|
    _residuof -= ammce2.get_real(AMMCE_QNOR)+ammce2.get_real(AMMCE_QACC)+ammce2.get_real(AMMCE_QANT)+ammce2.get_real(AMMCE_QPERSE)+ammce2.get_real(AMMCE_FPRIVATO)+ammce2.get_real(AMMCE_QPPRIVATE);
 | 
						|
      
 | 
						|
  ces.calc_amm(2, fine_es);
 | 
						|
//rectype giá di "tipo civilistico"
 | 
						|
// determinazione del residuo civilistico
 | 
						|
  _residuoc = ZERO;
 | 
						|
  _residuoc = salce2.get_real(SALCE_CSTO)+salce2.get_real(SALCE_RIV75)+salce2.get_real(SALCE_RIV83)+salce2.get_real(SALCE_RIV90)+salce2.get_real(SALCE_RIV91)+salce2.get_real(SALCE_RIVGC);
 | 
						|
  _residuoc -= ammce2.get_real(AMMCE_QNORP)+ammce2.get_real(AMMCE_QACCP)+ammce2.get_real(AMMCE_QANTP);
 | 
						|
  if (!prec)
 | 
						|
    _residuoc -= ammce2.get_real(AMMCE_QNOR)+ammce2.get_real(AMMCE_QACC)+ammce2.get_real(AMMCE_QANT);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TSelam_qmask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case F_ESERCIZIO:            
 | 
						|
    if (e == fe_close)
 | 
						|
      calcola_stato_attivita();
 | 
						|
    break;
 | 
						|
    
 | 
						|
  case F_SEARCH1:
 | 
						|
  case F_SEARCH2:
 | 
						|
  case F_SEARCH3:
 | 
						|
    if (e == fe_button)
 | 
						|
      on_search_event(o);
 | 
						|
    break;
 | 
						|
    
 | 
						|
  case F_IDCESPITE:            //é come fare l'OR (F_IDCESPITE || F_IDCESPITE_I)
 | 
						|
  case F_IDCESPITE_I:
 | 
						|
    if (e == fe_close)  
 | 
						|
    { 
 | 
						|
      if (!cespite_ok())
 | 
						|
        return error_box("Inserire un cespite valido"); //controlla che esista il cespite
 | 
						|
      if (stato_attivita() == 1)
 | 
						|
        warning_box("E' stato stampato il bollato dell'anno:\nnon sono permesse modifiche"); //il bollato é stato stampato
 | 
						|
        
 | 
						|
      TCespite ces (get(F_IDCESPITE));                 // controlla che la categoria del cespite sia ammortizzabile
 | 
						|
      const TRectype& categoria = ces.categoria();
 | 
						|
      bool non_ammortizzabile = categoria.get_bool("B0");
 | 
						|
      if (non_ammortizzabile)
 | 
						|
        return error_box("Impossibile effettuare ammortamenti perché il cespite\nappartiene ad una categoria di beni non ammortizzabili");
 | 
						|
      
 | 
						|
      int materiale = categoria.get_int("I0");      
 | 
						|
      app().set_tipo_beni(materiale);  //inizializza la variabile tipo
 | 
						|
       
 | 
						|
      if (materiale == 0)                                // controlla che il cespite non sia per caso in leasing 
 | 
						|
      {                                                  // solo i cespiti materiali possono essere in leasing..
 | 
						|
        if (ces.get_bool(CESPI_LEASING) == TRUE)
 | 
						|
          return error_box("Impossibile impostare le scelte per cespiti ceduti in leasing");
 | 
						|
      }   
 | 
						|
      
 | 
						|
      const TDate& datafunz = ces.get_date("DTFUNZ");    // se la data di entrata in funzione non é nulla....
 | 
						|
      if (datafunz.ok())
 | 
						|
      {
 | 
						|
        calc_res(TRUE);                                  // controllo dei residui fiscale e civilistico in ingresso (prec=TRUE)
 | 
						|
        if (_residuof==ZERO)
 | 
						|
        {
 | 
						|
          message_box("Il valore fiscale del cespite risulta giá completamente ammortizzato");
 | 
						|
          return TRUE;
 | 
						|
        }
 | 
						|
        
 | 
						|
        if (_residuoc==ZERO)
 | 
						|
        {
 | 
						|
          message_box("Il valore civilistico del cespite risulta giá completamente ammortizzato");
 | 
						|
          return TRUE;
 | 
						|
        }
 | 
						|
      }
 | 
						|
      
 | 
						|
      TLocalisamfile ammce(LF_AMMCE);                  // controlla eventuali forzature precedenti
 | 
						|
      ammce.put(AMMCE_IDCESPITE, get(F_IDCESPITE));
 | 
						|
      ammce.put(AMMCE_CODES, get(F_ESERCIZIO));
 | 
						|
      ammce.put(AMMCE_TPSALDO, 2);
 | 
						|
      ammce.put(AMMCE_TPAMM, 1);
 | 
						|
      if (ammce.read() == NOERR)
 | 
						|
        {
 | 
						|
          if (ammce.get_bool(AMMCE_FZPER) == TRUE)        
 | 
						|
            return error_box("Sul cespite sono state forzate le Percentuali:\nprocedere dalla forzatura ammortamenti su cespite");
 | 
						|
          if (ammce.get_bool(AMMCE_FZQUO) == TRUE)        
 | 
						|
            return error_box("Sul cespite sono state forzate le Quote:\nprocedere dalla forzatura ammortamenti su cespite");
 | 
						|
        }
 | 
						|
        
 | 
						|
      TLocalisamfile salce(LF_SALCE);              // controlla se ammesso ammortamento 100% per beni inferiori a 516.46 Euro
 | 
						|
      salce.put(SALCE_IDCESPITE, get(F_IDCESPITE));
 | 
						|
      salce.put(SALCE_CODES, get(F_ESERCIZIO));
 | 
						|
      salce.put(SALCE_TPSALDO, 1);
 | 
						|
      _ammo100 = FALSE;
 | 
						|
      _uniprice = 516.46;
 | 
						|
      if (! salce.get_date(SALCE_DTSTBOLL).ok())
 | 
						|
      {
 | 
						|
        if (datafunz.ok() && (datafunz > get_date(F_INIZIO_ES) && datafunz < get_date(F_FINE_ES)) && salce.get_int(SALCE_ANNIAMM) == 0)
 | 
						|
        {
 | 
						|
          if (ces.get_bool(CESPI_TUIR) == TRUE)
 | 
						|
          { 
 | 
						|
            const TDate& data_fine_es = get_date(F_FINE_ES);
 | 
						|
            ces.calc_amm(2, data_fine_es);
 | 
						|
            real valore = salce.get_real(SALCE_CSTO)-salce.get_real(SALCE_VNONAMM)+salce.get_real(SALCE_RIV75)+salce.get_real(SALCE_RIV83)+salce.get_real(SALCE_RIV90)+salce.get_real(SALCE_RIV91)+salce.get_real(SALCE_RIVGF);
 | 
						|
            real valoreuni = valore / salce.get_int(SALCE_NUMELE);
 | 
						|
            if (valoreuni <= _uniprice)
 | 
						|
              _ammo100 = TRUE;
 | 
						|
          }
 | 
						|
        }
 | 
						|
      }
 | 
						|
      else
 | 
						|
      {
 | 
						|
        real valore = salce.get_real(SALCE_CSTO)-salce.get_real(SALCE_VNONAMM)+salce.get_real(SALCE_RIV75)+salce.get_real(SALCE_RIV83)+salce.get_real(SALCE_RIV90)+salce.get_real(SALCE_RIV91)+salce.get_real(SALCE_RIVGF);
 | 
						|
        real valoreuni = valore / salce.get_int(SALCE_NUMELE);
 | 
						|
        if (valoreuni <= _uniprice)
 | 
						|
          _ammo100 = TRUE;       
 | 
						|
      }     
 | 
						|
 | 
						|
    }
 | 
						|
    break;
 | 
						|
    
 | 
						|
  default:
 | 
						|
  break;
 | 
						|
  }  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
TSelam_qmask::TSelam_qmask() : TAutomask("ce1301a") 
 | 
						|
{
 | 
						|
  first_focus(F_IDCESPITE);
 | 
						|
}
 | 
						|
 | 
						|
//-----------------------------------------------------------------------------------------------------------------------//
 | 
						|
//////////////////////////////////////////////////////////////////
 | 
						|
//Maschera BENI MATERIALI
 | 
						|
//////////////////////////////////////////////////////////////////
 | 
						|
class TSelam_mmask : public TAutomask
 | 
						|
{
 | 
						|
  int _staat;
 | 
						|
 | 
						|
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;
 | 
						|
          
 | 
						|
public:
 | 
						|
  void set_stato_attivita(int sa) { _staat = sa; }
 | 
						|
  int stato_attivita() const { return _staat; }
 | 
						|
 | 
						|
  TSelam_mmask() : TAutomask("ce1301b") { }
 | 
						|
};
 | 
						|
 | 
						|
bool TSelam_mmask::test_min(short quota, short minimo) const
 | 
						|
{
 | 
						|
  bool warning = FALSE;
 | 
						|
  const bool ammrit = get_bool(F_AMMRIT_CE);
 | 
						|
  if (!ammrit)
 | 
						|
  {
 | 
						|
    const real perq = get(quota);
 | 
						|
    const real minq = get(minimo);
 | 
						|
    warning = perq < minq;
 | 
						|
  }
 | 
						|
  return warning;
 | 
						|
}
 | 
						|
 | 
						|
bool TSelam_mmask::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 TSelam_mmask::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_AMMFISC_NOR_CE:                     
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    { 
 | 
						|
      if (get_bool(F_AMM100_CE) == FALSE)
 | 
						|
      {
 | 
						|
        if (test_min(F_AMMFISC_NOR_CE, F_NORMIN))        // controlla se si producono quote perse fiscali
 | 
						|
          warning_box("L'ammortamento normale è inferiore al minimo della tabella ministeriale:\n"
 | 
						|
                      "Se non si seleziona l'ammortamento ritardato verranno generate delle quote perse");
 | 
						|
        if (test_max(F_AMMFISC_NOR_CE, F_AMMFISC_ANT_CE, F_AMMFISC_ACC_CE))     // controlla totale percentuali impostate fiscali
 | 
						|
          return error_box("Il totale delle percentuali di ammortamento fiscale supera il 100%");
 | 
						|
      }   
 | 
						|
    }    
 | 
						|
    break; 
 | 
						|
 | 
						|
  case F_AMMFISC_ACC_CE:
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    {
 | 
						|
      if (test_max(F_AMMFISC_NOR_CE, F_AMMFISC_ANT_CE, F_AMMFISC_ACC_CE))     // controlla totale percentuali impostate fiscali
 | 
						|
        return error_box("Il totale delle percentuali di ammortamento fiscale supera il 100%");
 | 
						|
    }
 | 
						|
    break;
 | 
						|
                 
 | 
						|
  case F_AMMFISC_ANT_CE:
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    { 
 | 
						|
      if (test_max(F_AMMFISC_NOR_CE, F_AMMFISC_ANT_CE, F_AMMFISC_ACC_CE))     // controlla totale percentuali impostate fiscali
 | 
						|
        return error_box("Il totale delle percentuali di ammortamento fiscale supera il 100%");
 | 
						|
    
 | 
						|
      if (!o.empty() && test_min(F_AMMFISC_NOR_CE, F_NORMAX))
 | 
						|
        return error_box("E' necessario completare l'ammortamento normale fiscale prima di calcolare quello anticipato fiscale");
 | 
						|
    }
 | 
						|
    break;    
 | 
						|
 | 
						|
  case F_AMMCIV_NOR_CE:                     
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    {
 | 
						|
      if (test_max(F_AMMCIV_NOR_CE, F_AMMCIV_ANT_CE, F_AMMCIV_ACC_CE))     // controlla totale percentuali impostate civilistiche
 | 
						|
        return error_box("Il totale delle percentuali di ammortamento civilistico supera il 100%");    
 | 
						|
    }    
 | 
						|
    break;
 | 
						|
 | 
						|
  case F_AMMCIV_ANT_CE:
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    { 
 | 
						|
      if (test_max(F_AMMCIV_NOR_CE, F_AMMCIV_ANT_CE, F_AMMCIV_ACC_CE))     // controlla totale percentuali impostate civilistiche
 | 
						|
        return error_box("Il totale delle percentuali di ammortamento civilistico supera il 100%");
 | 
						|
    
 | 
						|
      if (!o.empty() && test_min(F_AMMCIV_NOR_CE, F_NORMAX))
 | 
						|
        return error_box("E' necessario completare l'ammortamento normale civilistico prima di calcolare quello anticipato civilistico");
 | 
						|
    }
 | 
						|
    break;
 | 
						|
 | 
						|
  case F_AMMCIV_ACC_CE:
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    {
 | 
						|
      if (test_max(F_AMMCIV_NOR_CE, F_AMMCIV_ANT_CE, F_AMMCIV_ACC_CE))     // controlla totale percentuali impostate civilistiche
 | 
						|
        return error_box("Il totale delle percentuali di ammortamento civilistico supera il 100%");
 | 
						|
    }
 | 
						|
    break;
 | 
						|
    
 | 
						|
  case F_AMMRIT_CE:
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    {
 | 
						|
      if (get_bool(F_AMMRIT_CE) == TRUE)
 | 
						|
      {
 | 
						|
        if ((get_real(F_AMMFISC_NOR_CE) >= get_real(F_NORMIN)) || (get_real(F_AMMCIV_NOR_CE) >= get_real(F_NORMIN)))
 | 
						|
          return error_box("Indicata la scelta di ammortamento ritardato ma il Normale supera il Minimo ministeriale");
 | 
						|
        if (get_real(F_AMMFISC_ACC_CE) != 0 || get_real(F_AMMCIV_ACC_CE) != 0)
 | 
						|
          return error_box("Impossibile scegliere contemporaneamente ammortamento Accelerato e Ritardato");
 | 
						|
      }
 | 
						|
    }
 | 
						|
    break;
 | 
						|
    
 | 
						|
  case F_ANTMIN:
 | 
						|
  case F_SCELTA:
 | 
						|
    if (e == fe_modify || e == fe_init)
 | 
						|
    {
 | 
						|
      if (((get_int(F_SCELTA) == 1) && (get_real(F_ANTMIN) == 0)) || get_int(F_SCELTA) != 1)
 | 
						|
      {  
 | 
						|
        disable(F_AMMFISC_ANT_CE);
 | 
						|
        reset(F_AMMFISC_ANT_CE);
 | 
						|
      }  
 | 
						|
      else
 | 
						|
        enable(F_AMMFISC_ANT_CE);
 | 
						|
    }
 | 
						|
    break; 
 | 
						|
  
 | 
						|
  default:
 | 
						|
  break;    
 | 
						|
  }    
 | 
						|
  return TRUE;
 | 
						|
} 
 | 
						|
 | 
						|
//-----------------------------------------------------------------------------------------------------------------------//
 | 
						|
////////////////////////////////////////////////////////////////////
 | 
						|
//Maschera BENI IMMATERIALI
 | 
						|
////////////////////////////////////////////////////////////////////
 | 
						|
class TSelam_imask : public TAutomask
 | 
						|
{      
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:  
 | 
						|
  TSelam_imask() : TAutomask("ce1301c") { }
 | 
						|
};
 | 
						|
 | 
						|
bool TSelam_imask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case F_CATEGORIA:
 | 
						|
  case F_DESC_CAT:
 | 
						|
    {
 | 
						|
      TDitta_cespiti& dc = ditta_cespiti();
 | 
						|
      return dc.on_category_event(o, e, jolly);
 | 
						|
    }
 | 
						|
    break;
 | 
						|
    
 | 
						|
  case F_AMMFISC_CE:
 | 
						|
  case F_AMMCIV_CE:
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    {
 | 
						|
      TCespite ces = get(F_IDCESPITE);
 | 
						|
      if ( (ces.get_int(CESPI_VINCOLO) != 2) && ( (get(F_AMMFISC_CE) > get(F_ALIQMAX)) || (get(F_AMMCIV_CE) > get(F_ALIQMAX)) ) )
 | 
						|
        return error_box("L' ammortamento richiesto supera il limite della categoria");
 | 
						|
    }
 | 
						|
  break;
 | 
						|
  
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
//-----------------------------------------------------------------------------------------------------------------------//
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Maschera di costi pluriennali
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TSelam_pmask : public TAutomask
 | 
						|
{      
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:  
 | 
						|
  TSelam_pmask() : TAutomask("ce1301d") { }
 | 
						|
};
 | 
						|
 | 
						|
bool TSelam_pmask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case F_CATEGORIA:
 | 
						|
  case F_DESC_CAT:
 | 
						|
    {
 | 
						|
      TDitta_cespiti& dc = ditta_cespiti();
 | 
						|
      return dc.on_category_event(o, e, jolly);
 | 
						|
    }
 | 
						|
    break;
 | 
						|
    
 | 
						|
  case F_AMMFISC_CE:
 | 
						|
  case F_AMMCIV_CE:
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    { 
 | 
						|
      TCespite ces = get(F_IDCESPITE);
 | 
						|
      if (ces.get_int(CESPI_VINCOLO) == 1)      
 | 
						|
      {
 | 
						|
        if (ces.get_int(CESPI_ANNIRIC) == 0)
 | 
						|
        { 
 | 
						|
          real amm_fisc = o.get();
 | 
						|
          if (amm_fisc == ZERO)     //controlla l'obbligatorietá e la validitá dei campi (fiscale)
 | 
						|
            return error_box("Compilare l'ammortamento scelto");
 | 
						|
          else
 | 
						|
          {
 | 
						|
            if (amm_fisc < get_real(F_ALIQMIN))
 | 
						|
              return error_box("L'ammortamento scelto é inferiore al minimo da Tabella");
 | 
						|
            if (amm_fisc > get_real(F_ALIQMAX))
 | 
						|
              return error_box("L'ammortamento scelto é superiore al minimo da Tabella");
 | 
						|
          }   
 | 
						|
        }
 | 
						|
      }
 | 
						|
      else
 | 
						|
      { 
 | 
						|
        real anni_ammo = get_real(F_ANNIAMMOREQ);
 | 
						|
        if ((anni_ammo == 0) && ces.get_bool(CESPI_LEASING) == TRUE)
 | 
						|
          return error_box("Compilare gli anni ammortamento richiesti");
 | 
						|
        else if (anni_ammo > get_int(F_ENTROANNI))
 | 
						|
          return error_box("Il numero di anni di ammortamento scelti supera il limite da tabella");  
 | 
						|
      } 
 | 
						|
    }
 | 
						|
    break;  
 | 
						|
    
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
//---------------------------------------------------------------------------------------------------------//
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Applicazione principale: seconda puntata
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
TMask* TSelect_ammoces::get_mask(int mode)
 | 
						|
{
 | 
						|
  TMask* m = NULL;
 | 
						|
  if (mode == MODE_QUERY || mode == MODE_QUERYINS)
 | 
						|
  {
 | 
						|
    if (_msk[0] == NULL)
 | 
						|
       _msk[0] = new TSelam_qmask;
 | 
						|
    m = _msk[0];
 | 
						|
  }  
 | 
						|
  else
 | 
						|
  {
 | 
						|
    switch(_tipo)
 | 
						|
    {
 | 
						|
    case 1: 
 | 
						|
      if (_msk[2] == NULL)
 | 
						|
        _msk[2] = new TSelam_imask;
 | 
						|
      break;
 | 
						|
    case 2:
 | 
						|
      if (_msk[3] == NULL)
 | 
						|
        _msk[3] = new TSelam_pmask;
 | 
						|
      break;
 | 
						|
    default:
 | 
						|
      if (_msk[1] == NULL)
 | 
						|
        _msk[1] = new TSelam_mmask;
 | 
						|
      break;
 | 
						|
    }
 | 
						|
    m = _msk[_tipo+1];
 | 
						|
  }
 | 
						|
  return m;
 | 
						|
}
 | 
						|
 | 
						|
bool TSelect_ammoces::user_create()
 | 
						|
{             
 | 
						|
  open_files(LF_TABCOM, LF_TAB, LF_CESPI, LF_SALCE, LF_AMMCE, LF_CATDI, 0);
 | 
						|
  _rel = new TRelation (LF_AMMCE);                               // relazione principale su AMMCE
 | 
						|
  TString expr69, expr77;
 | 
						|
  expr69 << "IDCESPITE==IDCESPITE|CODES==CODES|TPSALDO==TPSALDO|TPAMM==2";   //seconda relazione su AMMCE (quella con i TPAMM=2)
 | 
						|
  _rel->add(LF_AMMCE, expr69, 1, 0, 69);                                   //69 é l'alias di AMMCE
 | 
						|
  _rel->write_enable(-69);                   //abilita la scrittura su secondo AMMCE
 | 
						|
  expr77 << "IDCESPITE==IDCESPITE|CODES==CODES|TPSALDO==TPSALDO|TPAMM==3";   //terza relazione su AMMCE (quella con i TPAMM=3)
 | 
						|
  _rel->add(LF_AMMCE, expr77, 1, 0, 77);                                   //77 é l'alias di AMMCE
 | 
						|
  _rel->write_enable(-77);                   //abilita la scrittura su terzo AMMCE  
 | 
						|
  _rel->add(LF_CESPI, "IDCESPITE==IDCESPITE");    //estende la relazione con CESPI
 | 
						|
  _rel->add(LF_SALCE, "IDCESPITE==IDCESPITE|CODES==CODES|TPSALDO==TPSALDO");
 | 
						|
  memset(_msk, 0, sizeof(_msk));
 | 
						|
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TSelect_ammoces::user_destroy()
 | 
						|
{                                
 | 
						|
  for (int m = 3; m >= 0; m--)
 | 
						|
    if (_msk[m]) delete _msk[m];
 | 
						|
  delete _rel;
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void TSelect_ammoces::init_query_mode(TMask& m)
 | 
						|
{
 | 
						|
  ditta_cespiti().init_mask(m);
 | 
						|
}
 | 
						|
 | 
						|
void TSelect_ammoces::init_mask(TMask& m)
 | 
						|
{
 | 
						|
  TDitta_cespiti& dc = ditta_cespiti();                 //se il bollato dell'esercizio é stato stampato inibisce il REGISTRA
 | 
						|
  const int ese = _msk[0]->get_int(F_ESERCIZIO);        //prende i dati attivitá dalla maschera di selezione
 | 
						|
  const int gru = _msk[0]->get_int(F_GRUPPO);
 | 
						|
  const char* spe = _msk[0]->get(F_SPECIE);
 | 
						|
  dc.set_attivita(ese, gru, spe);
 | 
						|
  dc.init_mask(m);
 | 
						|
  const bool can_edit = !dc.bollato_stampato();
 | 
						|
  m.enable(DLG_SAVEREC, can_edit);         // inibisce la registrazione se bollato stampato
 | 
						|
  m.enable(DLG_DELREC, can_edit);
 | 
						|
  const TString16 idcespite = m.get(F_IDCESPITE);
 | 
						|
  const TCespite ces (idcespite);
 | 
						|
  
 | 
						|
  TLocalisamfile catdi(LF_CATDI);       //legge i valori dal file CATDI e li mette nei campi solo output delle msk
 | 
						|
  catdi.put(CATDI_CODES, m.get_int(F_ESERCIZIO));
 | 
						|
  catdi.put(CATDI_CODCGRA, m.get_int(F_GRUPPO));
 | 
						|
  catdi.put(CATDI_CODSPA, m.get(F_SPECIE));
 | 
						|
  catdi.put(CATDI_CODCAT, m.get_int(F_CATEGORIA));
 | 
						|
  if (catdi.read() != NOERR)    
 | 
						|
    catdi.zero();
 | 
						|
  const int annofunz = m.get_date(F_DTFUNZ).year();   //getta l'anno di entrata in funzione del cespite
 | 
						|
  
 | 
						|
  TLocalisamfile salce1(LF_SALCE);              
 | 
						|
  salce1.put(SALCE_IDCESPITE, m.get(F_IDCESPITE));
 | 
						|
  salce1.put(SALCE_CODES, m.get_int(F_ESERCIZIO));
 | 
						|
  salce1.put(SALCE_TPSALDO, 1);
 | 
						|
  
 | 
						|
  switch (_tipo)
 | 
						|
  {
 | 
						|
  case 1: //immateriali
 | 
						|
      if (ces.get_int(CESPI_VINCOLO) == 2)    //Controllo tipo ammortamento da categoria
 | 
						|
      {
 | 
						|
        m.clear(F_ALIQMAX);
 | 
						|
        m.clear(F_AMMFISC_CE);
 | 
						|
        m.clear(F_AMMCIV_CE);
 | 
						|
        m.set(F_ANNIAMMOREQ, ces.get_int(CESPI_ANNIRIC));
 | 
						|
      }
 | 
						|
      else
 | 
						|
      {
 | 
						|
        m.set(F_ALIQMAX, ces.get_real(CESPI_PIMM));
 | 
						|
        m.set(F_AMMFISC_CE, _rel->curr().get_real(AMMCE_PNOR));
 | 
						|
        m.set(F_AMMCIV_CE, _rel->curr(-69).get_real(AMMCE_PNOR));
 | 
						|
        m.clear(F_ANNIAMMOREQ);
 | 
						|
      }
 | 
						|
      
 | 
						|
      if (annofunz < 1988)    //mette i valori di categoria nei campi solo output
 | 
						|
      {
 | 
						|
        m.set(F_AMMFISC_CT, catdi.get(CATDI_PFNORVN));
 | 
						|
        m.set(F_AMMCIV_CT, catdi.get(CATDI_PCNORVN));
 | 
						|
      }
 | 
						|
      else if (annofunz == 1988)
 | 
						|
      {
 | 
						|
        m.set(F_AMMFISC_CT, catdi.get(CATDI_PFNORVT));
 | 
						|
        m.set(F_AMMCIV_CT, catdi.get(CATDI_PCNORVT));
 | 
						|
      }
 | 
						|
      else
 | 
						|
      {
 | 
						|
        m.set(F_AMMFISC_CT, catdi.get(CATDI_PFNORNT));
 | 
						|
        m.set(F_AMMCIV_CT, catdi.get(CATDI_PCNORNT));
 | 
						|
      }
 | 
						|
      
 | 
						|
    break;
 | 
						|
    
 | 
						|
  case 2: //pluriennali
 | 
						|
      m.set(F_ENTROANNI, ces.categoria().get("I3")); //scrive sulla maschera il numero di anni per l'ammortamento
 | 
						|
      
 | 
						|
      if (annofunz < 1988)    //mette i valori di categoria nei campi solo output
 | 
						|
      {
 | 
						|
        m.set(F_AMMFISC_CT, catdi.get(CATDI_PFNORVN));
 | 
						|
        m.set(F_AMMCIV_CT, catdi.get(CATDI_PCNORVN));
 | 
						|
      }
 | 
						|
      else if (annofunz == 1988)
 | 
						|
      {
 | 
						|
        m.set(F_AMMFISC_CT, catdi.get(CATDI_PFNORVT));
 | 
						|
        m.set(F_AMMCIV_CT, catdi.get(CATDI_PCNORVT));
 | 
						|
      }
 | 
						|
      else
 | 
						|
      {
 | 
						|
        m.set(F_AMMFISC_CT, catdi.get(CATDI_PFNORNT));
 | 
						|
        m.set(F_AMMCIV_CT, catdi.get(CATDI_PCNORNT));
 | 
						|
      }
 | 
						|
      
 | 
						|
      if (ces.get_int(CESPI_VINCOLO) == 3) //se il cespite é a quote costanti...
 | 
						|
      { 
 | 
						|
        if (salce1.read() == NOERR)
 | 
						|
        {
 | 
						|
          if (salce1.get_int(SALCE_ANNIAMM) != 0)    //controlla la modificabilitá delle scelte dopo il primo anno
 | 
						|
          { 
 | 
						|
            m.disable(DLG_SAVEREC); 
 | 
						|
            error_box("Ammortamento in quote costanti:\nimpossibile modificare le scelte dopo il primo esercizio di ammortamento");
 | 
						|
          }
 | 
						|
          else
 | 
						|
          {
 | 
						|
            m.disable(F_AMMFISC_CE);
 | 
						|
            m.disable(F_AMMCIV_CE);
 | 
						|
          }
 | 
						|
        }
 | 
						|
      }
 | 
						|
      else
 | 
						|
      {
 | 
						|
        if (m.get_int(F_ENTROANNI) <= m.get_int(F_NUMESERAMM))
 | 
						|
        {
 | 
						|
          m.disable(DLG_SAVEREC);
 | 
						|
          error_box("Impossibile proseguire:\nammortamento oltre il limite di anni della Tabella");
 | 
						|
        }
 | 
						|
      }           
 | 
						|
    break;
 | 
						|
    
 | 
						|
  default: //materiali
 | 
						|
    {    
 | 
						|
      _aliqmax = ces.get_real(CESPI_PMAT);    // calcola i valori predefiniti delle aliquote limite per cespiti materiali    
 | 
						|
      _aliqmin = _aliqmax * 0.5;
 | 
						|
      if (salce1.read() == NOERR)
 | 
						|
      {
 | 
						|
        if (ces.get_bool(CESPI_USATO) == FALSE)
 | 
						|
        {
 | 
						|
          if (salce1.get_int(SALCE_ANNIAMM) <= 2)
 | 
						|
          {
 | 
						|
            if (ces.get_bool(CESPI_TUIR) == TRUE)
 | 
						|
              _aliqant = _aliqmax;
 | 
						|
            else
 | 
						|
              _aliqant = 15.0;
 | 
						|
          }
 | 
						|
          else
 | 
						|
            _aliqant = 0.0;    
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
          if (salce1.get_int(SALCE_ANNIAMM) != 0)
 | 
						|
            _aliqant = 0.0;
 | 
						|
          else
 | 
						|
            _aliqant = _aliqmax;
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
    m.set(F_NORMIN, _aliqmin);
 | 
						|
    m.set(F_NORMAX, _aliqmax);
 | 
						|
    m.set(F_ANTMIN, _aliqant);
 | 
						|
        
 | 
						|
    if (annofunz < 1988)                              //mette i valori di categoria nei campi solo output
 | 
						|
    {
 | 
						|
      m.set(F_AMMFISC_NOR_CT, catdi.get(CATDI_PFNORVN));
 | 
						|
      m.set(F_AMMFISC_ANT_CT, catdi.get(CATDI_PFANTVN));
 | 
						|
      m.set(F_AMMCIV_NOR_CT, catdi.get(CATDI_PCNORVN));
 | 
						|
      m.set(F_AMMCIV_ANT_CT, catdi.get(CATDI_PCANTVN));
 | 
						|
    }
 | 
						|
    else if (annofunz == 1988)
 | 
						|
    {
 | 
						|
      m.set(F_AMMFISC_NOR_CT, catdi.get(CATDI_PFNORVT));
 | 
						|
      m.set(F_AMMFISC_ANT_CT, catdi.get(CATDI_PFANTVT));
 | 
						|
      m.set(F_AMMCIV_NOR_CT, catdi.get(CATDI_PCNORVT));
 | 
						|
      m.set(F_AMMCIV_ANT_CT, catdi.get(CATDI_PCANTVT));
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      m.set(F_AMMFISC_NOR_CT, catdi.get(CATDI_PFNORNT));
 | 
						|
      m.set(F_AMMFISC_ANT_CT, catdi.get(CATDI_PFANTNT));
 | 
						|
      m.set(F_AMMCIV_NOR_CT, catdi.get(CATDI_PCNORNT));
 | 
						|
      m.set(F_AMMCIV_ANT_CT, catdi.get(CATDI_PCANTNT));
 | 
						|
    }
 | 
						|
      
 | 
						|
    m.set(F_AMMFISC_ACC_CT, catdi.get(CATDI_PFACC));
 | 
						|
    m.set(F_AMMCIV_ACC_CT, catdi.get(CATDI_PCACC));
 | 
						|
    m.set(F_AMMRIT_CT, catdi.get(CATDI_AMMRIT));
 | 
						|
    m.set(F_AMM100_CT, catdi.get(CATDI_CSCEN));    
 | 
						|
    break;
 | 
						|
  } //chiude lo switch
 | 
						|
  
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
void TSelect_ammoces::init_insert_mode(TMask& m)
 | 
						|
{ 
 | 
						|
  init_mask(m);
 | 
						|
}
 | 
						|
 | 
						|
void TSelect_ammoces::init_modify_mode(TMask& m)
 | 
						|
{ 
 | 
						|
  init_mask(m);
 | 
						|
}
 | 
						|
 | 
						|
int ce1300(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TSelect_ammoces a;
 | 
						|
  a.run(argc, argv, "Scelta ammortamento per cespite");
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 |