/*
 * JSMin
 * Javascript Compressor
 * http://www.crockford.com/
 * http://www.smallsharptools.com/Projects/Packer/
*/

// V:\1.1.007\js\form\QE\Ext.ux.Namirial.form.QESezV_Popup.js

Ext.ns('Ext.ux');Ext.ns('Ext.ux.Namirial');Ext.ns('Ext.ux.Namirial.form');Ext.ux.Namirial.form.QESezV_Popup=Ext.extend(Ext.Window,{constructor:function(c){c=c||{};try{this.record=c.record||null;this.cfisc=dichiarazione.getCurrentCfisc();this.store=c.store||null;this.dataIndex='E38_1';this.flag=false;this.tb_Salva=new Ext.Toolbar.Button({text:'Salva',icon:IMG_NUOVO,disabled:false,scope:this,iconCls:'x-btn-text-icon',tooltip:{title:'Salva',text:'Salva'},handler:this.salva});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.codE=new Ext.form.TextField({name:'E_ID',hidden:true,hideLabel:true,labelSeparator:''})
this.CFISC_DIC=new Ext.ux.Namirial.form.TextField({name:'CFISC',hidden:true,hideLabel:true,labelSeparator:'',value:this.cfisc})
this.identificativoImmobile=new Ext.ux.Namirial.form.TextField({fieldLabel:'Identificativo immobile',name:'E_IMMOBILE',width:200,allowBlank:false})
this.tipoIntervento=new Ext.ux.Namirial.form.ComboBox({name:'E_TIPO',width:95,readOnly:true,labelAlign:'top',fieldLabel:'<b>1</b> - Tipo Intervento',store:Ext.ux.Namirial.QE.Tipo,tpl:COMBO_WRAP,mode:'local',allowBlank:false,triggerAction:'all',selectOnFocus:true,listWidth:340,showValue:true})
this.tipoIntervento.on('change',function(field){this.verifica5(field);},this);this.annoSpesa=new Ext.ux.Namirial.form.NumberField({fieldLabel:'<b>2</b> - Anno Spesa',name:'E_ANNO',width:75,allowBlank:false,validateOnBlur:false,validationEvent:'change',validator:controlloE5_ANNO.createDelegate(this),autoCreate:MAX_LENGHT(4)})
this.annoSpesa.on('change',function(field){this.ripartizione.validate();this.verifica1();this.verifica3();},this);this.continuazione=new Ext.ux.Namirial.form.Checkbox({name:'E_CONTINUAZIONE',disabled:true,fieldLabel:'<b>3</b> - Continuazione',qtip:{text:'Spese sostenute per lavori iniziati nel 2007 e ancora in corso nel 2008'}})
this.continuazione.on('check',function(field,checked){this.verifica4(checked);this.spesaSostenuta.validate();},this);this.labelRate=new Ext.form.Label({html:'<p align="center"><b>Rate</b></p><hr width="190" size="1">'})
this.ripartizione=new Ext.ux.Namirial.form.ComboBox({name:'E_RATE',width:75,readOnly:true,labelAlign:'top',fieldLabel:'<b>4</b> - Ripartizione',store:Ext.ux.Namirial.QE.RateSezV,mode:'local',allowBlank:false,tpl:COMBO_WRAP,triggerAction:'all',selectOnFocus:true,listWidth:100,showValue:true,validateOnBlur:false,validationEvent:'change',validator:controlloE5_RATE.createDelegate(this)})
this.rataUtilizzata=new Ext.ux.Namirial.form.TextField({fieldLabel:'<b>5</b> - Rata utilizzata',name:'E_NRATA',disabled:true,width:85})
this.labelSpesa=new Ext.form.Label({html:'<p align="center"><b>6 - Spesa totale</b></p><hr width="495" size="1">'})
this.spesaSostenuta=new Ext.ux.Namirial.form.NumberField({fieldLabel:'Spesa sostenuta',name:'E_IMPORTO',dataIndex:this.dataIndex,width:120,readOnly:true,allowDecimals:false,allowNegative:false,allowBlank:false,asString:true,validateOnBlur:false,validationEvent:'change',validator:controlloE5_IMPORTO.createDelegate(this)})
this.spesaSostenuta.on('change',function(){this.verifica2();this.spesaSostenuta.validate();},this);this.spesaAnnoPrecedente=new Ext.ux.Namirial.form.NumberField({fieldLabel:'Spesa anno precedente',name:'E_SPESE',width:120,allowDecimals:false,allowNegative:false,asString:true,disabled:true})
this.spesaAnnoPrecedente.on('change',function(field){this.spesaSostenuta.validate();},this);this.spesaDetraibile=new Ext.ux.Namirial.form.NumberField({fieldLabel:'Spesa detraibile',name:'E_DETRAIBILE',width:120,allowDecimals:false,allowNegative:false,asString:true,disabled:true})
this.speseButton=new Ext.Button({iconCls:'x-btn-icon',icon:IMG_PROP,width:30,disabled:true,scope:this,handler:function(){if(Ext.isEmpty(this.codE.getValue())){this.codE.setValue(generaCodiceRandom());}
var doc=new Ext.ux.Namirial.form.DettagliQE({totalField:this.spesaSostenuta,idRecord:this.codE.getValue(),recordStore:this.dettStore});doc.apri();}})
this.contentPanel=new Ext.FormPanel({title:'E38 - SPESE PER INTERVENTI DI RISPARMIO ENERGETICO PER LE QUALI SPETTA LA DETRAZIONE DEL 55%',name:'contentPanel',labelAlign:'top',frame:true,bodyStyle:'background:transparent;',layout:'form',items:[{layout:'column',items:[{layout:'form',width:200,items:[this.identificativoImmobile]},{layout:'form',width:300,style:'padding-left: 92px; padding-top: 20px;',items:[this.labelRate]}]},{layout:'column',items:[{layout:'form',width:110,items:[this.tipoIntervento]},{layout:'form',width:90,items:[this.annoSpesa]},{layout:'form',width:105,items:[this.continuazione]},{layout:'form',width:90,items:[this.ripartizione]},{layout:'form',width:105,items:[this.rataUtilizzata]}]},{layout:'form',width:490,items:[this.labelSpesa]},{layout:'column',items:[{layout:'form',width:125,items:[this.spesaSostenuta]},{layout:'form',width:50,items:[{height:17},this.speseButton]},{layout:'form',width:130,items:[this.spesaAnnoPrecedente]},{layout:'form',width:130,items:[this.spesaDetraibile]}]}]})
try{this.basicForm=new Ext.form.BasicForm();this.basicForm.add(this.identificativoImmobile);this.basicForm.add(this.tipoIntervento);this.basicForm.add(this.annoSpesa);this.basicForm.add(this.continuazione);this.basicForm.add(this.ripartizione);this.basicForm.add(this.rataUtilizzata);this.basicForm.add(this.spesaSostenuta);this.basicForm.add(this.spesaAnnoPrecedente);this.basicForm.add(this.spesaDetraibile);this.basicForm.add(this.codE);this.basicForm.add(this.CFISC_DIC);this.dettStore=new Ext.ux.Namirial.data.GearsStore({gearsConn:conn,dbname:GDATABASE,selectFrom:QEDETT_TAB,tableId:'keyId',fields:structStore.getFields(QEDETT_TAB),autoCommit:false});}catch(e){log.error('ERRORE CREAZIONE BASIC FORM Ext.ux.Namirial.form.QESezV_Popup -> ',e);}
this.messaggio=new Ext.form.Label({html:'<br><b style="color:red">Il limite massimo di detrazione deve intendersi riferito all\'unit'+UNI_A+' immobiliare e, pertanto, andr'+UNI_A+' suddiviso tra i soggetti che partecipano alla spesa, in ragione dell\'onere da ciascuno effettivamente sostenuto</b>'})
Ext.ux.Namirial.form.QESezV_Popup.superclass.constructor.call(this,{id:WINDOW_QESEZV,draggable:false,resizable:false,constrain:true,title:'Quadro E - ONERI E SPESE',width:730,height:475,layout:'form',items:[this.contentPanel,{bodyStyle:PADDING_5+SFONDO_TRASPARENTE+' border: none',items:[this.messaggio]}],tbar:[this.tb_Salva,this.tb_Annulla]});this.on('show',function(){hideLoading();if(!Ext.isEmpty(this.record)){this.basicForm.loadRecord(this.record);this.dataIndex='E38_'+this.record.get('E_TIPO');this.dettStore.selectFilter="CFISC = '"+this.cfisc+"' AND DETTAGLIO = '"+this.dataIndex+"' AND ID ='"+this.record.get('E_ID')+"'";this.dettStore.load();this.verifica3();this.verifica4(this.continuazione.getValue());this.spesaSostenuta.validate();this.speseButton.enable();}
this.flag=true;},this)}
catch(e){getToastMsg(MSG_TEXT,'data entry QE Sez. V ');log.error("Ext.ux.Namirial.form.QESezV_popup#1 -> ",e);}},salva:function(){var sql;if(this.basicForm.isValid()){if(!Ext.isEmpty(this.record)){sql=generateQueryFromForm(QEV_TAB,this.basicForm,'UPDATE',"E_ID='"+this.codE.getValue()+"'",null,'basicform');}
else{if(Ext.isEmpty(this.codE.getValue())){this.codE.setValue(generaCodiceRandom());}
sql=generateQueryFromForm(QEV_TAB,this.basicForm,'INSERT',null,null,'basicform');}
try{conn.exec(sql);conn.exec(getQuery(DEL_QE_DETT_ID,[this.spesaSostenuta.dataIndex,this.cfisc,this.codE.getValue()]));this.dettStore.each(function(record){conn.exec(generateQuery(LOCAL,QEDETT_TAB,record.data,INSERT));})}
catch(e){log.error("Ext.ux.Namirial.form.QESezV_Popup#2 - Salvataggio QEV -> ",e)
getToastMsg(MSG_ERROR_SAVE);}
this.close();if(this.store)
this.store.reload();}else{getToastMsg(MSG_INVALID_FIELD);}},annulla:function(){this.close();},verifica1:function(){var anno=convertiStrNum(this.annoSpesa.getValue());if(anno>0&&this.annoSpesa.isValid()){var nrata=ANNO_DICHIARAZIONE-anno+1;if(nrata>0)
this.rataUtilizzata.setValue(nrata);else
this.rataUtilizzata.setValue('');}
else
this.rataUtilizzata.setValue('');},verifica2:function(){var anno=convertiStrNum(this.annoSpesa.getValue());var tipo=this.tipoIntervento.getValue();var spesaSost=convertiStrNum(this.spesaSostenuta.getValue());var spesePrec=convertiStrNum(this.spesaAnnoPrecedente.getValue());var impmax;switch(tipo){case'1':impmax=181818;break;case'2':case'3':impmax=109091;break;case'4':impmax=54545;break;}
var max=impmax-spesePrec;if(max<0)max=0;if(spesaSost>max)
this.spesaDetraibile.setValue(max);else
this.spesaDetraibile.setValue(spesaSost);},verifica3:function(){var anno=convertiStrNum(this.annoSpesa.getValue());if(anno==QEV_ANNO_MIN){this.continuazione.disable();this.continuazione.setValue(false);}
else{this.continuazione.enable();}},verifica4:function(checked){if(checked){this.spesaAnnoPrecedente.enable();}
else{if(this.flag)this.spesaAnnoPrecedente.setValue('');this.spesaAnnoPrecedente.disable();}},verifica5:function(field){var tipo=field.getValue();if(this.flag){this.spesaSostenuta.setValue('');this.dettStore.removeAll();if(!Ext.isEmpty(this.record)){conn.exec(getQuery(DEL_QE_DETT_ID,[this.dataIndex,this.cfisc,this.record.get('E_ID')]))}}
this.dataIndex='E38_'+tipo;this.spesaSostenuta.dataIndex=this.dataIndex;this.speseButton.enable();}})

