function credenceSubmit(){
var credence = validation();
if(credence==false){
return false;
}
new Ajax.Request(
'http://localhost:8080/slasset/credence_manage.do',{
method : 'post',
parameters : {
m : 'add',
json : Object.toJSON(credence)
},
onComplete : function(response){
var flag = response.responseJSON.flag;
if(flag==1){
alert("金额过大,必须经大额度");
}else if(flag==2){
alert("添加凭证成功");
window.location = 'http://localhost:8080/slasset/credence_manage.do?m=backtrace';
}else if(flag==-1){
alert("添加凭证失败");
}
}
});
}
----------------------------------------------------------------------------------------
function validation(){
var credence = {};
credence.shopid = 45;
credence.accid = 1;
credence.credtypeid = $F('credtypeid');
credence.creddate = $F('creddate');
if(credence.creddate==''){
alert('日期不能为空');
return false;
}
credence.billnumber = $F('billnumber');
if(credence.billnumber==''){
alert('附件数不能为空');
return false;
}
credence.billmaker = $F('billmaker');
var detail = [];
var sumDebit=0;
var sumCredit=0;
var j=0;
var brief,subid,debit,credit;
for(var i=1;i<totalRowNum;i++)
{
brief = $F('briefRow'+i).trim();
subid = $F('subjectRow'+i).trim();
debit = $F('debitRow'+i).trim();
credit = $F('creditRow'+i).trim();
if((i==1 && (brief!='' && subid!='' && (debit!='' || credit!=''))) || (i>1 && (subid!='' && (debit!='' || credit!=''))) ){
var obj = {};
obj.brief = brief;
obj.subid = subid;
obj.debit = debit==''?0:debit;
obj.credit = credit==''?0:credit;
obj.assist = $F('assistflag'+i);
if(obj.assist>0){
obj.data = $F('assistData'+i).evalJSON();
}
detail[j++] = obj;
}else if( (subid!='' && subid!='-1') || debit!='' || credit!=''){
alert("请将明细填写完整");
return false;
}
}
if(j<2){
alert("请将明细填写完整");
return false;
}
if($F('debitSum') != $F('creditSum')){
alert("借贷不平衡,请检查数据");
return false;
}
credence.sum = $F('debitSum');
credence.detail = detail;
return credence;
}