/*
 * JSMin
 * Javascript Compressor
 * http://www.crockford.com/
 * http://www.smallsharptools.com/Projects/Packer/
*/

// V:\1.1.007\js\form\QE\Calcolatrici\Ext.ux.Namirial.form.CalcE7.js

Ext.ns('Ext.ux');Ext.ns('Ext.ux.Namirial');Ext.ns('Ext.ux.Namirial.form');Ext.ux.Namirial.form.CalcE7=Ext.extend(Ext.Window,{constructor:function(c){c=c||{};this.targetField=c.targetField;this.perc;this.CFISC=dichiarazione.getCurrentCfisc();this.tipo;try{this.tb_Annulla=new Ext.Toolbar.Button({text:'Annulla',icon:IMG_CANCEL,disabled:false,iconCls:'x-btn-text-icon',scope:this,tooltip:{title:'Annulla',text:'Annulla'},handler:this.annulla});this.tb_Salva=new Ext.Toolbar.Button({text:'Ok',icon:IMG_OK,disabled:false,scope:this,iconCls:'x-btn-text-icon',tooltip:{title:'Ok',text:'Ok'},handler:this.salva});this.titolo=new Ext.form.Label({html:'<b>Rideterminazione interessi nel caso di mutuo eccedente il costo di acquisto dell\'immobile (C.M. del 20 aprile 2005 n. 15 e successive)</b>'});this.labelEuro=new Ext.form.Label({html:'In Euro'});this.labelLire=new Ext.form.Label({html:'In Lire'});this.labelFooter=new Ext.form.Label({style:'font-weight: bold',text:''});this.textCfisc=new Ext.ux.Namirial.form.TextField({name:'CFISC',value:this.CFISC,hidden:true,labelSeparator:''});this.textTipo=new Ext.ux.Namirial.form.TextField({name:'TIPO',value:this.CFISC,hidden:true,labelSeparator:''});this.textPerc=new Ext.ux.Namirial.form.TextField({name:'PERC',value:this.CFISC,hidden:true,labelSeparator:''});this.IMPORTO=new Ext.ux.Namirial.form.NumberField({name:'IMPORTO',fieldLabel:'Importo da rideterminare',decimalPrecision:2,maxValue:99999999999,allowBlank:false});this.C01_E=new Ext.ux.Namirial.form.NumberField({name:'C01_E',decimalPrecision:2,fieldLabel:'Valore di acquisto contenuto nel rogito',maxValue:99999999999});this.C01_E.on('change',function(field){this.C01_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.C01_L=new Ext.ux.Namirial.form.NumberField({name:'C01_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.C01_L.on('change',function(field){this.C01_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.C02_E=new Ext.ux.Namirial.form.NumberField({name:'C02_E',fieldLabel:'Spese notarili per l\'atto di compravendita',decimalPrecision:2,maxValue:99999999999});this.C02_E.on('change',function(field){this.C02_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.C02_L=new Ext.ux.Namirial.form.NumberField({name:'C02_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.C02_L.on('change',function(field){this.C02_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.C03_E=new Ext.ux.Namirial.form.NumberField({name:'C03_E',fieldLabel:'Imposta di registro',decimalPrecision:2,maxValue:99999999999});this.C03_E.on('change',function(field){this.C03_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.C03_L=new Ext.ux.Namirial.form.NumberField({name:'C03_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.C03_L.on('change',function(field){this.C03_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.C04_E=new Ext.ux.Namirial.form.NumberField({name:'C04_E',fieldLabel:'Imposte ipotecarie e catastali',decimalPrecision:2,maxValue:99999999999});this.C04_E.on('change',function(field){this.C04_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.C04_L=new Ext.ux.Namirial.form.NumberField({name:'C04_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.C04_L.on('change',function(field){this.C04_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.C05_E=new Ext.ux.Namirial.form.NumberField({name:'C05_E',fieldLabel:'Compensi di mediazione',decimalPrecision:2,maxValue:99999999999});this.C05_E.on('change',function(field){this.C05_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.C05_L=new Ext.ux.Namirial.form.NumberField({name:'C05_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.C05_L.on('change',function(field){this.C05_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.C06_E=new Ext.ux.Namirial.form.NumberField({name:'C06_E',fieldLabel:'<u><b>Costo di acquisto</b></u>',decimalPrecision:2,readOnly:true,maxValue:99999999999});this.C06_E.on('change',function(field){this.C06_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.C06_L=new Ext.ux.Namirial.form.NumberField({name:'C06_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,readOnly:true,maxValue:99999999999});this.C06_L.on('change',function(field){this.C06_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.C07_E=new Ext.ux.Namirial.form.NumberField({name:'C07_E',fieldLabel:'<u><b>Capitale chiesto a mutuo</b></u>',decimalPrecision:2,maxValue:99999999999});this.C07_E.on('change',function(field){this.C07_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();if(this.C06_E.getNumericValue()>0){if(this.C06_E.getValue()>=this.C07_E.getValue()){this.setMsgMaggioreUguale();}else{this.setMsgMinore();}}else{this.perc=0;}},this);this.C07_L=new Ext.ux.Namirial.form.NumberField({name:'C07_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.C07_L.on('change',function(field){this.C07_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();if(this.C06_L.getNumericValue()>0){if(this.C06_E.getValue()>=this.C07_E.getValue()){this.setMsgMaggioreUguale();}
else{this.setMsgMinore();}}else{this.perc.setText('');}},this);this.C08_E=new Ext.ux.Namirial.form.NumberField({name:'C08_E',fieldLabel:'Imposta sostitutiva sul mutuo',decimalPrecision:2,maxValue:99999999999});this.C08_E.on('change',function(field){this.C08_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.C08_L=new Ext.ux.Namirial.form.NumberField({name:'C08_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.C08_L.on('change',function(field){this.C08_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.C09_E=new Ext.ux.Namirial.form.NumberField({name:'C09_E',fieldLabel:'Spese per autorizzazione del Giudice tutelare alla stipula del contratto',decimalPrecision:2,maxValue:99999999999});this.C09_E.on('change',function(field){this.C09_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.C09_L=new Ext.ux.Namirial.form.NumberField({name:'C09_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.C09_L.on('change',function(field){this.C09_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.C10_E=new Ext.ux.Namirial.form.NumberField({name:'C10_E',fieldLabel:'Spese per procedimenti di esecuzione individuale o concorsuale',decimalPrecision:2,maxValue:99999999999});this.C10_E.on('change',function(field){this.C10_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.C10_L=new Ext.ux.Namirial.form.NumberField({name:'C10_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.C10_L.on('change',function(field){this.C10_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.NC06_E=new Ext.ux.Namirial.form.NumberField({name:'NC06_E',fieldLabel:'Spese notarili per il contratto di mutuo',decimalPrecision:2,maxValue:99999999999});this.NC06_E.on('change',function(field){this.NC06_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.NC06_L=new Ext.ux.Namirial.form.NumberField({name:'NC06_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.NC06_L.on('change',function(field){this.NC06_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.NC07_E=new Ext.ux.Namirial.form.NumberField({name:'NC07_E',fieldLabel:'Spese di iscrizione e cancellazione dell\'ipoteca',decimalPrecision:2,maxValue:99999999999});this.NC07_E.on('change',function(field){this.NC07_L.setValue(EuroLire(field.getValue(),false));this.aggiornaTotali();},this);this.NC07_L=new Ext.ux.Namirial.form.NumberField({name:'NC07_L',hideLabel:true,labelSeparator:'',decimalPrecision:0,maxValue:99999999999});this.NC07_L.on('change',function(field){this.NC07_E.setValue(EuroLire(field.getValue(),true));this.aggiornaTotali();},this);this.formPanel=new Ext.form.FormPanel({name:'formPanel',defaults:{border:false,bodyStyle:SFONDO_FORM},items:[this.titolo,{layout:'column',defaults:{border:false,bodyStyle:SFONDO_FORM+'text-align:center'},items:[{layout:'form',labelWidth:340,width:495,items:[this.IMPORTO]}]},{layout:'column',defaults:{border:false,bodyStyle:SFONDO_FORM+'text-align:center'},items:[{layout:'form',width:355,items:[new Ext.form.Label({html:'&nbsp;'})]},{layout:'form',width:128,items:[this.labelEuro]},{width:155,layout:'form',items:[this.labelLire]}]},{layout:'column',defaults:{border:false,bodyStyle:SFONDO_FORM},items:[{labelWidth:350,width:500,layout:'form',items:[this.C01_E,this.C02_E,this.C03_E,this.C04_E,this.C05_E,this.NC06_E,this.NC07_E,this.C08_E,this.C09_E,this.C10_E,this.C06_E,this.C07_E]},{width:150,layout:'form',items:[this.C01_L,this.C02_L,this.C03_L,this.C04_L,this.C05_L,this.NC06_L,this.NC07_L,this.C08_L,this.C09_L,this.C10_L,this.C06_L,this.C07_L]}]},{height:20},this.labelFooter,this.textCfisc,this.textTipo,this.textPerc]});this.store_calcE7=new Ext.ux.Namirial.data.GearsStore({gearsConn:conn,dbname:GDATABASE,selectFrom:CALC_E7_TAB,selectFilter:"CFISC = '"+this.CFISC+"'",fields:structStore.getFields(CALC_E7_TAB)});this.store_calcE7.on('load',function(store,rec){if(this.store_calcE7.getCount()>0){this.tipo=UPDATE;this.formPanel.getForm().loadRecord(rec[0]);if(this.textTipo.getValue()==1){this.setMsgMaggioreUguale();}
if(this.textTipo.getValue()==2){this.setMsgMinore();}}else{this.tipo=INSERT;}},this);Ext.ux.Namirial.form.CalcE7.superclass.constructor.call(this,{id:WINDOW_CALCE7,resizable:false,constrain:true,title:'Rideterminazione interessi passivi',width:700,height:520,defaults:{border:false,bodyStyle:'padding:10px;'+SFONDO_FORM},items:[this.formPanel],buttonAlign:'right',buttons:[this.tb_Salva,this.tb_Annulla]});this.on('show',function(){this.store_calcE7.load();},this)}
catch(e){getToastMsg(MSG_TEXT,'data entry Rideterminazione interessi passivi');log.error("Ext.ux.Namirial.form.CalcE7#1 -> ",e);}},showWin:function(){if(Ext.isEmpty(Ext.WindowMgr.get(WINDOW_CALCE7))){this.show();}},aggiornaTotali:function(){this.aggiornaTotEuro();this.aggiornaTotLire();},aggiornaTotEuro:function(){var totEuro=this.C01_E.getNumericValue()+this.C02_E.getNumericValue()+this.C03_E.getNumericValue()+this.C04_E.getNumericValue()+this.C05_E.getNumericValue()+this.NC06_E.getNumericValue()+this.NC07_E.getNumericValue()+this.C08_E.getNumericValue()+this.C09_E.getNumericValue()+this.C10_E.getNumericValue();this.C06_E.setValue(totEuro);},aggiornaTotLire:function(){var totLire=this.C01_L.getNumericValue()+this.C02_L.getNumericValue()+this.C03_L.getNumericValue()+this.C04_L.getNumericValue()+this.C05_L.getNumericValue()+this.NC06_L.getNumericValue()+this.NC07_L.getNumericValue()+this.C08_L.getNumericValue()+this.C09_L.getNumericValue()+this.C10_L.getNumericValue();this.C06_L.setValue(totLire);},annulla:function(){this.close();},salva:function(){var sql;if(this.formPanel.getForm().isValid()){if(this.tipo==UPDATE){var whereCl="CFISC='"+this.CFISC+"'";sql=generateQueryFromForm(CALC_E7_TAB,this.formPanel,'UPDATE',whereCl);}else{sql=generateQueryFromForm(CALC_E7_TAB,this.formPanel,'INSERT');}
conn.exec(sql);var oldval=this.targetField.getValue();var newal=this.C06_E.getNumericValue();this.targetField.setValue(newal);this.targetField.fireEvent('change',this.targetField,newal,oldval);this.close();}else{Toast('Attenzione','Compilare i campi obbligatori')}},setMsgMaggioreUguale:function(){this.textPerc.setValue(100);this.textTipo.setValue(1);this.labelFooter.setText("Costo di acquisto dell'immobile di ammontare superiore o uguale al capitale preso in prestito. L'agevolazione fiscale del 19% pu"+UNI_O+" essere calcolata sulla somma totale degli interessi ed oneri accessori al contratto di mutuo sostenuti nell'anno, entro il limite di "+UNI_EURO+" 4.000,00.");},setMsgMinore:function(){this.setPercentuale();this.labelFooter.setText("Costo di acquisto dell'immobile di ammontare inferiore al capitale preso in prestito. L'agevolazione fiscale del 19% per gli interessi ed oneri accessori al mutuo va limitata al "+this.perc+"% degli stessi, entro il valore massimo di "+UNI_EURO+" 4.000,00.");},setPercentuale:function(){this.textTipo.setValue(2);this.perc=((this.C06_E.getNumericValue()/this.C07_E.getNumericValue())*100).toFixed(2);this.textPerc.setValue(this.perc);}});

