Wtf.assignPlan=function(A){Wtf.apply(this,A);this.planAdd=[];this.plandel=[];this.displanAdd=[];this.displandel=[];this.schplanAdd=[];this.schplandel=[];this.pRecord=Wtf.data.Record.create([{name:"code",type:"string"},{name:"amount",type:"float"}]);this.pSM=new Wtf.grid.CheckboxSelectionModel({singleSelect:true});this.pReader=new Wtf.data.KwlJsonReader({root:"data"},this.pRecord);this.pStore=new Wtf.data.Store({proxy:new Wtf.data.HttpProxy({url:"jspfiles/admin/acastructure.jsp"}),reader:this.pReader});this.pCM=new Wtf.grid.ColumnModel([this.pSM,{header:"Plan",dataIndex:"code"},{header:"Amount",dataIndex:"amount"}]);this.pCM.defaultSortable=true;this.pGrid=new Wtf.grid.EditorGridPanel({ds:this.pStore,cm:this.pCM,sm:this.pSM,autoScroll:true,collapsible:true,layout:"fit",clicksToEdit:1,viewConfig:{forceFit:true,autoFill:true}});this.disRecord=Wtf.data.Record.create([{name:"code",type:"string"}]);this.disSM=new Wtf.grid.CheckboxSelectionModel({});this.disReader=new Wtf.data.KwlJsonReader({root:"data"},this.disRecord);this.disStore=new Wtf.data.Store({proxy:new Wtf.data.HttpProxy({url:"jspfiles/admin/acastructure.jsp"}),reader:this.pReader});this.disCM=new Wtf.grid.ColumnModel([this.disSM,{header:"Plan",dataIndex:"code"}]);this.disCM.defaultSortable=true;this.disGrid=new Wtf.grid.EditorGridPanel({ds:this.disStore,cm:this.disCM,sm:this.disSM,autoScroll:true,collapsible:true,layout:"fit",clicksToEdit:1,viewConfig:{forceFit:true,autoFill:true}});this.schRecord=Wtf.data.Record.create([{name:"code",type:"string"}]);this.schSM=new Wtf.grid.CheckboxSelectionModel({});this.schReader=new Wtf.data.KwlJsonReader({root:"data"},this.schRecord);this.schStore=new Wtf.data.Store({proxy:new Wtf.data.HttpProxy({url:"jspfiles/admin/acastructure.jsp"}),reader:this.schReader});this.schCM=new Wtf.grid.ColumnModel([this.schSM,{header:"Plan",dataIndex:"code"}]);this.schCM.defaultSortable=true;this.schGrid=new Wtf.grid.EditorGridPanel({ds:this.schStore,cm:this.schCM,sm:this.schSM,autoScroll:true,collapsible:true,layout:"fit",clicksToEdit:1,viewConfig:{forceFit:true,autoFill:true}});this.pStore.load({params:{type:46,userid:this.userid,programid:this.programid,flag:this.flag,typeflag:this.typeflag}});this.disStore.load({params:{type:47,userid:this.userid,programid:this.programid,flag:this.flag,typeflag:this.typeflag}});if(this.defaultplan==0){this.pStore.on("load",this.pStoreLoad,this);this.disStore.on("load",this.disStoreLoad,this)}else{if(this.defaultplan==1){this.planloadCount=0;this.pStore.on("load",function(){this.planloadCount++;if(this.planloadCount==2){this.pStoreLoad1()}},this);this.disStore.on("load",function(){this.planloadCount++;if(this.planloadCount==2){this.pStoreLoad1()}},this)}}this.otherRec=Wtf.data.Record.create([{name:"month"},{name:"amount",type:"float"}]);this.otherReader=new Wtf.data.JsonReader({root:"data"},this.otherRec);this.otherStore=new Wtf.data.Store({root:"data",reader:this.otherReader});this.otherCM=new Wtf.grid.ColumnModel([{header:"Month",dataIndex:"month"},{header:"Amount",dataIndex:"amount",editor:this.amountText=new Wtf.form.NumberField({allowNegative:false})}]);this.otherGrid=new Wtf.grid.EditorGridPanel({ds:this.otherStore,cm:this.otherCM,autoScroll:true,collapsible:true,layout:"fit",clicksToEdit:1,viewConfig:{forceFit:true,autoFill:true}});this.otherGrid.on("afteredit",this.editHandler,this);this.editWin=new Wtf.Window({title:"Select Plan",closable:true,modal:true,iconCls:"win",width:500,height:550,resizable:false,buttonAlign:"center",buttons:[{text:"Save",scope:this,handler:this.userPlanmap},{text:"Cancel",scope:this,handler:function(){this.editWin.close();this.planAdd=[];this.plandel=[];this.displanAdd=[];this.displandel=[];this.schplanAdd=[];this.schplandel=[];this.fireEvent("closewin")}}],layout:"border",items:[{region:"north",height:75,border:false,bodyStyle:"background:white;border-bottom:1px solid #bfbfbf;",html:getHeader("images/upload52.gif","Select Plan","Select Plan for Course.")},{region:"center",border:false,layout:"fit",items:[{border:false,bodyStyle:"background:transparent;",layout:"border",labelWidth:50,items:[{title:"Base Plans",region:"north",layout:"fit",border:false,height:150,items:this.pGrid},{region:"center",layout:"fit",border:false,items:[{title:"Discount Plans",region:"west",width:250,layout:"fit",border:false,items:this.disGrid}]},{region:"south",layout:"form",id:"planAssign_southReg",border:false,height:40,items:[this.southPanel=new Wtf.Panel({layout:"column",columnWidth:1,border:false,items:[{border:false,bodyStyle:"padding:0 0 0 20px;",columnWidth:0.5,items:this.spegrad=new Wtf.form.Checkbox({id:this.id+"installment",boxLabel:"Installment",hideLabel:true})},{layout:"form",border:false,columnWidth:0.5,bodyStyle:"padding:0 0 0 20px;",items:this.chk2=new Wtf.form.Checkbox({id:this.id+"flatFee",boxLabel:"Flat Fee",hideLabel:true})}]}),this.specialPanel=new Wtf.Panel({height:0,layout:"border",border:false,items:[{region:"center",layout:"fit",border:false,items:this.otherGrid}]})]}]}]}]});this.spegrad.on("check",this.spechkchange,this);this.editWin.show();Wtf.assignPlan.superclass.constructor.call(this,A)};Wtf.extend(Wtf.assignPlan,Wtf.Panel,{onRender:function(A){Wtf.assignPlan.superclass.onRender.call(this,A);this.addEvents={"refreshgrid":true,"closewin":true}},editHandler:function(A){if(A.row==this.otherStore.getCount()-1){this.otherStore.add(this.makeRecord((parseInt(A.row)+2)))}},addDataInGrid:function(){this.otherStore.removeAll();this.otherStore.add(this.makeRecord(1))},makeRecord:function(B){var A=new this.otherRec({month:"Month "+B});return A},spechkchange:function(A,B){if(B){this.specialPanel.setHeight(90);Wtf.getCmp("planAssign_southReg").setHeight(120);this.editWin.setHeight(600)}else{this.specialPanel.setHeight(0);Wtf.getCmp("planAssign_southReg").setHeight(40);this.editWin.setHeight(550)}},setInstallments:function(){Wtf.Ajax.requestEx({url:"jspfiles/admin/acastructure.jsp",method:"POST",params:{type:130,moduleid:this.userid}},this,function(response,option){var resp=eval("("+response+")");if(resp!=null&&resp.data!=null){var arr=[];for(var ctr=0;ctr<resp.data.length;ctr++){var p=new this.otherRec({month:"Month "+resp.data[ctr].monthid,amount:resp.data[ctr].amount});if(resp.data[ctr].pass==true){arr.push(p)}this.otherStore.add(p)}}},function(response,req){})},pStoreLoad:function(){var A=[];for(var B=0;B<this.plansel.length;B++){A.push(this.pStore.getAt(this.pStore.find("code",this.plansel[B])))}this.pSM.selectRecords(A);this.pSM.on("rowselect",this.planSelected,this);this.pSM.on("rowdeselect",this.planDeSelected,this)},disStoreLoad:function(){var A=[];for(var B=0;B<this.displansel.length;B++){A.push(this.disStore.getAt(this.disStore.find("code",this.displansel[B])))}this.disSM.selectRecords(A);this.disSM.on("rowselect",this.disSelected,this);this.disSM.on("rowdeselect",this.disDeSelected,this)},schStoreLoad:function(){var A=[];for(var B=0;B<this.schplansel.length;B++){A.push(this.schStore.getAt(this.schStore.find("code",this.schplansel[B])))}this.schSM.selectRecords(A);this.schSM.on("rowselect",this.schSelected,this);this.schSM.on("rowdeselect",this.schDeSelected,this)},planSelected:function(B,A,C){if(this.plandel.indexOf(this.pStore.getAt(A).get("code"))>-1){this.plandel.remove(this.pStore.getAt(A).get("code"))}else{this.planAdd.push(this.pStore.getAt(A).get("code"))}},planDeSelected:function(B,A,C){if(this.planAdd.indexOf(this.pStore.getAt(A).get("code"))>-1){this.planAdd.remove(this.pStore.getAt(A).get("code"))}else{this.plandel.push(this.pStore.getAt(A).get("code"))}},disSelected:function(B,A,C){if(this.displandel.indexOf(this.disStore.getAt(A).get("code"))>-1){this.displandel.remove(this.disStore.getAt(A).get("code"))}else{this.displanAdd.push(this.disStore.getAt(A).get("code"))}},disDeSelected:function(B,A,C){if(this.displanAdd.indexOf(this.disStore.getAt(A).get("code"))>-1){this.displanAdd.remove(this.disStore.getAt(A).get("code"))}else{this.displandel.push(this.disStore.getAt(A).get("code"))}},schSelected:function(B,A,C){if(this.schplandel.indexOf(this.schStore.getAt(A).get("code"))>-1){this.schplandel.remove(this.schStore.getAt(A).get("code"))}else{this.schplanAdd.push(this.schStore.getAt(A).get("code"))}},schDeSelected:function(B,A,C){if(this.schplanAdd.indexOf(this.schStore.getAt(A).get("code"))>-1){this.schplanAdd.remove(this.schStore.getAt(A).get("code"))}else{this.schplandel.push(this.schStore.getAt(A).get("code"))}},userPlanmap:function(){if(!this.pSM.hasSelection()){msgBoxShow(["Base Plan","Select a base plan"],Wtf.MessageBox.ERROR);return }var iflag=0;var flatFlag=0;if(this.spegrad.getValue()){iflag=1;if(this.chk2.getValue()){flatFlag=1}var tamt=0;var iamount="";for(ii=0;ii<this.otherStore.getCount()-1;ii++){tamt+=parseFloat(this.otherStore.getAt(ii).data["amount"]);iamount+=this.otherStore.getAt(ii).data["amount"];if(ii!=this.otherStore.getCount()-2){iamount+=","}if(parseFloat(this.otherStore.getAt(ii).data["amount"])==0){msgBoxShow(["Error","Amount applied to selected month is 0"],Wtf.MessageBox.ERROR);return }}if(this.chk2.getValue()&&tamt!=this.pGrid.getSelections()[0].data["amount"]){msgBoxShow(["Error","Total installment amount is not equal to the base plan amount."],Wtf.MessageBox.ERROR);return }else{if(!this.chk2.getValue()&&tamt!=100){msgBoxShow(["Error","Total installment amount is not equal to 100."],Wtf.MessageBox.ERROR);return }}}Wtf.Ajax.requestEx({url:"jspfiles/admin/acastructure.jsp",method:"POST",params:{userid:this.userid,planAdd:this.planAdd.toString(),plandel:this.plandel.toString(),displanAdd:this.displanAdd.toString(),displandel:this.displandel.toString(),schplanAdd:this.schplanAdd.toString(),schplandel:this.schplandel.toString(),programid:this.programid,iamount:iamount,iflag:iflag,flatFlag:flatFlag,type:49,flag:this.flag,typeflag:this.typeflag}},this,function(response,option){var resp=eval("("+response+")");if(resp!=null&&resp.amount!=null){this.fireEvent("refreshgrid",resp.amount)}this.editWin.close();this.planAdd=[];this.plandel=[];this.displanAdd=[];this.displandel=[];this.schplanAdd=[];this.schplandel=[]},function(resp,req){})},pStoreLoad1:function(){Wtf.Ajax.request({url:"jspfiles/admin/acastructure.jsp",method:"POST",params:{userid:this.userid,type:96,typeflag:this.typeflag},scope:this,success:function(response,option){var resp=eval("("+response.responseText+")");var planSelected=[];var disSelected=[];var schSelected=[];for(var ctr=0;ctr<resp.data.length;ctr++){var selected=[];if(resp.data[ctr].type==0){planSelected.push(this.pStore.getAt(this.pStore.find("code",resp.data[ctr].code)));this.spegrad.setValue((resp.data[ctr].iflag==1)?true:false);this.chk2.setValue((resp.data[ctr].flatflag==1)?true:false)}else{if(resp.data[ctr].type==1){disSelected.push(this.disStore.getAt(this.disStore.find("code",resp.data[ctr].code)))}else{if(resp.data[ctr].type==2){schSelected.push(this.schStore.getAt(this.schStore.find("code",resp.data[ctr].code)))}}}}if(this.spegrad.getValue()){this.setInstallments()}else{this.addDataInGrid()}if(planSelected.length>0){this.pSM.selectRecords(planSelected)}if(disSelected.length>0){this.disSM.selectRecords(disSelected)}if(schSelected.length>0){this.schSM.selectRecords(schSelected)}this.planAdd=[];this.plandel=[];this.displanAdd=[];this.displandel=[];this.schplanAdd=[];this.schplandel=[];this.pSM.on("rowselect",this.planSelected,this);this.pSM.on("rowdeselect",this.planDeSelected,this);this.disSM.on("rowselect",this.disSelected,this);this.disSM.on("rowdeselect",this.disDeSelected,this);this.schSM.on("rowselect",this.schSelected,this);this.schSM.on("rowdeselect",this.schDeSelected,this)}})}})