Wtf.CreditNote=function(A){Wtf.apply(this,A);Wtf.CreditNote.superclass.constructor.call(this,A)};Wtf.extend(Wtf.CreditNote,Wtf.Window,{initComponent:function(A){customerId=null;refNo=null;customerName=null;creditAmount=null;receivableAccid=null;this.bankAccid=1;creditId=null;totalTid=null;moduleid=null;Wtf.CreditNote.superclass.initComponent.call(this,A);this.addEvents({"closeform":true})},onRender:function(A){Wtf.CreditNote.superclass.onRender.call(this,A);this.loadMask=new Wtf.LoadMask(this.el.dom,Wtf.apply(this.loadMask));this.chargeStore=new Wtf.data.SimpleStore({fields:["id","name"],data:[["0","Flat Fee"],["1","% Fee"]]});this.add({border:false,layout:"border",items:[{region:"north",border:false,height:75,bodyStyle:"background:white;border-bottom:1px solid #bfbfbf;",html:"<div style = 'width:100%;height:100%;position:relative;float:left;'><div style='float:left;height:100%;width:auto;position:relative;'><img src = 'images/createuser.gif' style = 'width:40px;height:52px;margin:5px 5px 5px 5px;'></img></div><div style='float:left;height:100%;width:60%;position:relative;'><div style='font-size:12px;font-style:bold;float:left;margin:15px 0px 0px 10px;width:100%;position:relative;'><b>Credit Note</b></div><div style='font-size:10px;float:left;margin:15px 0px 10px 10px;width:100%;position:relative;'>Generate credit note</div></div></div>"},{region:"center",autoScroll:true,bodyStyle:"background:#f1f1f1;font-size:10px;",border:false,items:[{border:false,layout:"form",bodyStyle:"padding:13px 13px 13px 13px",labelWidth:100,items:[this.CustName=new Wtf.form.TextField({fieldLabel:"Customer Name*",anchor:"93%",allowBlank:false,id:"custname"+this.id,value:this.customerName,msgTarget:"side",readOnly:true}),this.RefAmt=new Wtf.form.TextField({fieldLabel:"Credit Amount*",anchor:"93%",allowBlank:false,value:this.creditAmount,id:"refamt"+this.id,msgTarget:"side",readOnly:true}),this.amtcut=new Wtf.form.NumberField({fieldLabel:"Refund",anchor:"93%",allowBlank:false,id:"amtcut"+this.id,msgTarget:"side"}),this.chargeCombo=new Wtf.form.ComboBox({triggerAction:"all",store:this.chargeStore,anchor:"93%",fieldLabel:"Charge Mode",mode:"local",readOnly:true,displayField:"name",hiddenName:"id",allowBlank:false,valueField:"id",emptyText:"Select Charge Mode"}),this.RefundAmt=new Wtf.form.NumberField({fieldLabel:"Total Refund Amount*",anchor:"93%",allowBlank:false,id:"refundamt"+this.id,decimalPrecision:2,msgTarget:"side"}),this.dateTimePickerdate=new Wtf.form.DateField({fieldLabel:"Date*",anchor:"93%",id:"Date"+this.id,displayField:"Date",allowBlank:false}),this.memo=new Wtf.form.TextArea({fieldLabel:"Memo",height:40,anchor:"93%",allowBlank:true,id:"memo"+this.id})]}]}],buttonAlign:"center",buttons:[{text:"Submit",handler:this.generateCreditNote,scope:this},{text:"Cancel",handler:function(){this.close()},scope:this}]});this.amtcut.on("blur",this.calRefamount,this);this.chargeCombo.on("select",this.calRefamount,this);if(this.fullrefund=="true"){this.amtcut.disable();this.chargeCombo.disable();this.RefundAmt.value=this.creditAmount;this.RefundAmt.disable()}},calRefamount:function(){if(this.amtcut.getValue()!=""&&this.chargeCombo.getValue()!=null){var A=0;if(this.chargeCombo.getValue()=="0"){A=parseFloat(this.amtcut.getValue())}else{A=(parseFloat(this.RefAmt.getValue()))*(parseFloat(this.amtcut.getValue())/100)}this.RefundAmt.setValue(Wtf.precisionDecimalValue(A))}},generateCreditNote:function(){this.RefAmt.validate();this.dateTimePickerdate.validate();this.RefundAmt.validate();this.CustName.validate();if(!this.RefAmt.isValid()||!this.dateTimePickerdate.isValid()||!this.RefundAmt.isValid()||!this.CustName.isValid()){return }var A=3;this.UUIDStore=new Wtf.data.Store({url:"jspfiles/accounting/Accounts.jsp?flag=3&count="+A,reader:new Wtf.data.JsonReader({root:"data"},["id"])});this.UUIDStore.load();this.UUIDStore.on("load",this.submitcreditmemo,this)},submitcreditmemo:function(L,I,B){this.loadMask.show();var O=Wtf.common.CreateJsonStart();var H;var Q=1;var W=0;var F=0;var U=0;var R=I[0].data["id"];this.totalTid=R;var A=0;var S=new Date(this.dateTimePickerdate.getValue());var V=S.format("Y-m-d H:i:s");var T=this.receivableAccid;var P="3";var K=this.refNo;var G=this.customerId;A=this.RefundAmt.getValue();var N=0;var E=new Number(A);var M=new Array("tablename","id","tid","ttypeid","dateval","num","total","customerid","amount","amountdue","salestaxid");var C=new Array("transaction1",W,R,10,V,K,"true",G,-E,-E,0);H=Wtf.common.getJsonObjectForAccounting(M,C);W++;O+=H;var M=new Array("tablename","id","tid","accid","balance");var C=new Array("accounttransaction",F,R,T,-E);H=Wtf.common.getJsonObjectForAccounting(M,C);F++;O+=H;var J=I[1].data["id"];var D=I[2].data["id"];var M=new Array("tablename","id","tid","creditmemoid","num","memo","amount","itemid","itemqty","price");var C=new Array("creditmemo",U,R,J,K,this.memo.getValue(),E,"",1,E);H=Wtf.common.getJsonObjectForAccounting(M,C);U++;O+=H;var M=new Array("tablename","id","tid","ttypeid","dateval","num","total","customerid","amount","amountdue","salestaxid");C=new Array();C[0]="transaction1";C[1]=W;C[2]=D;C[3]=10;C[4]=V;C[5]=K;C[6]="false";C[7]=G;C[8]=-E;C[9]=-E;C[10]=0;H=Wtf.common.getJsonObjectForAccounting(M,C);W++;O+=H;var M=new Array("tablename","id","tid","accid","balance");var C=new Array("accounttransaction",F,D,P,-E);H=Wtf.common.getJsonObjectForAccounting(M,C);F++;O+=H;var M=new Array("tablename","id","tid","dateval","num","amount","amountdue","ctype","credittype");var C=new Array("credit",0,R,V,K,E,E,"creditmemo","Withdrawl");H=Wtf.common.getJsonObjectForAccounting(M,C);O+=H;O=Wtf.common.CreateJsonEnd(O);this.InsertStore=new Wtf.data.Store({method:"POST",url:"jspfiles/accounting/CreditMemo.jsp",baseParams:{flag:0,jsondata:O,programid:this.programid},reader:new Wtf.data.JsonReader({root:"data",fields:[{name:"result",type:"string"},{name:"ErrorMsg",type:"string"}]})});this.InsertStore.on("load",function(Y,Z,X){this.loadMask.hide();if(Z[0].data["result"]=="Success"){Wtf.Msg.alert("Status","Credit note has been generated successfully");if(this.moduleid){Wtf.Ajax.requestEx({url:"jspfiles/newCourse.jsp",params:{userid:this.customerId,moduleid:this.moduleid,sessionid:this.sessionid,classtypeid:this.classtypeid,type:this.type,operation:"approvewithdrawal",msg:"Your request for withdrawal approved",status:"18"},method:"POST"},this,function(b,a){this.fireEvent("closeform",this.id);this.close()},function(b,a){})}else{this.fireEvent("closeform",this.id);this.close()}}else{Wtf.Msg.alert("Transaction Failure",Z[0].get("ErrorMsg"));this.close()}},this);this.InsertStore.on("loadexception",function(){Wtf.Msg.alert("Error","Error occurred while connecting to server")});this.InsertStore.load()}});Wtf.IssueRefund=function(A){Wtf.apply(this,A);Wtf.IssueRefund.superclass.constructor.call(this,A)};Wtf.extend(Wtf.IssueRefund,Wtf.Window,{initComponent:function(A){customerId=null;refNo=null;customerName=null;creditAmount=null;receivableAccid=null;this.bankAccid=1;totalTid=null;moduleid=null;Wtf.IssueRefund.superclass.initComponent.call(this,A);this.addEvents({"closeform":true})},onRender:function(A){Wtf.IssueRefund.superclass.onRender.call(this,A);this.loadMask=new Wtf.LoadMask(this.el.dom,Wtf.apply(this.loadMask));this.storePacc=new Wtf.data.SimpleStore({fields:["abbr","title"],data:[["1","Cash"],["2","Cheque"]]});this.chargeStore=new Wtf.data.SimpleStore({fields:["id","name"],data:[["0","Flat Fee"],["1","% Fee"]]});this.add({border:false,layout:"border",items:[{region:"north",border:false,height:75,bodyStyle:"background:white;border-bottom:1px solid #bfbfbf;",html:"<div style = 'width:100%;height:100%;position:relative;float:left;'><div style='float:left;height:100%;width:auto;position:relative;'><img src = 'images/createuser.gif' style = 'width:40px;height:52px;margin:5px 5px 5px 5px;'></img></div><div style='float:left;height:100%;width:60%;position:relative;'><div style='font-size:12px;font-style:bold;float:left;margin:15px 0px 0px 10px;width:100%;position:relative;'><b>Issue Refund</b></div><div style='font-size:10px;float:left;margin:15px 0px 10px 10px;width:100%;position:relative;'>Refund credit memo amount</div></div></div>"},{region:"center",autoScroll:true,bodyStyle:"background:#f1f1f1;font-size:10px;",border:false,items:[{border:false,layout:"form",bodyStyle:"padding:13px 13px 13px 13px",labelWidth:100,items:[this.CustName=new Wtf.form.TextField({fieldLabel:"Customer Name*",anchor:"93%",allowBlank:false,id:"custname"+this.id,value:this.customerName,msgTarget:"side",readOnly:true}),this.RefAmt=new Wtf.form.TextField({fieldLabel:"Amount*",anchor:"93%",allowBlank:false,value:this.creditAmount,id:"refamt"+this.id,msgTarget:"side",readOnly:true}),this.amtcut=new Wtf.form.NumberField({fieldLabel:"Refund Amount",anchor:"93%",allowBlank:false,id:"amtcut"+this.id,msgTarget:"side"}),this.chargeCombo=new Wtf.form.ComboBox({triggerAction:"all",store:this.chargeStore,anchor:"93%",fieldLabel:"Charge Mode",mode:"local",readOnly:true,displayField:"name",hiddenName:"id",allowBlank:false,valueField:"id",emptyText:"Select Charge Mode"}),this.RefundAmt=new Wtf.form.NumberField({fieldLabel:"Actual Refund Amount*",anchor:"93%",allowBlank:false,id:"refundamt"+this.id,msgTarget:"side",decimalPrecision:2,readOnly:true}),this.dateTimePickerdate=new Wtf.form.DateField({fieldLabel:"Date*",anchor:"93%",id:"Date"+this.id,displayField:"Date",allowBlank:false}),this.via=new Wtf.form.ComboBox({fieldLabel:"Refund via*",anchor:"93%",id:"via"+this.id,mode:"local",triggerAction:"all",typeAhead:true,editable:false,allowBlank:false,store:this.storePacc,displayField:"title",valueField:"abbr",allowBlank:false,value:this.storePacc.getAt(0).data["abbr"],msgTarget:"side"}),this.textBoxCNno=new Wtf.form.TextField({fieldLabel:"Ref No#",anchor:"93%",id:"creditNote"+this.id,allowBlank:true,disabled:true}),this.memo=new Wtf.form.TextArea({fieldLabel:"Memo",height:40,anchor:"93%",allowBlank:false,id:"memo"+this.id})]}]}],buttonAlign:"center",buttons:[{text:"Submit",handler:this.generateCreditNote,scope:this},{text:"Cancel",handler:function(){this.close()},scope:this}]});this.amtcut.on("blur",this.calRefamount,this);this.via.on("select",this.checkFun,this);this.chargeCombo.on("select",this.calRefamount,this);if(this.fullrefund=="true"){this.amtcut.disable();this.chargeCombo.disable();this.RefundAmt.value=this.creditAmount;this.RefundAmt.disable()}},calRefamount:function(){if(this.amtcut.getValue()!=""&&this.chargeCombo.getValue()!=null){var A=0;if(this.chargeCombo.getValue()=="0"){A=parseFloat(this.amtcut.getValue())}else{A=(parseFloat(this.RefAmt.getValue()))*(parseFloat(this.amtcut.getValue())/100)}this.RefundAmt.setValue(Wtf.precisionDecimalValue(A))}},checkFun:function(B,C,A){if(C.get("abbr")=="2"){this.textBoxCNno.allowBlank=false;this.textBoxCNno.setValue("");this.textBoxCNno.setDisabled(false)}else{this.textBoxCNno.allowBlank=true;this.textBoxCNno.setValue("");this.textBoxCNno.setDisabled(true)}},generateCreditNote:function(){this.RefAmt.validate();this.dateTimePickerdate.validate();this.via.validate();this.RefundAmt.validate();this.CustName.validate();if(this.via.getValue()!=1){this.textBoxCNno.validate();if(!this.textBoxCNno.isValid()){return }}if(!this.RefAmt.isValid()||!this.dateTimePickerdate.isValid()||!this.via.isValid()||!this.RefundAmt.isValid()||!this.CustName.isValid()){return }var A=1;this.UUIDStore=new Wtf.data.Store({url:"jspfiles/accounting/Accounts.jsp?flag=3&count="+A,reader:new Wtf.data.JsonReader({root:"data"},["id"])});this.UUIDStore.load();this.UUIDStore.on("load",this.submitcreditmemo,this)},submitcreditmemo:function(I,F,B){this.loadMask.show();var G=Wtf.common.CreateJsonStart();var M;var K=1;var L=0;var N=0;var J=F[0].data["id"];var E="3";var O=new Date(this.dateTimePickerdate.getValue());var D=O.format("Y-m-d H:i:s");var A="";if(this.via.getValue()==2){A=this.textBoxCNno.getValue()}var H=new Array("tablename","id","tid","ttypeid","dateval","num","total","customerid","amount","amountdue","salestaxid");var C=new Array("transaction1",L,J,13,D,this.refNo,true,this.customerId,-this.RefundAmt.getValue(),-this.RefundAmt.getValue(),0);M=Wtf.common.getJsonObjectForAccounting(H,C);L++;G+=M;var H=new Array("tablename","id","tid","accid","balance");var C=new Array();C[0]="accounttransaction";C[1]=N;C[2]=J;C[3]=this.bankAccid;C[4]=-this.creditAmount;M=Wtf.common.getJsonObjectForAccounting(H,C);N++;G+=M;var C=new Array("accounttransaction",N,J,E,-this.creditAmount);M=Wtf.common.getJsonObjectForAccounting(H,C);N++;G+=M;var H=new Array("tablename","id","tid","num","memo","chequeno","refundmode","amount");var C=new Array("refund",0,J,"",this.memo.getValue(),A,this.via.getValue(),this.creditAmount);M=Wtf.common.getJsonObjectForAccounting(H,C);G+=M;G=Wtf.common.CreateJsonEnd(G);this.InsertStore=new Wtf.data.Store({method:"POST",url:"jspfiles/accounting/CreditMemo.jsp",baseParams:{flag:0,jsondata:G,programid:this.programid},reader:new Wtf.data.JsonReader({root:"data",fields:[{name:"result",type:"string"},{name:"ErrorMsg",type:"string"}]})});this.InsertStore.on("load",function(Q,R,P){this.loadMask.hide();if(R[0].data["result"]=="Success"){Wtf.Msg.alert("Status","Amount refunded successfully");if(this.moduleid){Wtf.Ajax.requestEx({url:"jspfiles/newCourse.jsp",params:{userid:this.customerId,moduleid:this.moduleid,sessionid:this.sessionid,classtypeid:this.classtypeid,type:this.type,operation:"approvewithdrawal",msg:"Your request for withdrawal approved",status:"18"},method:"POST"},this,function(T,S){this.fireEvent("closeform",this.id);this.close()},function(T,S){})}else{this.fireEvent("closeform",this.id);this.close()}}else{Wtf.Msg.alert("Transaction Failure",R[0].get("ErrorMsg"));this.close()}},this);this.InsertStore.on("loadexception",function(){Wtf.Msg.alert("Error","Error occurred while connecting to server")});this.InsertStore.load()}});Wtf.NewGenInvoice=function(A){Wtf.apply(this,A);Wtf.NewGenInvoice.superclass.constructor.call(this,A)};Wtf.extend(Wtf.NewGenInvoice,Wtf.Window,{modal:true,initComponent:function(){customerId=null;type=null;feetypeid=null;moduleid=null;sessionid=null;incomeid=null;accountid=null;phdflag=null;balDue=0;totalTid=null;amountDue=null;creditHrs=null;Wtf.NewGenInvoice.superclass.initComponent.call(this);this.addEvents({"closeform":true})},onRender:function(A){Wtf.NewGenInvoice.superclass.onRender.call(this,A);this.loadMask=new Wtf.LoadMask(this.el.dom,Wtf.apply(this.loadMask));this.NewInv=Wtf.data.Record.create([{name:"code",type:"string"},{name:"descval",type:"string"},{name:"id",type:"string"},{name:"amount",type:"string"},{name:"rid",type:"string"}]);this.dsNewInv=new Wtf.data.Store({baseParams:{flag:1,num:""},url:"jspfiles/accounting/NewInvoice.jsp",reader:new Wtf.data.JsonReader({root:"data"},this.NewInv)});this.cmNewInv=new Wtf.grid.ColumnModel([new Wtf.grid.RowNumberer(),{header:"Code",hidden:true,dataIndex:"code"},{header:"Description",dataIndex:"descval"},{header:"Amount",dataIndex:"amount",width:50,renderer:function(B){return Wtf.precisionDecimalValue(B)}}]);this.newapplycredits=new Wtf.Panel({frame:true,border:false,layout:"fit",items:[{border:false,region:"center",layout:"border",items:[{region:"north",height:75,border:false,bodyStyle:"background:white;border-bottom:1px solid #bfbfbf;",html:getHeader("images/createcommunity.png","Invoice","Generate Invoice")},{border:false,region:"center",bodyStyle:"background:#f1f1f1;font-size:10px;",layout:"border",items:[{region:"center",id:"center"+this.id,height:225,border:false,layout:"border",items:[{region:"center",id:"MGrid"+this.id,border:false,title:"Selected Modules",layout:"fit",items:this.AccGridModuleList=new Wtf.AccGridComp({id:"accGridMList"+this.id,selModel:new Wtf.grid.RowSelectionModel(),ds:this.dsNewInv,cm:this.cmNewInv})},{region:"south",id:"MFTot"+this.id,height:38,border:false,items:[this.totAmt=new Wtf.form.TextField({fieldLabel:"Original Amount",labelWidth:"35%",editable:false,anchor:"100%",id:"origAmt"+this.id,readOnly:true,value:Wtf.precisionDecimalValue(this.amountDue),cls:"floatrightdiv"})]}]},{region:"south",id:"south"+this.id,border:false}]}]}],bbar:[{id:"submit"+this.id,text:"Submit",iconCls:"tags",tooltip:{title:"Submit",text:"Click to Submit"},handler:this.SaveInvoice,scope:this},{text:"Cancel",iconCls:"tags",tooltip:{title:"Cancel",text:"Click to Cancel"},handler:function(){this.close()},scope:this}]});this.add(this.newapplycredits);this.populateGridInv()},populateGridInv:function(){var C=0;for(var B=0;B<this.store.getCount();B++){var A=new this.NewInv({code:this.store.getAt(B).get("code"),descval:this.store.getAt(B).get("name"),id:this.store.getAt(B).get("id"),amount:this.store.getAt(B).get("fee"),rid:this.store.getAt(B).get("rid")});this.dsNewInv.add(A)}},SaveInvoice:function(){this.loadMask.show();var A=2+this.dsNewInv.getCount()*3;this.UUIDStore=new Wtf.data.Store({url:"jspfiles/accounting/Accounts.jsp?flag=3&count="+A,reader:new Wtf.data.JsonReader({root:"data"},["id"])});this.UUIDStore.on("load",this.submitinvoice,this);this.UUIDStore.load()},submitinvoice:function(D,E,A){var F="{tableinfo:[";for(ii=0;ii<this.dsNewInv.getCount();ii++){var C=new Array();C[0]="amount";C[1]="itemid";var B=new Array();B[0]=new Number(this.dsNewInv.getAt(ii).data["amount"]).toFixed(2);B[1]=this.dsNewInv.getAt(ii).data["id"];jobj=Wtf.common.getJsonObjectForAccounting(C,B);F+=jobj}F=Wtf.common.CreateJsonEnd(F);this.InsertStore=new Wtf.data.Store({method:"POST",url:"jspfiles/accounting/NewInvoice.jsp",baseParams:{flag:0,jsondata:F},reader:new Wtf.data.JsonReader({root:"data",fields:[{name:"result",type:"string"},{name:"ErrorMsg",type:"string"}]})});this.InsertStore.on("load",function(H,I,G){this.loadMask.hide();if(I[0].data["result"]=="Success"){Wtf.Msg.alert("Status","Invoice created successfully");if(this.feetypeid=="2"||this.feetypeid=="7"){Wtf.Ajax.requestEx({url:"jspfiles/newCourse.jsp",params:{userid:this.customerId,moduleid:this.moduleid,type:"insertCreditHrForExempted",credithr:this.creditHrs},method:"POST"},this,function(K,J){},function(K,J){})}}else{Wtf.Msg.alert("Transaction Failure",I[0].get("ErrorMsg"))}this.fireEvent("closeform",this.id);this.close()},this);this.InsertStore.on("loadexception",function(){this.loadMask.hide();Wtf.Msg.alert("Error","Error occurred while connecting to server")},this);this.InsertStore.load({params:{flag:0,jsondata:F,moduleid:this.moduleid,userid:this.customerId,feetypeid:this.feetypeid,type:this.type,sessionid:this.sessionid,accountid:this.accountid,incomeid:this.incomeid}})}});Wtf.genCreditNote=function(A){Wtf.apply(this,A);Wtf.genCreditNote.superclass.constructor.call(this,A)};Wtf.extend(Wtf.genCreditNote,Wtf.Window,{initComponent:function(A){customerId=null;refNo=null;customerName=null;creditAmount=null;receivableAccid=null;this.bankAccid=1;creditId=null;totalTid=null;moduleid=null;Wtf.genCreditNote.superclass.initComponent.call(this,A);this.addEvents({"closeform":true})},show:function(A){Wtf.genCreditNote.superclass.show.call(this,A);Wtf.get("matricno"+this.id).dom.onkeyup=this.onKeyUp.createDelegate(this)},onRender:function(A){Wtf.genCreditNote.superclass.onRender.call(this,A);this.loadMask=new Wtf.LoadMask(this.el.dom,Wtf.apply(this.loadMask));this.programRecord=Wtf.data.Record.create([{name:"id",type:"string"},{name:"name",type:"string"}]);this.programReader=new Wtf.data.KwlJsonReader({root:"data"},this.programRecord);this.programStore=new Wtf.data.Store({reader:this.programReader});this.add({border:false,layout:"border",items:[{region:"north",border:false,height:75,bodyStyle:"background:white;border-bottom:1px solid #bfbfbf;",html:"<div style = 'width:100%;height:100%;position:relative;float:left;'><div style='float:left;height:100%;width:auto;position:relative;'><img src = 'images/createuser.gif' style = 'width:40px;height:52px;margin:5px 5px 5px 5px;'></img></div><div style='float:left;height:100%;width:60%;position:relative;'><div style='font-size:12px;font-style:bold;float:left;margin:15px 0px 0px 10px;width:100%;position:relative;'><b>Credit Note</b></div><div style='font-size:10px;float:left;margin:15px 0px 10px 10px;width:100%;position:relative;'>Generate credit note</div></div></div>"},{region:"center",autoScroll:true,bodyStyle:"background:#f1f1f1;font-size:10px;",border:false,items:[{border:false,layout:"form",bodyStyle:"padding:13px 13px 13px 13px",labelWidth:70,items:[this.metricno=new Wtf.form.TextField({fieldLabel:"Matric No.*",anchor:"93%",allowBlank:false,id:"matricno"+this.id,msgTarget:"side"}),this.CustName=new Wtf.form.TextField({fieldLabel:"Name*",anchor:"93%",id:"custname"+this.id,msgTarget:"side",readOnly:true}),this.sponsor=new Wtf.form.TextField({fieldLabel:"Sponsor",anchor:"93%",id:"sponsor"+this.id,msgTarget:"side",readOnly:true}),this.programCombo=new Wtf.form.ComboBox({triggerAction:"all",store:this.programStore,anchor:"93%",fieldLabel:"Program",mode:"local",readOnly:true,displayField:"name",hiddenName:"id",allowBlank:false,valueField:"id",emptyText:"Select program"}),this.RefundAmt=new Wtf.form.NumberField({fieldLabel:"Amount*",anchor:"93%",allowBlank:false,id:"refundamt"+this.id,decimalPrecision:2,msgTarget:"side"}),this.dateTimePickerdate=new Wtf.form.DateField({fieldLabel:"Date*",anchor:"93%",id:"Date"+this.id,displayField:"Date",allowBlank:false}),this.memo=new Wtf.form.TextArea({fieldLabel:"Memo",height:40,anchor:"93%",allowBlank:true,id:"memo"+this.id})]}]}],buttonAlign:"center",buttons:[{text:"Submit",handler:this.generateCreditNote,scope:this},{text:"Cancel",handler:function(){this.close()},scope:this}]})},onKeyUp:function(e){if(this.metricno.getValue().length==7){Wtf.Ajax.requestEx({url:"jspfiles/admin/acastructure.jsp",params:{matricno:this.metricno.getValue(),type:101},method:"POST"},this,function(resp,req){this.CustName.setValue("");this.customerId=="";this.programStore.removeAll();this.programCombo.setValue("");this.sponsor.setValue("");var respobj=eval("("+resp+")");var arrobj=[];if(respobj.data!=null){for(var ctr=0;ctr<respobj.data.length;ctr++){this.CustName.setValue(respobj.data[ctr].name);this.sponsor.setValue(respobj.data[ctr].code);this.customerId=respobj.data[ctr].id;var arrelement=new this.programRecord({id:respobj.data[ctr].programid,name:respobj.data[ctr].programname});arrobj.push(arrelement)}this.programStore.add(arrobj)}},function(resp,req){})}},generateCreditNote:function(){this.dateTimePickerdate.validate();this.RefundAmt.validate();this.CustName.validate();if(!this.dateTimePickerdate.isValid()||!this.RefundAmt.isValid()||!this.CustName.isValid()){return }var A=3;this.UUIDStore=new Wtf.data.Store({url:"jspfiles/accounting/Accounts.jsp?flag=3&count="+A,reader:new Wtf.data.JsonReader({root:"data"},["id"])});this.UUIDStore.load();this.UUIDStore.on("load",this.submitcreditmemo,this)},submitcreditmemo:function(L,I,B){this.loadMask.show();var O=Wtf.common.CreateJsonStart();var H;var Q=1;var W=0;var F=0;var U=0;var R=I[0].data["id"];this.totalTid=R;var A=0;var S=new Date(this.dateTimePickerdate.getValue());var V=S.format("Y-m-d H:i:s");var T=this.receivableAccid;var P="3";var K=this.refNo;var G=this.customerId;A=this.RefundAmt.getValue();var N=0;var E=new Number(A);var M=new Array("tablename","id","tid","ttypeid","dateval","num","total","customerid","amount","amountdue","salestaxid");var C=new Array("transaction1",W,R,10,V,K,"true",G,-E,-E,0);H=Wtf.common.getJsonObjectForAccounting(M,C);W++;O+=H;var M=new Array("tablename","id","tid","accid","balance");var C=new Array("accounttransaction",F,R,T,-E);H=Wtf.common.getJsonObjectForAccounting(M,C);F++;O+=H;var J=I[1].data["id"];var D=I[2].data["id"];var M=new Array("tablename","id","tid","creditmemoid","num","memo","amount","itemid","itemqty","price");var C=new Array("creditmemo",U,R,J,K,this.memo.getValue(),E,"",1,E);H=Wtf.common.getJsonObjectForAccounting(M,C);U++;O+=H;var M=new Array("tablename","id","tid","ttypeid","dateval","num","total","customerid","amount","amountdue","salestaxid");C=new Array();C[0]="transaction1";C[1]=W;C[2]=D;C[3]=10;C[4]=V;C[5]=K;C[6]="false";C[7]=G;C[8]=-E;C[9]=-E;C[10]=0;H=Wtf.common.getJsonObjectForAccounting(M,C);W++;O+=H;var M=new Array("tablename","id","tid","accid","balance");var C=new Array("accounttransaction",F,D,P,-E);H=Wtf.common.getJsonObjectForAccounting(M,C);F++;O+=H;var M=new Array("tablename","id","tid","dateval","num","amount","amountdue","ctype","credittype");var C=new Array("credit",0,R,V,K,E,E,"creditmemo","Withdrawl");H=Wtf.common.getJsonObjectForAccounting(M,C);O+=H;O=Wtf.common.CreateJsonEnd(O);this.InsertStore=new Wtf.data.Store({method:"POST",url:"jspfiles/accounting/CreditMemo.jsp",baseParams:{flag:0,jsondata:O,programid:this.programCombo.getValue()},reader:new Wtf.data.JsonReader({root:"data",fields:[{name:"result",type:"string"},{name:"ErrorMsg",type:"string"}]})});this.InsertStore.on("load",function(Y,Z,X){this.loadMask.hide();if(Z[0].data["result"]=="Success"){Wtf.Msg.alert("Status","Credit note has been generated successfully");this.close()}else{Wtf.Msg.alert("Transaction Failure",Z[0].get("ErrorMsg"));this.close()}},this);this.InsertStore.on("loadexception",function(){Wtf.Msg.alert("Error","Error occurred while connecting to server")});this.InsertStore.load()}})