/*
 * JSMin
 * Javascript Compressor
 * http://www.crockford.com/
 * http://www.smallsharptools.com/Projects/Packer/
*/

// V:\1.1.007\js\form\QE\Ext.ux.Namirial.form.DettagliQEParticolare1.js

Ext.ns('Ext.ux','Ext.ux.Namirial','Ext.ux.Namirial.form');Ext.ux.Namirial.form.DettagliQEParticolare1=Ext.extend(Ext.ux.Namirial.form.DettagliQE,{constructor:function(c){c=c||{};connection=c.connection||null;var stipula=false;var contrib=true;var percent=true;var campo_singolo=false;var max;switch(c.totalField.dataIndex){case'E7':stipula=true;var contributi=new Ext.ux.Namirial.form.NumberField({name:'E7_CONTRIBUTI',width:90,allowNegative:false,allowZero:true,decimalPrecision:2,disabled:true,labelSeparator:'',fieldLabel:'Contributi statali in conto interessi',returnAsString:true});BF_QE.add(contributi);contributi.on({scope:this,change:function(){var tot_quote=this.store.stringSum('IMPORTO');contr=contributi.getValue();if((tot_quote-contributi.getValue())>0){importo=(tot_quote-contributi.getValue());}
else{importo=0;}
this.totale_quote.setValue(importo.toFixed(2));if(importo.toFixed(0)>E7_MAX){this.importo_detrazione.setValue(E7_MAX);}
else{this.importo_detrazione.setValue(importo.toFixed(0));}}});var percentuale_intestazione=new Ext.ux.Namirial.form.NumberField({name:'E7_PERC',width:50,allowNegative:false,allowZero:true,decimalPrecision:2,maxValue:100,minValue:0.01,disabled:true,labelStyle:'color: #E00505; font-weight: bold;',labelSeparator:'',fieldLabel:'Percentuale di intestazione/contitolarit\u00E0',allowBlank:false,allowZero:true,returnAsString:true});BF_QE.add(percentuale_intestazione);var data_stipula=new Ext.ux.Namirial.form.ComboBox({name:'E7_STIPULA',upperCase:false,width:250,listWidth:250,disabled:true,fieldLabel:'Data di stipula o accollo del mutuo',allowBlank:false,store:Ext.ux.Namirial.QE.Rigo7,tpl:COMBO_STANDARD,mode:'local',triggerAction:'all',editable:false,forceSelection:true});percentuale_intestazione.on('change',function(field){if(data_stipula.getValue()==0){E7_MAX=4000;}else{E7_MAX=4000*(percentuale_intestazione.getNumericValue()/100);}
this.setTotali();},this)
data_stipula.on('select',function(combo,record,index){if(index==0){E7_MAX=4000;}else{E7_MAX=4000*(percentuale_intestazione.getNumericValue()/100);}
this.setTotali();},this)
BF_QE.add(data_stipula);var secondoPannello=new Ext.Panel({width:300,labelWidth:240,items:percentuale_intestazione},{width:10,defaults:{border:false,bodyStyle:SFONDO_TRASPARENTE},items:[{height:5},{xtype:'label',text:'%'}]})
break;case'E8':max=2066;var contributi=new Ext.ux.Namirial.form.NumberField({name:'E8_CONTRIBUTI',width:90,allowNegative:false,allowZero:true,decimalPrecision:2,disabled:true,labelSeparator:'',fieldLabel:'Contributi statali in conto interessi',returnAsString:true});BF_QE.add(contributi);contributi.on({scope:this,change:function(){var tot_quote=this.store.stringSum('IMPORTO');contr=contributi.getValue();if((tot_quote-contributi.getValue())>0){importo=(tot_quote-contributi.getValue());}
else{importo=0;}
this.totale_quote.setValue(importo.toFixed(2));if(importo.toFixed(0)>max){this.importo_detrazione.setValue(max);}
else{this.importo_detrazione.setValue(importo.toFixed(0));}}});var percentuale_intestazione=new Ext.ux.Namirial.form.NumberField({name:'E8_PERC',width:50,allowNegative:false,allowZero:true,decimalPrecision:2,maxValue:100,minValue:0.01,disabled:true,labelStyle:'color: #E00505; font-weight: bold;',labelSeparator:'',fieldLabel:'Percentuale di intestazione/contitolarit\u00E0',allowBlank:false,allowZero:true,returnAsString:true});BF_QE.add(percentuale_intestazione);var secondoPannello=new Ext.Panel({width:300,labelWidth:240,items:percentuale_intestazione},{width:10,defaults:{border:false,bodyStyle:SFONDO_TRASPARENTE},items:[{height:5},{xtype:'label',text:'%'}]})
break;case'E9':max=(2582*perc)/100;var contributi=new Ext.ux.Namirial.form.NumberField({name:'E9_CONTRIBUTI',width:90,allowNegative:false,allowZero:true,decimalPrecision:2,disabled:true,labelSeparator:'',fieldLabel:'Contributi statali in conto interessi',returnAsString:true});BF_QE.add(contributi);contributi.on({scope:this,change:function(){var tot_quote=this.store.stringSum('IMPORTO');contr=contributi.getValue();perc=percentuale_intestazione.getValue();max=(2582*perc)/100;if((tot_quote-contributi.getValue())>0){importo=(tot_quote-contributi.getValue());}
if((tot_quote-contributi.getValue())>0){importo=(tot_quote-contributi.getValue());}
else{importo=0;}
this.totale_quote.setValue(importo.toFixed(2));if(importo.toFixed(0)>max){this.importo_detrazione.setValue(max.toFixed(0));}
else{this.importo_detrazione.setValue(importo.toFixed(0));}}});var percentuale_intestazione=new Ext.ux.Namirial.form.NumberField({name:'E9_PERC',width:50,allowNegative:false,allowZero:true,decimalPrecision:2,maxValue:100,minValue:0.01,disabled:true,labelStyle:'color: #E00505; font-weight: bold;',labelSeparator:'',fieldLabel:'Percentuale di intestazione/contitolarit\u00E0',allowBlank:false,allowZero:true,returnAsString:true});BF_QE.add(percentuale_intestazione);percentuale_intestazione.on({scope:this,change:function(){var tot_quote=this.store.stringSum('IMPORTO');contr=contributi.getValue();perc=percentuale_intestazione.getValue();max=(2582*perc)/100;if((tot_quote-contributi.getValue())>0){importo=(tot_quote-contributi.getValue());}
else{importo=0;}
this.totale_quote.setValue(importo.toFixed(2));if(importo.toFixed(0)>max){this.importo_detrazione.setValue(max.toFixed(0));}
else{this.importo_detrazione.setValue(importo.toFixed(0));}}});var secondoPannello=new Ext.Panel({width:300,labelWidth:240,items:percentuale_intestazione},{width:10,defaults:{border:false,bodyStyle:SFONDO_TRASPARENTE},items:[{height:5},{xtype:'label',text:'%'}]})
break;case'E10':stipula=true;max=(2582*perc)/100;var contributi=new Ext.ux.Namirial.form.NumberField({name:'E10_CONTRIBUTI',width:90,allowNegative:false,allowZero:true,decimalPrecision:2,disabled:true,labelSeparator:'',fieldLabel:'Contributi statali in conto interessi',returnAsString:true});BF_QE.add(contributi);contributi.on({scope:this,change:function(){var tot_quote=this.store.stringSum('IMPORTO');contr=contributi.getValue();perc=percentuale_intestazione.getValue();if(perc==''){perc=0;}
max=(2582*perc)/100;if((tot_quote-contributi.getValue())>0){importo=(tot_quote-contributi.getValue());}
else{importo=0;}
this.totale_quote.setValue(importo.toFixed(2));if(importo.toFixed(0)>max){this.importo_detrazione.setValue(max.toFixed(0));}
else{this.importo_detrazione.setValue(importo.toFixed(0));}}});var percentuale_intestazione=new Ext.ux.Namirial.form.NumberField({name:'E10_PERC',width:50,allowNegative:false,allowZero:true,decimalPrecision:2,maxValue:100,minValue:0.01,disabled:true,labelStyle:'color: #E00505; font-weight: bold;',labelSeparator:'',fieldLabel:'Percentuale di intestazione/contitolarit\u00E0',allowBlank:false,allowZero:true,returnAsString:true});BF_QE.add(percentuale_intestazione);percentuale_intestazione.on({scope:this,change:function(){var tot_quote=this.store.stringSum('IMPORTO');contr=contributi.getValue();perc=percentuale_intestazione.getValue();max=(2582*perc)/100;if((tot_quote-contributi.getValue())>0){importo=(tot_quote-contributi.getValue());}
else{importo=0;}
this.totale_quote.setValue(importo.toFixed(2));if(importo.toFixed(0)>max){this.importo_detrazione.setValue(max.toFixed(0));}
else{this.importo_detrazione.setValue(importo.toFixed(0));}}});this.storeStipula=new Ext.data.SimpleStore({fields:['chiave','valore'],data:Ext.ux.Namirial.QE.Rigo7});var data_stipula=new Ext.ux.Namirial.form.ComboBox({name:'E10_STIPULA',upperCase:false,width:150,listWidth:250,disabled:true,fieldLabel:'Data di stipula o accollo del mutuo',allowBlank:false,store:this.storeStipula,mode:'local',displayField:'valore',valueField:'chiave',triggerAction:'all',editable:false,forceSelection:true});BF_QE.add(data_stipula);var secondoPannello=new Ext.Panel({width:300,labelWidth:240,items:percentuale_intestazione},{width:10,defaults:{border:false,bodyStyle:SFONDO_TRASPARENTE},items:[{height:5},{xtype:'label',text:'%'}]})
break;case'E11':var contributi=new Ext.ux.Namirial.form.NumberField({name:'E11_CONTRIBUTI',width:90,allowNegative:false,allowZero:true,decimalPrecision:2,disabled:true,labelSeparator:'',fieldLabel:'Contributi statali in conto interessi',returnAsString:true});BF_QE.add(contributi);contributi.on({scope:this,change:function(){var tot_quote=this.store.stringSum('IMPORTO');contr=contributi.getValue();if((tot_quote-contributi.getValue())>0){importo=(tot_quote-contributi.getValue());}
else{importo=0;}
this.totale_quote.setValue(importo.toFixed(2));this.importo_detrazione.setValue(importo.toFixed(0));}});var percentuale_intestazione=new Ext.ux.Namirial.form.NumberField({name:'E11_PERC',width:50,allowNegative:false,allowZero:true,decimalPrecision:2,maxValue:100,minValue:0.01,disabled:true,labelStyle:'color: #E00505; font-weight: bold;',labelSeparator:'',fieldLabel:'Percentuale di intestazione/contitolarit\u00E0',allowBlank:false,allowZero:true,returnAsString:true});BF_QE.add(percentuale_intestazione);percentuale_intestazione.on({scope:this,change:function(){var tot_quote=this.store.stringSum('IMPORTO');contr=contributi.getValue();if((tot_quote-contributi.getValue())>0){importo=(tot_quote-contributi.getValue());}
else{importo=0;}
this.totale_quote.setValue(importo.toFixed(2));this.importo_detrazione.setValue(importo.toFixed(0));}});var secondoPannello=new Ext.Panel({width:300,labelWidth:240,items:percentuale_intestazione},{width:10,defaults:{border:false,bodyStyle:SFONDO_TRASPARENTE},items:[{height:5},{xtype:'label',text:'%'}]})
break;case'E17':campo_singolo=true;contrib=false;max=1000;case'E17':percentuale_intestazione=new Ext.ux.Namirial.form.NumberField({name:'E17_PERC',width:50,allowNegative:false,allowZero:true,decimalPrecision:2,maxValue:100,minValue:0.01,disabled:true,labelStyle:'color: #E00505; font-weight: bold;',labelSeparator:'',fieldLabel:'Percentuale propriet\u00E0 abitazione',allowBlank:true,value:0,returnAsString:true});BF_QE.add(percentuale_intestazione);percentuale_intestazione.on({scope:this,change:function(){var tot_detrazione=this.store.stringSum('IMPORTO');perc=percentuale_intestazione.getValue();this.importo_detrazione.setValue(((tot_detrazione*perc)/100).toFixed(0));}});var secondoPannello=new Ext.Panel({width:300,labelWidth:240,items:percentuale_intestazione},{width:10,defaults:{border:false,bodyStyle:SFONDO_TRASPARENTE},items:[{height:5},{xtype:'label',text:'%'}]})
campo_singolo=true;break;case'E27_1':percent=false;max=3615;contributi=new Ext.ux.Namirial.form.NumberField({name:'E27_1_CONTRIBUTI',width:80,allowNegative:false,allowZero:true,decimalPrecision:2,disabled:true,labelSeparator:'',fieldLabel:'Contributi versati a enti e casse aventi aventi fini assistenziali (p.51 del CUD)',returnAsString:true});BF_QE.add(contributi);contributi.on({scope:this,change:function(){var tot_quote=this.store.stringSum('IMPORTO');contr=contributi.getValue();if((max-contr)>0){importo=tot_quote.toFixed(2);}
else{importo=0;}
if(importo>max){this.totale_quote.setValue((max-contr).toFixed(2));this.importo_detrazione.setValue((max-contr).toFixed(0));}
else{this.totale_quote.setValue(parseInt(importo).toFixed(2));this.importo_detrazione.setValue(parseInt(importo).toFixed(0));}}});secondoPannello=new Ext.Panel({width:330,labelWidth:240,items:contributi})
campo_singolo=true;break;};var storeQE=new Ext.ux.Namirial.data.GearsStore({gearsConn:conn,dbname:GDATABASE,selectFrom:QE_TAB,tableId:'keyId',selectFilter:"CFISC = '"+dichiarazione.getCurrentCfisc()+"'",fields:structStore.getFields(QE_TAB),autoLoad:true,autoCommit:true});var stipulaPanel;if(stipula){stipulaPanel=new Ext.Panel({layout:'form',border:false,bodyStyle:SFONDO_TRASPARENTE+PADDING_10,columnWidth:.45,labelAlign:'top',items:data_stipula})}else{stipulaPanel=new Ext.Panel({columnWidth:.45,layout:'form',bodyStyle:SFONDO_TRASPARENTE+PADDING_10,border:false});}
var contributiPanel;if(campo_singolo){contributiPanel=new Ext.Panel({columnWidth:.5,bodyStyle:SFONDO_TRASPARENTE+PADDING_5+'border-right: 1px solid '+BORDER_COLOR,labelWidth:200,border:false,layout:'column',defaults:{layout:'form',border:false,bodyStyle:SFONDO_TRASPARENTE},items:[secondoPannello]})}else{contributiPanel=new Ext.Panel({columnWidth:.5,bodyStyle:SFONDO_TRASPARENTE+PADDING_5+'border-right: 1px solid '+BORDER_COLOR,border:false,layout:'form',labelWidth:200,items:[contributi,{layout:'column',bodyStyle:SFONDO_TRASPARENTE,border:false,defaults:{layout:'form',border:false,bodyStyle:SFONDO_TRASPARENTE},items:[{width:300,labelWidth:240,items:percentuale_intestazione},{width:10,defaults:{border:false,bodyStyle:SFONDO_TRASPARENTE},items:[{height:5},{xtype:'label',text:'%'}]}]}]})}
var intestazionePanel=new Ext.FormPanel({border:false,layout:'column',bodyStyle:SFONDO_TRASPARENTE+PADDING_5+'border-top: 1px solid '+BORDER_COLOR,items:[contributiPanel,stipulaPanel]})
c.optionalPanel=intestazionePanel;c.gridHeight=170;Ext.ux.Namirial.form.DettagliQEParticolare1.superclass.constructor.call(this,c);function setContribPanel(){var state;if(this.store.getCount()>0){state=false;if(contrib){contributi.setDisabled(state);}
if(this.cod=='E17'&&(this.store.getAt(0).get('IMPORTO')=='0,00'||this.store.getAt(0).get('IMPORTO')=='')){percentuale_intestazione.setRawValue('');percentuale_intestazione.setDisabled(!state);}
else if(percent){percentuale_intestazione.setDisabled(state);}
if(stipula){data_stipula.setDisabled(state);}}
else{state=true;if(contrib){contributi.setDisabled(state);contributi.setRawValue('');}
if(percent){percentuale_intestazione.setDisabled(state);percentuale_intestazione.setRawValue('');}
if(stipula){data_stipula.setDisabled(state);data_stipula.setRawValue('');}}}
this.store.on({'load':{fn:setContribPanel,scope:this},'remove':{fn:setContribPanel,scope:this},'add':{fn:setContribPanel,scope:this}},this)
this.winDettagliQE.on('show',function(){var record;var rec;switch(c.totalField.dataIndex){case'E7':record=conn.query(getQuery(SEL_QE_2,[dichiarazione.getCurrentCfisc()]));rec=new Ext.data.Record(record.rows[0]);BF_QE.loadRecord(rec);break;case'E8':record=conn.query(getQuery(SEL_QE_4,[dichiarazione.getCurrentCfisc()]));rec=new Ext.data.Record(record.rows[0]);BF_QE.loadRecord(rec);break;case'E9':record=conn.query(getQuery(SEL_QE_5,[dichiarazione.getCurrentCfisc()]));rec=new Ext.data.Record(record.rows[0]);BF_QE.loadRecord(rec);break;case'E10':record=conn.query(getQuery(SEL_QE_7,[dichiarazione.getCurrentCfisc()]));rec=new Ext.data.Record(record.rows[0]);BF_QE.loadRecord(rec);break;case'E11':record=conn.query(getQuery(SEL_QE_8,[dichiarazione.getCurrentCfisc()]));rec=new Ext.data.Record(record.rows[0]);BF_QE.loadRecord(rec);break;case'E17':record=conn.query(getQuery(SEL_QE_6,[dichiarazione.getCurrentCfisc()]));rec=new Ext.data.Record(record.rows[0]);BF_QE.loadRecord(rec);break;case'E27_1':record=conn.query(getQuery(SEL_QE_9,[dichiarazione.getCurrentCfisc()]));rec=new Ext.data.Record(record.rows[0]);BF_QE.loadRecord(rec);break;}},this);this.winDettagliQE.on('close',function(){switch(c.totalField.dataIndex){case'E7':BF_QE.remove(contributi);BF_QE.remove(percentuale_intestazione);BF_QE.remove(data_stipula);break;case'E8':BF_QE.remove(contributi);BF_QE.remove(percentuale_intestazione);break;case'E9':BF_QE.remove(contributi);BF_QE.remove(percentuale_intestazione);break;case'E10':BF_QE.remove(contributi);BF_QE.remove(percentuale_intestazione);BF_QE.remove(data_stipula);break;case'E11':BF_QE.remove(contributi);BF_QE.remove(percentuale_intestazione);break;case'E17':BF_QE.remove(percentuale_intestazione);break;case'E27_1':BF_QE.remove(contributi);break;}},this);}})

