You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
JiCangHai/PingTai/DSWeb/js/InvoiceVerificationEdit.js

958 lines
39 KiB
JavaScript

var commonGridObj_feelist;
var comboCustomer;//委托单位
function $(id){
return document.getElementById(id);
}
function createGrid(){
//header
var headerArgs_feelist = new Array("<input type=\"checkbox\" id=\"ck_all\" onclick=\"checkAll()\" />", "委托编号", "主提单号", "分提单号", "结算单位", "费用名称", "收/付", "结算金额", "未结算金额", "开票金额", "计费标准", "单价", "数量", "金额", "币别", "汇率", "录入时间", "BSNO", "备注");
//width
var widthArgs_feelist = new Array("40", "150", "150", "150", "100", "100", "40", "100", "100", "100", "100", "100", "100", "100", "90", "70", "120", "0", "300");
//column align
var colAlignArgs_feelist = new Array("center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center");
//column sort
var colSortArgs_feelist = new Array("na", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str", "str");
//column type
var colTypeArgs_feelist = new Array("ch", "ro", "ro", "ro", "ro", "ro", "ro", "ed", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro", "ro");
commonGridObj_feelist = new TGridCommon("mygrid_container_feelist","form1",headerArgs_feelist,widthArgs_feelist,colAlignArgs_feelist,colSortArgs_feelist,colTypeArgs_feelist);
commonGridObj_feelist.setResponseUrl("InvoiceApplicationGridSource.aspx");
var invoiceId = $("h_invoiceid").value;
if($("h_cacheid").value.trim() == ""){
$("h_cacheid").value = commonGridObj_feelist.newGuid();
}
var cacheName = $("h_cacheid").value;
commonGridObj_feelist.setRequest("InvoiceApplicationGridSource.aspx?handle=unverificationfee&show_page=15&cur_page=1&invoiceid="+invoiceId+"&cachename="+cacheName+"&uid="+commonGridObj_feelist.newGuid());
commonGridObj_feelist.setSourceType("json");
commonGridObj_feelist.setSkin("xp");
commonGridObj_feelist.setImageUrl("../images/");
commonGridObj_feelist.initGrid();
commonGridObj_feelist.bind();
//commonGridObj_feelist.initPageByHandle("unverificationfee");
//commonGridObj_feelist.initPageByGID("unverificationfee","&invoiceid="+invoiceId+"&cachename="+cacheName);
// commonGridObj_invoicelist.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
// if(stage == 0){
// if(cInd == 2 || cInd == 3){
// return false;
// }else{
// return true;
// }
// }
// });
// commonGridObj_invoicelist.getGridObj().attachEvent("onRowSelect", function(id,ind){
// var openSet = "height=490, width=1000, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top= " +(screen.height-490)/2 + ",Left= "+(screen.width-900)/2
// var openType = "_blank";
//
// var openUrl = "InvoiceMakeOutEdit.aspx?handle=edit&id="+id;
// window.open (openUrl,openType,openSet);
//
// });
//
// commonGridObj_invoicelist.clickEvent = function(){
// commonGridObj_invoicelist.getGridObj().attachEvent("onRowSelect", function(id,ind){
// var openSet = "height=490, width=1000, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top= " +(screen.height-490)/2 + ",Left= "+(screen.width-900)/2
// var openType = "_blank";
//
// var openUrl = "InvoiceMakeOutEdit.aspx?handle=edit&id="+id;
// window.open (openUrl,openType,openSet);
//
// });
// }
commonGridObj_feelist.getGridObj().enableEditEvents(true,false,true);
commonGridObj_feelist.onEditEvent = function(){
commonGridObj_feelist.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
if(stage == 0){
if(cInd == 0){
return true;
}
}
if(stage == 1){
for(var i = 0; i < document.all.length; i++){
if(document.all(i).tagName == "TEXTAREA"){
txtEdit = document.all(i);
txtEdit.focus();
txtEdit.select();
break;
}
}
}
if(stage == 2){
var rowIndex = commonGridObj_feelist.getGridObj().getRowIndex(rId);
var stl = 0.0;
var cstl = 0.0;
var ustl = 0.0;
stl = parseFloat(clearNoNum(isObjNaN(ConvertToMoney(commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,13).getValue()))));
cstl = parseFloat(clearNoNum(isObjNaN(ConvertToMoney(commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,7).getValue()))));
ustl = parseFloat(clearNoNum(isObjNaN(ConvertToMoney(commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,8).getValue()))));
var rustl = 0.0;
var newCstl = parseFloat(nValue);
var oldCstl = parseFloat(oValue);
if(newCstl < 0){
return false;
}else if(newCstl > oldCstl && newCstl > (oldCstl + ustl)){
return false;
}else if(newCstl == 0){
return false;
}
var newStl = 0.0;
if(oldCstl != ustl){
newStl = (ustl+oldCstl) - newCstl;
}else{
newStl = ustl - newCstl;
}
commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,0).setValue(1);
commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,7).setValue(ConvertToMoney(outputMoney(cstl.toString())));
commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,8).setValue(ConvertToMoney(outputMoney(newStl.toString())));
var customerName = commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,4).getValue();
if($("txt_customer").value.trim() == ""){
$("txt_customer").value = customerName;
}
var invoiceId = $("h_invoiceid").value;
var doAmount = ConvertToMoney(outputMoney(cstl.toString()));
var unDoAmount = ConvertToMoney(outputMoney(newStl.toString()));
var rate = $("txt_rate").value.trim() == "" ? 0 : parseFloat($("txt_rate").value.trim());
var settleType = 0;
if($("ck_rmb").checked){
settleType = 1;
}else if($("ck_usd").checked){
settleType = 2;
}else{
settleType = 3;
}
var urlVal = "InvoiceApplicationGridSource.aspx?handle=editverifyfee&invoiceid="+invoiceId+"&cachename="+cacheName+"&verifyfee="+rId+"&doamount="+doAmount+"&unamount="+unDoAmount+"&rate="+rate+"&settletype="+settleType+"&val="+commonGridObj_feelist.newGuid();
var loader = dhtmlxAjax.getSync(urlVal);
var loadVal = loader.xmlDoc.responseText;
if(loadVal.trim() != ""){
var totalObj = eval('(' + loadVal + ')');
if(totalObj.verify.length > 0){
if(totalObj.verify[0].state == 1){
$("txt_rmbtotal").value = totalObj.verify[0].rmb;
$("txt_usdtotal").value = totalObj.verify[0].usd;
// commonGridObj_feelist.initGrid();
// commonGridObj_feelist.bind();
}
}
}
return true;
}
});
}
commonGridObj_feelist.onEditEvent();
commonGridObj_feelist.isOnEditCell = true;
commonGridObj_feelist.onCheckBox = function(){
commonGridObj_feelist.getGridObj().attachEvent("onCheckbox", function(rId,cInd,state){
var totalRmb = 0;
var totalUsd = 0;
var rowIndex = commonGridObj_feelist.getGridObj().getRowIndex(rId);
totalRmb = $("txt_rmbtotal").value.trim() == "" ? 0 : parseFloat($("txt_rmbtotal").value.trim());
totalUsd = $("txt_usdtotal").value.trim() == "" ? 0 : parseFloat($("txt_usdtotal").value.trim());
var doAmount = parseFloat(commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,7).getValue());
var currency = commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,14).getValue();
//var rate = parseFloat(commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,15).getValue());
var rate = parseFloat($("txt_rate").value.trim());
var customerName = commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,4).getValue();
//cache name
if($("h_cacheid").value.trim() == ""){
$("h_cacheid").value = commonGridObj_feelist.newGuid();
}
var cacheName = $("h_cacheid").value;
if(state){
if($("txt_customer").value.trim() == ""){
$("txt_customer").value = customerName;
}
// if($("txt_customer").value.trim() == ""){
// $("txt_customer").value = customerName;
// }
// if($("ck_rmb").checked){
// if(currency == "USD"){
// totalRmb += ForDight((doAmount/rate),2);
// }else if(currency == "RMB"){
// totalRmb += doAmount;
// }
// }else if($("ck_usd").checked){
// if(currency == "RMB"){
// totalUsd += ForDight((doAmount/rate),2);
// }else if(currency == "USD"){
// totalUsd += doAmount;
// }
// }else{
// if(currency == "USD"){
// totalUsd += doAmount;
// }else if(currency == "RMB"){
// totalRmb += doAmount;
// }
// }
//
// $("txt_rmbtotal").value = totalRmb;
// $("txt_usdtotal").value = totalUsd;
//
// var invoiceId = $("h_invoiceid").value;
// var urlVal = "InvoiceApplicationGridSource.aspx?handle=checkverifyfee&invoiceid="+invoiceId+"&checktype=1&cachename="+cacheName+"&verifyfee="+rId+"&val="+commonGridObj_feelist.newGuid();
// var loader = dhtmlxAjax.getSync(urlVal);
// var loadVal = loader.xmlDoc.responseText;
var invoiceId = $("h_invoiceid").value;
var rate = $("txt_rate").value.trim() == "" ? 0 : parseFloat($("txt_rate").value.trim());
var settleType = 0;
if($("ck_rmb").checked){
settleType = 1;
}else if($("ck_usd").checked){
settleType = 2;
}else{
settleType = 3;
}
var urlVal = "InvoiceApplicationGridSource.aspx?handle=checkverifyfee&invoiceid="+invoiceId+"&checktype=1&cachename="+cacheName+"&rate="+rate+"&settletype="+settleType+"&verifyfee="+rId+"&val="+commonGridObj_feelist.newGuid();
var loader = dhtmlxAjax.getSync(urlVal);
var loadVal = loader.xmlDoc.responseText;
if(loadVal.trim() != ""){
var totalObj = eval('(' + loadVal + ')');
if(totalObj.verify.length > 0){
if(totalObj.verify[0].state == 1){
$("txt_rmbtotal").value = totalObj.verify[0].rmb;
$("txt_usdtotal").value = totalObj.verify[0].usd;
// commonGridObj_feelist.initGrid();
// commonGridObj_feelist.bind();
}
}
}
}else{
// if($("ck_rmb").checked){
// if(currency == "USD"){
// totalRmb -= ForDight((doAmount*rate),2);
// }else if(currency == "RMB"){
// totalRmb -= doAmount;
// }
// }else if($("ck_usd").checked){
// if(currency == "RMB"){alert(totalUsd);
// totalUsd = ForDight(totalUsd - ForDight((doAmount/rate),2),2);
// }else if(currency == "USD"){
// totalUsd -= doAmount;
// }
// }else{
// if(currency == "USD"){
// totalUsd -= doAmount;
// }else if(currency == "RMB"){
// totalRmb -= doAmount;
// }
// }
// $("txt_rmbtotal").value = totalRmb;
// $("txt_usdtotal").value = totalUsd;
// var invoiceId = $("h_invoiceid").value;
// var urlVal = "InvoiceApplicationGridSource.aspx?handle=checkverifyfee&invoiceid="+invoiceId+"&checktype=2&cachename="+cacheName+"&verifyfee="+rId+"&val="+commonGridObj_feelist.newGuid();
// var loader = dhtmlxAjax.getSync(urlVal);
// var loadVal = loader.xmlDoc.responseText;
var invoiceId = $("h_invoiceid").value;
var rate = $("txt_rate").value.trim() == "" ? 0 : parseFloat($("txt_rate").value.trim());
var settleType = 0;
if($("ck_rmb").checked){
settleType = 1;
}else if($("ck_usd").checked){
settleType = 2;
}else{
settleType = 3;
}
var urlVal = "InvoiceApplicationGridSource.aspx?handle=checkverifyfee&invoiceid="+invoiceId+"&checktype=2&cachename="+cacheName+"&rate="+rate+"&settletype="+settleType+"&verifyfee="+rId+"&val="+commonGridObj_feelist.newGuid();
var loader = dhtmlxAjax.getSync(urlVal);
var loadVal = loader.xmlDoc.responseText;
if(loadVal.trim() != ""){
var totalObj = eval('(' + loadVal + ')');
if(totalObj.verify.length > 0){
if(totalObj.verify[0].state == 1){
$("txt_rmbtotal").value = totalObj.verify[0].rmb;
$("txt_usdtotal").value = totalObj.verify[0].usd;
// commonGridObj_feelist.initGrid();
// commonGridObj_feelist.bind();
}
}
}
}
});
}
commonGridObj_feelist.onCheckBox();
commonGridObj_feelist.isOnCheckBox = true;
}
function initCombo(){
createComboCustomer();//结算单位
}
function refreshList(){
createGrid();
}
//根据条件查询付费申请信息
function search(){
var _begintime = $("txt_beginDate").value.trim();
if(_begintime.trim() != ""){
if(!validateDateTime(_begintime)){
alert("起始时间格式错误");
return;
}
}
var _endtime = $("txt_endDate").value.trim();
if(_endtime.trim() != ""){
if(!validateDateTime(_endtime)){
alert("结束时间格式错误");
return;
}
}
var _customer = $("h_customer").value.trim();
var _checkno = $("txt_billno").value.trim();
var searchJson = "";
//begin
searchJson +="{";
searchJson += "[";
//如果查询条件设置了起始时间和结束时间则判断结束时间是否大于起始时间
if(_begintime != "" && _endtime != ""){
if(_begintime.length > 9 && _endtime.length > 9){
var status = DateTimeEqual(_begintime,_endtime);
if(status == 0){
searchJson += "\"btime\":\""+_begintime+"\","
searchJson += "\"etime\":\""+_endtime+"\","
}else if(status == -1){
alert("时间设置错误,起始时间不能大于结束时间,请修改!");
return;
}
// else if(status == -2){
// alert("时间设置错误,起始时间不能等于结束时间,请修改!");
// return;
// }
}
else{
alert("时间格式有问题,长度应大于9个字符,请修改!");
return;
}
}else{
searchJson += "\"btime\":\""+_begintime+"\","
searchJson += "\"etime\":\""+_endtime+"\","
}
searchJson += "\"cus\":\""+_customer+"\",";
searchJson += "\"no\":\""+_checkno+"\"";
searchJson += "]";
searchJson +="}";//alert(searchJson);
commonGridObj_invoicelist.initGrid();
commonGridObj_invoicelist.setRequest("InvoiceApplicationGridSource.aspx?handle=makeoutlist&show_page=15&cur_page=1&search="+escape(searchJson)+"&uid="+commonGridObj_invoicelist.newGuid());
commonGridObj_invoicelist.bind();
commonGridObj_invoicelist.setSearch(searchJson);
commonGridObj_invoicelist.initPageByHandle("makeoutlist");
commonGridObj_invoicelist.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
if(stage == 0){
if(cInd == 2 || cInd == 3){
return false;
}else{
return true;
}
}
});
commonGridObj_invoicelist.getGridObj().attachEvent("onRowDblClicked", function(rId,cInd){
var rId = commonGridObj_invoicelist.getGridObj().getSelectedRowId();
var openSet = "height=500, width=960, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top= " +(screen.height-710)/2 + ",Left= "+(screen.width-960)/2
var openType = "_blank";
var openUrl = "InvoiceMakeOutEdit.aspx?id="+rId+"&handle=edit";
window.open (openUrl,openType,openSet);
});
}
//校验时间格式
function validateDateTime(dateTimeObj){
var isValid = false;
var parseToObj = new Date(dateTimeObj.replace(/-/g, "/"));
if(!isNaN(parseToObj)){
isValid = true;
}
return isValid;
}
function DateTimeEqual(beginObj,endObj){
var isEqual = 0;
var begin = new Date(beginObj.replace(/-/g, "/"));
var end = new Date(endObj.replace(/-/g, "/"));
if(Date.parse(begin) - Date.parse(end) > 0){
isEqual = -1;//起始时间大于结束时间
}else if(Date.parse(begin) - Date.parse(end) == 0){
isEqual = -2;//起始时间与结束时间相等
}
return isEqual;
}
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
function createComboCustomer(){//委托单位
comboCustomer = dhtmlXComboFromSelect("sel_customer");
comboCustomer.loadXML("../FeeCodes/WebCrmClientAdapter.aspx?mask=0&pos=0");
comboCustomer.attachEvent("onChange", function(){
comboCustomer.setComboText($("h_customer").value);
});
comboCustomer.attachEvent("onBlur", function(){
var s1 = comboCustomer.getComboText().trim();
var s2 = s1.indexOf("|");
if(s2>0){
s2=s2+2;
}
var s3 = s1.substring(s2);
if(s2>0){
comboCustomer.setComboText(s3);
$("h_customer").value=s3;
}
else
{
comboCustomer.setComboText($("h_customer").value);
}
});
comboCustomer.setComboText($("h_customer").value);
comboCustomer.attachEvent("onKeyPressed", function(keyCode){
if(keyCode!="8"){
var arrayArg = new Array();
setTimeout(function(){
var filterCount = 0;
var is = -1;
var ishd = $("h_customer").value.trim();
if("" != comboCustomer.getComboText().trim()){
while("undefined" != typeof comboCustomer.getOptionByIndex(filterCount)){
var comboValue = comboCustomer.getOptionByIndex(filterCount).text.toUpperCase();//.value;
var enterValue = comboCustomer.getComboText().trim().toUpperCase();
$("h_customer").value = comboCustomer.getComboText().trim().toUpperCase();
if(comboValue.indexOf(enterValue) == 0){
comboCustomer.selectOption(filterCount,true,true);
is=filterCount;
break;
}
++filterCount;
}
if(is==-1){
$("h_customer").value = ishd;
alert("无此内容,请重新选择!");
}
}
},10);
}
});
comboCustomer.attachEvent("onSelectionChange", function(){
$("h_customer").value = comboCustomer.getComboText().trim();
});
}
//初始化界面
function initGrid(){
$("h_customer").value = "";
comboCustomer.setComboText($("h_customer").value);
$("txt_beginDate").value = "";
$("txt_endDate").value = "";
$("txt_billno").value = "";
createGrid();
}
function checkAll(){
var checkState = $("ck_all").checked;
var totalRmb = 0;
var totalUsd = 0;
totalRmb = $("txt_rmbtotal").value.trim() == "" ? 0 : parseFloat($("txt_rmbtotal").value.trim());
totalUsd = $("txt_usdtotal").value.trim() == "" ? 0 : parseFloat($("txt_usdtotal").value.trim());
var customerName = commonGridObj_feelist.getGridObj().cellByIndex(0,4).getValue();
if($("txt_customer").value.trim() == ""){
$("txt_customer").value = customerName;
}
if($("h_cacheid").value.trim() == ""){
$("h_cacheid").value = commonGridObj_feelist.newGuid();
}
var cacheName = $("h_cacheid").value;
if(checkState){
// for(var i=0;i<commonGridObj_feelist.getGridObj().getRowsNum();i++){
// var rowIndex = i
// var isChecked = commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,0).getValue();
// if(isChecked == 0){
// var doAmount = parseFloat(commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,7).getValue());
// var currency = commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,14).getValue();
// //var rate = parseFloat(commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,15).getValue());
// var rate = parseFloat($("txt_rate").value.trim());
//
// if($("ck_rmb").checked){
// if(currency == "USD"){
// totalRmb += ForDight((doAmount/rate),2);
// }else if(currency == "RMB"){
// totalRmb += doAmount;
// }
// }else if($("ck_usd").checked){
// if(currency == "RMB"){
// totalUsd += ForDight((doAmount/rate),2);
// }else if(currency == "USD"){
// totalUsd += doAmount;
// }
// }else{
// if(currency == "USD"){
// totalUsd += doAmount;
// }else if(currency == "RMB"){
// totalRmb += doAmount;
// }
// }
// commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,0).setValue(1);
// }
// }
var invoiceId = $("h_invoiceid").value;
var rate = $("txt_rate").value.trim() == "" ? 0 : parseFloat($("txt_rate").value.trim());
var settleType = 0;
if($("ck_rmb").checked){
settleType = 1;
}else if($("ck_usd").checked){
settleType = 2;
}else{
settleType = 3;
}
var urlVal = "InvoiceApplicationGridSource.aspx?handle=checkverifyfee&invoiceid="+invoiceId+"&checktype=3&cachename="+cacheName+"&rate="+rate+"&settletype="+settleType+"&val="+commonGridObj_feelist.newGuid();
var loader = dhtmlxAjax.getSync(urlVal);
var loadVal = loader.xmlDoc.responseText;
if(loadVal.trim() != ""){
var totalObj = eval('(' + loadVal + ')');
if(totalObj.verify.length > 0){
if(totalObj.verify[0].state == 1){
$("txt_rmbtotal").value = totalObj.verify[0].rmb;
$("txt_usdtotal").value = totalObj.verify[0].usd;
createGrid();
$("ck_all").checked = true;
}
}
}
}else{
// for(var i=0;i<commonGridObj_feelist.getGridObj().getRowsNum();i++){
// var rowIndex = i;//commonGridObj_feelist.getGridObj().getRowIndex(rId);
// var isChecked = commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,0).getValue();
// if(isChecked == 1){
// var doAmount = parseFloat(commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,7).getValue());
// var currency = commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,14).getValue();
// //var rate = parseFloat(commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,15).getValue());
// var rate = parseFloat($("txt_rate").value.trim());
//
//
// if($("ck_rmb").checked){
// if(currency == "USD"){
// totalRmb -= ForDight((doAmount*rate),2);
// }else if(currency == "RMB"){
// totalRmb -= doAmount;
// }
// }else if($("ck_usd").checked){
// if(currency == "RMB"){
// totalUsd = ForDight(totalUsd - ForDight((doAmount/rate),2),2);
// }else if(currency == "USD"){
// totalUsd -= doAmount;
// }
// }else{
// if(currency == "USD"){
// totalUsd -= doAmount;
// }else if(currency == "RMB"){
// totalRmb -= doAmount;
// }
// }
// commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,0).setValue(0);
// }
// }
var invoiceId = $("h_invoiceid").value;
var rate = $("txt_rate").value.trim() == "" ? 0 : parseFloat($("txt_rate").value.trim());
var settleType = 0;
if($("ck_rmb").checked){
settleType = 1;
}else if($("ck_usd").checked){
settleType = 2;
}else{
settleType = 3;
}
var urlVal = "InvoiceApplicationGridSource.aspx?handle=checkverifyfee&invoiceid="+invoiceId+"&checktype=4&cachename="+cacheName+"&rate="+rate+"&settletype="+settleType+"&val="+commonGridObj_feelist.newGuid();
var loader = dhtmlxAjax.getSync(urlVal);
var loadVal = loader.xmlDoc.responseText;
if(loadVal.trim() != ""){
var totalObj = eval('(' + loadVal + ')');
if(totalObj.verify.length > 0){
if(totalObj.verify[0].state == 1){
$("txt_rmbtotal").value = totalObj.verify[0].rmb;
$("txt_usdtotal").value = totalObj.verify[0].usd;
createGrid();
}
}
}
}
}
function saveVerification(){
// var feeObj = null;
var iCount = 0;
for(var i=0;i<commonGridObj_feelist.getGridObj().getRowsNum();i++){
if(commonGridObj_feelist.getGridObj().cellByIndex(i,0).getValue() == 1){
iCount++;
// var rowId = commonGridObj_feelist.getGridObj().getRowId(i);
// var rowIndex = commonGridObj_feelist.getGridObj().getRowIndex(rowId);
// if(feeObj == null){
// var cacheBuffer = "";
// cacheBuffer += "{";
// cacheBuffer += "\"id\":\""+rowId+"\",";
// var feeType = commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,1).getValue() == "收"?1:2;
// cacheBuffer += "\"type\":"+feeType+",";
// cacheBuffer += "\"bsno\":\""+commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,17).getValue()+"\",";
// cacheBuffer += "\"cus\":\""+commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,4).getValue()+"\",";
// cacheBuffer += "\"fname\":\""+commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,5).getValue()+"\",";
// cacheBuffer += "\"cur\":\""+commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,14).getValue()+"\",";
// cacheBuffer += "\"cstl\":\""+commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,7).getValue()+"\",";//本次结算
// cacheBuffer += "\"ustl\":\""+commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,8).getValue()+"\",";//未结
// cacheBuffer += "\"orig\":\"1\",";//原始类型
// cacheBuffer += "\"oname\":\""+commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,5).getValue()+"\",";//更改费用名称
// cacheBuffer += "\"ocstl\":"+commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,7).getValue()+"";//更改费用值
// cacheBuffer += "}";
//
// var result = "";
// result += "{\"feelist\":[";
// result += cacheBuffer;
// result += "]}";
// //生成新的缓存数据对象
// feeObj = eval('(' + result + ')');
// }else{
// //获取费用类型
// var feeType = commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,1).getValue() == "收"?1:2;
//
// var newCache = feeObj.feelist;
// newCache = {id:rowId,type:feeType,bsno:commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,14).getValue().toString(),cus:commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,3).getValue().toString(),
// fname:commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,2).getValue(),cur:commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,8).getValue(),
// cstl:commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,10).getValue(),ustl:commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,11).getValue(),
// orig:"1",oname:commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,2).getValue(),ocstl:commonGridObj_feelist.getGridObj().cellByIndex(rowIndex,10).getValue()};
// //alert(newCache);
// feeObj.feelist.push(newCache);
// }
}
}
if(iCount > 0){
$("h_rmbtotal").value = $("txt_rmbtotal").value;
$("h_usdtotal").value = $("txt_usdtotal").value;
$("h_customer").value = $("txt_customer").value.trim();
$("h_remark").value = $("txt_remark").value.trim();
$("h_remark").value = $("txt_remark").value.trim();
$("h_settlemode").value = $("sel_settlemode").value.trim();
var skj = $("sel_settlemode").value.trim();
//$("h_feelist").value = JSON.stringify(feeObj);
$("h_post").value = "1";
//提交结算信息
var iResult = postEnterFee();
if (iResult==1) {
alert("结算完毕!")
window.parent.opener.location.href = window.parent.opener.location.href;
window.close();
}
}else{
alert("没有要提交结算的费用信息");
}
}
function postEnterFee(){
var myForm = document.getElementById("form1");
myForm.submit() ;
}
function outputMoney(number) {
number= number.replace(/\,/g,"");
if (isNaN(number)||number=="") return "";
number = Math.round( number*100) /100;
if(number<0)
return '-'+outputDollars(Math.floor(Math.abs(number)-0) + '') + outputCents(Math.abs(number) - 0);
else
return outputDollars(Math.floor(number-0) + '') + outputCents(number - 0);
}
function outputDollars(number)
{
if (number.length<= 3)
return (number == '' ? '0' : number);
else
{
var mod = number.length%3;
var output = (mod == 0 ? '' : (number.substring(0,mod)));
for (i=0 ; i< Math.floor(number.length/3) ; i++)
{
if ((mod ==0) && (i ==0))
output+= number.substring(mod+3*i,mod+3*i+3);
else
output+= ',' + number.substring(mod+3*i,mod+3*i+3);
}
return (output);
}
}
function outputCents(amount)
{
amount = Math.round( ( (amount) - Math.floor(amount) ) *100);
return (amount<10 ? '.0' + amount : '.' + amount);
}
function ConvertToMoney(strObj){
var result = strObj.replace(",","");
return result;
}
function clearNoNum(valObj)
{
//先把非数字的都替换掉,除了数字和.
valObj = valObj.replace(/[^\d.]/g,"");
//必须保证第一个为数字而不是.
valObj = valObj.replace(/^\./g,"");
//保证只有出现一个.而没有多个.
valObj = valObj.replace(/\.{2,}/g,".");
//保证.只出现一次,而不能出现两次以上
valObj = valObj.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
if(valObj.indexOf(".") == valObj.length-1){
valObj += "0";
}
return valObj;
}
function isObjNaN(Obj){
if(Obj.toString().toLowerCase() == "nan"){
return 0;
}else{
return Obj;
}
}
function initBank(){
var bankInfo = $("h_bankcache").value;
var bankObj = eval('(' + bankInfo + ')');
var isRmb = $("ck_rmb").checked;
var isUsd = $("ck_usd").checked;
$("sel_usdbank").options.length = 0;
if(bankObj != null){
if(bankObj.banks.length > 0){
for(var i=0;i<bankObj.banks.length;i++){
if(isRmb){
if(bankObj.banks[i].cur == "RMB"){
var newOption = new Option(bankObj.banks[i].bank,bankObj.banks[i].id);
$("sel_rmbbank").options.add(newOption);
}
}else if(isUsd){
if(bankObj.banks[i].cur == "USD"){
var newOption = new Option(bankObj.banks[i].bank,bankObj.banks[i].id);
$("sel_usdbank").options.add(newOption);
}
}else{
if(bankObj.banks[i].cur == "RMB"){
var newOption = new Option(bankObj.banks[i].bank,bankObj.banks[i].id);
$("sel_rmbbank").options.add(newOption);
}else if(bankObj.banks[i].cur == "USD"){
var newOption = new Option(bankObj.banks[i].bank,bankObj.banks[i].id);
$("sel_usdbank").options.add(newOption);
}
}
}
}
}
}
function onCheckEvent(id,other){
$(other).checked = false;
//initBank();
// var totalRmb = $("txt_rmbtotal").value.trim() == "" ? 0 : parseFloat($("txt_rmbtotal").value.trim());
// var totalUsd = $("txt_usdtotal").value.trim() == "" ? 0 : parseFloat($("txt_usdtotal").value.trim());
// initExchangeRate();
// var rate = $("txt_rate").value.trim() == "" ? 0 : parseFloat($("txt_rate").value.trim());
//
// if(id == "ck_usd"){
// if(totalRmb > 0){
// totalUsd += ForDight((totalRmb/rate),2);
// totalRmb = 0;
// }
// }else if(id == "ck_rmb"){
// if(totalUsd > 0){
// totalRmb += ForDight((totalUsd/rate),1);
// totalUsd = 0;
// }
// }else{
// $("rate").value = "";
// }
initExchangeRate();
//var invoiceId = $("h_invoiceid").value;
//var doAmount = ConvertToMoney(outputMoney(cstl.toString()));
//var unDoAmount = ConvertToMoney(outputMoney(newStl.toString()));
var rate = $("txt_rate").value.trim() == "" ? 0 : parseFloat($("txt_rate").value.trim());
var settleType = 0;
if($("ck_rmb").checked){
settleType = 1;
}else if($("ck_usd").checked){
settleType = 2;
}else{
settleType = 3;
}
if($("h_cacheid").value.trim() == ""){
$("h_cacheid").value = commonGridObj_feelist.newGuid();
}
var cacheName = $("h_cacheid").value;
var urlVal = "InvoiceApplicationGridSource.aspx?handle=verifyfeerate&cachename="+cacheName+"&rate="+rate+"&settletype="+settleType+"&val="+commonGridObj_feelist.newGuid();
var loader = dhtmlxAjax.getSync(urlVal);
var loadVal = loader.xmlDoc.responseText;
if(loadVal.trim() != ""){
var totalObj = eval('(' + loadVal + ')');
if(totalObj.verify.length > 0){
if(totalObj.verify[0].state == 1){
$("txt_rmbtotal").value = totalObj.verify[0].rmb;
$("txt_usdtotal").value = totalObj.verify[0].usd;
// commonGridObj_feelist.initGrid();
// commonGridObj_feelist.bind();
}
}
}else{
$("txt_rmbtotal").value = "0";
$("txt_usdtotal").value = "0";
}
// $("txt_rmbtotal").value = totalRmb;
// $("txt_usdtotal").value = totalUsd;
}
function initExchangeRate(){
var urlVal = "../feecodes/CurrencyAdapter.aspx?handle=drate&val="+commonGridObj_feelist.newGuid();
var loader = dhtmlxAjax.getSync(urlVal);
var loadVal = loader.xmlDoc.responseText;
loader = null;
var jsonCacheObj;
var rmbRate = 0.0;
var usdRate = 0.0;
if(loadVal.length > 0){
jsonCacheObj = eval('(' + loadVal + ')');
if(jsonCacheObj != null){
for(var i = 0;i<jsonCacheObj.drate.length;i++){
if($("ck_usd").checked){
if(jsonCacheObj.drate[i].code == "USD"){
$("txt_rate").value = parseFloat(jsonCacheObj.drate[i].drate);
}
}else{
if(jsonCacheObj.drate[i].code == "USD"){
//$("txt_rate").value = ForDight((1/parseFloat(jsonCacheObj.drate[i].drate)),4);
$("txt_rate").value = parseFloat(jsonCacheObj.drate[i].drate);
}
}
}
}
}
}
//取消结算
function cancelVerification(){
}
/*
* ForDight(Dight,How):数值格式化函数Dight要
* 格式化的 数字How要保留的小数位数
*/
function ForDight(Dight,How){
Dight = Math.round(Dight*Math.pow(10,How))/Math.pow(10,How);
return Dight;
}
function onRatePress(){
var rate = $("txt_rate").value.trim() == "" ? 0 : parseFloat($("txt_rate").value.trim());
var settleType = 0;
if($("ck_rmb").checked){
settleType = 1;
}else if($("ck_usd").checked){
settleType = 2;
}else{
settleType = 3;
}
if($("h_cacheid").value.trim() == ""){
$("h_cacheid").value = commonGridObj_feelist.newGuid();
}
var cacheName = $("h_cacheid").value;
var urlVal = "InvoiceApplicationGridSource.aspx?handle=verifyfeerate&cachename="+cacheName+"&rate="+rate+"&settletype="+settleType+"&val="+commonGridObj_feelist.newGuid();
var loader = dhtmlxAjax.getSync(urlVal);
var loadVal = loader.xmlDoc.responseText;
if(loadVal.trim() != ""){
var totalObj = eval('(' + loadVal + ')');
if(totalObj.verify.length > 0){
if(totalObj.verify[0].state == 1){
$("txt_rmbtotal").value = totalObj.verify[0].rmb;
$("txt_usdtotal").value = totalObj.verify[0].usd;
}
}
}else{
$("txt_rmbtotal").value = "0";
$("txt_usdtotal").value = "0";
}
}