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/DoPayApplicationSettlement.js

861 lines
36 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

var commonGridObj_do;
var jsonCacheObj;
function $(id){
return document.getElementById(id);
}
function createGrid(){
//header 0 1 2 3 4 5 6 7 8
var headerArgs_do = new Array("应结币别", "申请金额", "应结金额", "本次结算", "未结", "实结币别", "实结汇率", "实结金额", "出账账户");
//width
var widthArgs_do = new Array("70", "80", "80", "80", "80", "80", "80", "80", "300");
//column align
var colAlignArgs_do = new Array("center", "center", "center", "center", "center", "center", "center", "center", "center");
//column sort
var colSortArgs_do = new Array("str", "str", "str", "str", "str", "str", "str", "str", "str");
//column type
var colTypeArgs_do = new Array("ro", "ro", "ro", "ed", "ro", "co", "ed", "ed", "co");
commonGridObj_do = new TGridCommon("mygrid_container_paydo","form1",headerArgs_do,widthArgs_do,colAlignArgs_do,colSortArgs_do,colTypeArgs_do);
commonGridObj_do.setResponseUrl("SettlementGridSource.aspx");
//var _billno = $("billno").value;
commonGridObj_do.setResponseUrl("SettlementGridSource.aspx");
commonGridObj_do.setSourceType("json");
commonGridObj_do.setSkin("xp");
commonGridObj_do.setImageUrl("../images/");
commonGridObj_do.initGrid();
//commonGridObj_do.bind();
commonGridObj_do.getGridObj().init();
commonGridObj_do.getGridObj().enableEditEvents(true, false, true);
commonGridObj_do.getGridObj().enableMultiselect(true);
commonGridObj_do.getGridObj().enableKeyboardSupport(true);
commonGridObj_do.getGridObj().attachEvent("onEditCell", function (stage, rId, cInd, nValue, oValue) {
if (stage == 0) {
return true;
}
if (stage == 1) {
var txtEdit;
for (i = 0; i < document.all.length; i++) {
if (document.all(i).tagName == "TEXTAREA") {
txtEdit = document.all(i);
txtEdit.focus();
txtEdit.select();
break;
}
}
return true;
}
if (stage == 2) {
if (cInd == 3) {
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rId);
var amount = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd - 1).getValue().trim());
var ctl = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd).getValue().trim());
var rate2 = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, 6).getValue().trim());
//if (ctl > amount) {
if (ctl == amount) {
commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd).setLabel(amount);
commonGridObj_do.getGridObj().cellByIndex(rowIndex, 4).setLabel("0");
}
else {
var tctl = amount - ctl;
commonGridObj_do.getGridObj().cellByIndex(rowIndex, 4).setLabel(tctl);
}
var amount2 = round2(ctl * rate2, 2);
commonGridObj_do.getGridObj().cellByIndex(rowIndex, 7).setLabel(amount2);
$("txt_je1").value = amount2;
$("h_je1").value = amount2;
$("txt_je3").value = amount2;
}
else if (cInd == 5) {
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rId);
var cur2 = commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd).getValue().trim();
$("ddl_bb1").value = cur2;
$("ddl_bb3").value = cur2;
}
else if (cInd == 6) {
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rId);
var cur = commonGridObj_do.getGridObj().cellByIndex(rowIndex, 0).getValue().trim();
var cur2 = commonGridObj_do.getGridObj().cellByIndex(rowIndex, 5).getValue().trim();
var ctr = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, 3).getValue().trim());
var rate2 = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd).getValue().trim());
if (cur == cur2) {
return false;
}
var amount2 = round2(ctr * rate2, 2);
commonGridObj_do.getGridObj().cellByIndex(rowIndex, 7).setLabel(amount2);
$("txt_je1").value = amount2;
$("h_je1").value = amount2;
$("txt_je3").value = amount2;
}
else if (cInd == 7) {
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rId);
var cur = commonGridObj_do.getGridObj().cellByIndex(rowIndex, 0).getValue().trim();
var ctr = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, 3).getValue().trim());
var cur2 = commonGridObj_do.getGridObj().cellByIndex(rowIndex, 5).getValue().trim();
var amount2 = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd).getValue().trim());
if (cur == cur2) {
return false;
}
//
var rate2 = round2(amount2 / ctr, 4);
commonGridObj_do.getGridObj().cellByIndex(rowIndex, 6).setLabel(rate2);
$("txt_je1").value = amount2;
$("h_je1").value = amount2;
$("txt_je3").value = amount2;
}
return true;
}
});
//键盘操作事件
commonGridObj_do.getGridObj().attachEvent("onKeyPress", function (code, cFlag, sFlag) {
//获取当前CellIndex(ind)
var ind = commonGridObj_do.getGridObj().getSelectedCellIndex();
if (code >= 65 && code <= 90) {//如果是输入英文字符
if (ind != 4) {
return false;
}
}
return true;
});
setTimeout(function(){
//获取结算信息
if($("h_settleinfo").value != ""){
var tempSettleInfo = $("h_settleinfo").value;
var jsonSettleObj = null;
jsonSettleObj = eval('(' + tempSettleInfo + ')');
if(jsonSettleObj.settles[0].bank.trim() != ""){
for (var k = 0; k < jsonSettleObj.settles.length; k++) {
//header 0 1 2 3 4 5 6 7 8
//var headerArgs_do = new Array("应结币别", "申请金额", "应结金额", "本次结算", "未结", "实结币别", "实结费率", "实结金额", "出账账户");
commonGridObj_do.getGridObj().addRow(jsonSettleObj.settles[k].id, [jsonSettleObj.settles[k].cur, jsonSettleObj.settles[k].applyamount, jsonSettleObj.settles[k].amount, jsonSettleObj.settles[k].ctl, jsonSettleObj.settles[k].uctl, jsonSettleObj.settles[k].cur2, jsonSettleObj.settles[k].rate2, jsonSettleObj.settles[k].amount2, jsonSettleObj.settles[k].bank], 0);
commonGridObj_do.bind();
}
commonGridObj_do.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
if(stage == 0){
return false;
}
});
} else {
var settleCurrency = $("h_settlecurrency").value;
var url = "SettlementGridSource.aspx?handle=bankinfo&uid="+commonGridObj_do.newGuid();//银行账号信息
var loader = dhtmlxAjax.getSync(url);
var bankInfo = loader.xmlDoc.responseText;
var jsonCacheObj = eval('(' + bankInfo + ')');
var isRun = false;
if(commonGridObj_do.getGridObj().getRowsNum() > 0){
for(var i=0;i < commonGridObj_do.getGridObj().getRowsNum();i++){
var rowId = commonGridObj_do.getGridObj().getRowId(i);
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rowId);
for(var j = 0;j<jsonSettleObj.settles.length;j++){
if(jsonSettleObj.settles[i].id = rowId){
commonGridObj_do.getGridObj().cellByIndex(rowIndex,8).setLabel(jsonSettleObj.settles[i].bank);
isRun = true;
break;
}
}
commonGridObj_do.bind();
}
if(isRun){
commonGridObj_do.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
if(stage == 0){
return false;
}
});
}
}else{
commonGridObj_do.initGrid();
commonGridObj_do.getGridObj().enableEditEvents(true, false, true);
commonGridObj_do.getGridObj().enableMultiselect(true);
commonGridObj_do.getGridObj().enableKeyboardSupport(true);
commonGridObj_do.getGridObj().attachEvent("onEditCell", function (stage, rId, cInd, nValue, oValue) {
if (stage == 0) {
return true;
}
if (stage == 1) {
var txtEdit;
for (i = 0; i < document.all.length; i++) {
if (document.all(i).tagName == "TEXTAREA") {
txtEdit = document.all(i);
txtEdit.focus();
txtEdit.select();
break;
}
}
return true;
}
if (stage == 2) {
if (cInd == 3) {
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rId);
var amount = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd - 1).getValue().trim());
var ctl = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd).getValue().trim());
var rate2 = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, 6).getValue().trim());
//if (ctl > amount) {
if (ctl == amount) {
commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd).setLabel(amount);
commonGridObj_do.getGridObj().cellByIndex(rowIndex, 4).setLabel("0");
}
else {
var tctl = amount - ctl;
commonGridObj_do.getGridObj().cellByIndex(rowIndex, 4).setLabel(tctl);
}
var amount2 = round2(ctl * rate2, 2);
commonGridObj_do.getGridObj().cellByIndex(rowIndex, 7).setLabel(amount2);
$("txt_je1").value = amount2;
$("h_je1").value = amount2;
$("txt_je3").value = amount2;
}
else if (cInd == 5) {
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rId);
var cur2 = commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd).getValue().trim();
$("ddl_bb1").value = cur2;
$("ddl_bb3").value = cur2;
}
else if (cInd == 6) {
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rId);
var cur = commonGridObj_do.getGridObj().cellByIndex(rowIndex, 0).getValue().trim();
var cur2 = commonGridObj_do.getGridObj().cellByIndex(rowIndex, 5).getValue().trim();
var ctr = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, 3).getValue().trim());
var rate2 = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd).getValue().trim());
if (cur == cur2) {
return false;
}
var amount2 = round2(ctr * rate2, 2);
commonGridObj_do.getGridObj().cellByIndex(rowIndex, 7).setLabel(amount2);
$("txt_je1").value = amount2;
$("h_je1").value = amount2;
$("txt_je3").value = amount2;
}
else if (cInd == 7) {
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rId);
var cur = commonGridObj_do.getGridObj().cellByIndex(rowIndex, 0).getValue().trim();
var ctr = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, 3).getValue().trim());
var cur2 = commonGridObj_do.getGridObj().cellByIndex(rowIndex, 5).getValue().trim();
var amount2 = parseFloat(commonGridObj_do.getGridObj().cellByIndex(rowIndex, cInd).getValue().trim());
if (cur == cur2) {
return false;
}
//
var rate2 = round2(amount2 / ctr, 4);
commonGridObj_do.getGridObj().cellByIndex(rowIndex, 6).setLabel(rate2);
$("txt_je1").value = amount2;
$("h_je1").value = amount2;
$("txt_je3").value = amount2;
}
return true;
}
});
//键盘操作事件
commonGridObj_do.getGridObj().attachEvent("onKeyPress", function (code, cFlag, sFlag) {
//获取当前CellIndex(ind)
var ind = commonGridObj_do.getGridObj().getSelectedCellIndex();
if (code >= 65 && code <= 90) {//如果是输入英文字符
if (ind != 8) {
return false;
}
}
return true;
});
//header 0 1 2 3 4 5 6 7 8
//var headerArgs_do = new Array("应结币别", "申请金额", "应结金额", "本次结算", "未结", "实结币别", "实结费率", "实结金额", "出账账户");
for (var j = 0; j < jsonSettleObj.settles.length; j++) {
if(jsonSettleObj.settles[j].cur == "RMB"){
var newId = commonGridObj_do.newGuid();
commonGridObj_do.getGridObj().addRow(newId, ["RMB", jsonSettleObj.settles[j].applyamount, jsonSettleObj.settles[j].amount, jsonSettleObj.settles[j].ctl, jsonSettleObj.settles[j].uctl, "RMB", jsonSettleObj.settles[j].rate2, jsonSettleObj.settles[j].amount2, ""], 0);
//
var newCombo2 = commonGridObj_do.getGridObj().getCustomCombo(newId, 5);
newCombo2.put("RMB", "RMB");
newCombo2.put("USD", "USD");
newCombo2.put("", "");
//
//commonGridObj_do.bind();
for(var k=0;k<jsonCacheObj.banks.length;k++){
if(jsonCacheObj.banks[k].cur == "RMB"){
var newCombo = commonGridObj_do.getGridObj().getCustomCombo(newId,8);
newCombo.put(jsonCacheObj.banks[k].id,jsonCacheObj.banks[k].bank);
//commonGridObj_do.bind();
}
}
}
if(jsonSettleObj.settles[j].cur == "USD"){
var newId = commonGridObj_do.newGuid();
if(commonGridObj_do.getGridObj().getRowsNum() > 0){
commonGridObj_do.getGridObj().addRow(newId, ["USD", jsonSettleObj.settles[j].applyamount, jsonSettleObj.settles[j].amount, jsonSettleObj.settles[j].ctl, jsonSettleObj.settles[j].uctl, "USD", jsonSettleObj.settles[j].rate2, jsonSettleObj.settles[j].amount2, ""], 1);
}else{
commonGridObj_do.getGridObj().addRow(newId, ["USD", jsonSettleObj.settles[j].applyamount, jsonSettleObj.settles[j].amount, jsonSettleObj.settles[j].ctl, jsonSettleObj.settles[j].uctl, "USD", jsonSettleObj.settles[j].rate2, jsonSettleObj.settles[j].amount2, ""], 0);
}
//
var newCombo2 = commonGridObj_do.getGridObj().getCustomCombo(newId, 5);
newCombo2.put("RMB", "RMB");
newCombo2.put("USD", "USD");
newCombo2.put("", "");
//
//commonGridObj_do.bind();
for(var k=0;k<jsonCacheObj.banks.length;k++){
if(jsonCacheObj.banks[k].cur == "USD"){
var newCombo = commonGridObj_do.getGridObj().getCustomCombo(newId,8);
newCombo.put(jsonCacheObj.banks[k].id,jsonCacheObj.banks[k].bank);
//commonGridObj_do.bind();
}
}
}
}
}
}
}
},50);
function round2(number, fractionDigits) {
with (Math) {
return round(number * pow(10, fractionDigits)) / pow(10, fractionDigits);
}
}
//合并结算的内容处理
if ($("h_total").value.trim() != "") {
var totalCache = $("h_total").value;
var totalObj = eval('(' + totalCache + ')');
if (totalObj.totals[0].totalrmb != 0) {
var newId = commonGridObj_do.newGuid();
var rowCount = commonGridObj_do.getGridObj().getRowsNum();
commonGridObj_do.getGridObj().addRow(newId, ["RMB", totalObj.totals[0].totalrmb], rowCount);
}
if (totalObj.totals[0].totalusd != 0) {
var newId = commonGridObj_do.newGuid();
var rowCount = commonGridObj_do.getGridObj().getRowsNum();
commonGridObj_do.getGridObj().addRow(newId, ["USD", totalObj.totals[0].totalusd], rowCount);
}
}
var iCount = 0;
var settleCurrency = $("h_settlecurrency").value;
var url = "SettlementGridSource.aspx?handle=bankinfo&uid="+commonGridObj_do.newGuid();//银行账号信息
var loader = dhtmlxAjax.getSync(url);
var bankInfo = loader.xmlDoc.responseText;
var jsonCacheObj = eval('(' + bankInfo + ')');
for(var i=0;i < commonGridObj_do.getGridObj().getRowsNum();i++){
var rowId = commonGridObj_do.getGridObj().getRowId(i);
var newCombo2 = commonGridObj_do.getGridObj().getCustomCombo(rowId, 5);
newCombo2.put("RMB", "RMB");
newCombo2.put("USD", "USD");
newCombo2.put("", "");
//
var newCombo = commonGridObj_do.getGridObj().getCustomCombo(rowId,8);
for(var j=0;j < jsonCacheObj.banks.length;j++){
if(commonGridObj_do.getGridObj().cellByIndex(i,0).getValue().trim() == jsonCacheObj.banks[j].cur){
newCombo.put(jsonCacheObj.banks[j].id,jsonCacheObj.banks[j].bank);
}
}
if($("h_usdaccount").value.trim() != "" && commonGridObj_do.getGridObj().cellByIndex(i,0).getValue().length > 0){
if(commonGridObj_do.getGridObj().cellByIndex(i,0).getValue().trim() == "USD"){
commonGridObj_do.getGridObj().cellByIndex(i,8).setValue($("h_usdaccount").value.trim());
}
}
if($("h_rmbaccount").value.trim() != "" && commonGridObj_do.getGridObj().cellByIndex(i,0).getValue().length > 0){
if(commonGridObj_do.getGridObj().cellByIndex(i,0).getValue().trim() == "RMB"){
commonGridObj_do.getGridObj().cellByIndex(i,8).setValue($("h_rmbaccount").value.trim());
}
}
}
}
function postSettle(){
if (commonGridObj_do != null) {
// var je1 = round2((parseFloat($("txt_je1").value.trim()) + parseFloat($("txt_je2").value.trim())), 2);
// var je2 = round2((parseFloat($("txt_je3").value.trim()) + parseFloat($("txt_je4").value.trim()) + parseFloat($("txt_je5").value.trim())), 2);
// if (je1 != je2) {
// alert("财务科目不平衡,请重新填写!");
// return false;
// }
//
var jsonSettleObj = null;
$("h_settleinfo").value = "";
for(var i = 0;i <commonGridObj_do.getGridObj().getRowsNum();i++){
//alert(commonGridObj_do.getGridObj().getRowId(0));alert(commonGridObj_do.getGridObj().getRowId(1));
var rId = commonGridObj_do.getGridObj().getRowId(i);
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rId);
var tempSettleInfo = $("h_settleinfo").value;
if(tempSettleInfo == ""){
var cacheBuffer = "";
cacheBuffer += "{";
cacheBuffer += "\"id\":\""+rId+"\",";
cacheBuffer += "\"cur\":\""+commonGridObj_do.getGridObj().cellByIndex(rowIndex,0).getValue()+"\",";//币别
cacheBuffer += "\"applyamount\":\"" + commonGridObj_do.getGridObj().cellByIndex(rowIndex, 1).getValue() + "\","; //币别
cacheBuffer += "\"amount\":\"" + commonGridObj_do.getGridObj().cellByIndex(rowIndex, 2).getValue() + "\","; //金额
cacheBuffer += "\"ctl\":\"" + commonGridObj_do.getGridObj().cellByIndex(rowIndex, 3).getValue() + "\","; //金额
cacheBuffer += "\"uctl\":\"" + commonGridObj_do.getGridObj().cellByIndex(rowIndex, 4).getValue() + "\","; //金额
cacheBuffer += "\"cur2\":\""+commonGridObj_do.getGridObj().cellByIndex(rowIndex,5).getValue()+"\",";//币别
cacheBuffer += "\"rate2\":\""+commonGridObj_do.getGridObj().cellByIndex(rowIndex,6).getValue()+"\",";//币别
cacheBuffer += "\"amount2\":\"" + commonGridObj_do.getGridObj().cellByIndex(rowIndex, 7).getValue() + "\","; //金额
cacheBuffer += "\"account\":\""+commonGridObj_do.getGridObj().cellByIndex(rowIndex,8).getValue()+"\",";//入账账户GID
cacheBuffer += "\"bank\":\""+commonGridObj_do.getGridObj().cellByIndex(rowIndex,8).getText()+"\"";//入账账户显示信息
cacheBuffer += "}";
var result = "";
result += "{\"settles\":[";
result += cacheBuffer;
result += "]}";
jsonSettleObj = eval('(' + result + ')');
$("h_settleinfo").value = JSON.stringify(jsonSettleObj);
}
else{
jsonSettleObj = eval('(' + tempSettleInfo + ')');
var newSettles = jsonSettleObj.settles;
newSettles = { id: rId, cur: commonGridObj_do.getGridObj().cellByIndex(rowIndex, 0).getValue(), applyamount: commonGridObj_do.getGridObj().cellByIndex(rowIndex, 1).getValue(), amount: commonGridObj_do.getGridObj().cellByIndex(rowIndex, 2).getValue(), ctl: commonGridObj_do.getGridObj().cellByIndex(rowIndex, 3).getValue(), uctl: commonGridObj_do.getGridObj().cellByIndex(rowIndex, 4).getValue(), cur2: commonGridObj_do.getGridObj().cellByIndex(rowIndex, 5).getValue(), rate2: commonGridObj_do.getGridObj().cellByIndex(rowIndex, 6).getValue(), amount2: commonGridObj_do.getGridObj().cellByIndex(rowIndex, 7).getValue(), account: commonGridObj_do.getGridObj().cellByIndex(rowIndex, 8).getValue(), bank: commonGridObj_do.getGridObj().cellByIndex(rowIndex, 8).getText() };
jsonSettleObj.settles.push(newSettles);
$("h_settleinfo").value = JSON.stringify(jsonSettleObj);
}
}
//window.opener.location.href=window.opener.location.href;
}
commonGridObj_do.getGridObj().editStop();
for(var i=0;i < commonGridObj_do.getGridObj().getRowsNum();i++){
if(commonGridObj_do.getGridObj().cellByIndex(i,0).getValue().trim() == "USD"){
$("h_usdaccount").value = commonGridObj_do.getGridObj().cellByIndex(i,8).getValue().trim();
}else if(commonGridObj_do.getGridObj().cellByIndex(i,0).getValue().trim() == "RMB"){
$("h_rmbaccount").value = commonGridObj_do.getGridObj().cellByIndex(i,8).getValue().trim();
}
}
var skj = $("h_rmbaccount").value;
$("h_enter").value = "1";
if ($("h_isAccess").value.trim() == "1") {
var fhz = saveRecvChange2();
}
postEnterFee();
}
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("$#$",".");
return valObj;
}
function isObjNaN(Obj){
if(Obj.toString().toLowerCase() == "nan"){
return 0;
}else{
return Obj;
}
}
function moneyMath(original){
var result = Math.round(original*100)/100;
return result;
}
function cancelSettle(){
window.opener.location.href=window.opener.location.href;
window.opener='null';window.close();
}
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
function printSettle(){
var strBillNO = "";
var typeName = "";
strBillNO = $("txt_billNO").value;
if(strBillNO.trim() != ""){
var printUrl = "";
var companyID = "";
var typeName = "PAYSETTLE";
var dbSourceID = "";
var userID = "";
var url = "";
url = "../Reports/ReportService.aspx?handle=printpaysettle&billno="+strBillNO+"&val="+commonGridObj_do.newGuid();
typeName = "PAYSETTLE";
var loader = dhtmlxAjax.getSync(url);
var reportVal = loader.xmlDoc.responseText;
var reportObj = null;
if(reportVal != ""){
reportObj = eval('(' + reportVal + ')');
if(reportObj.reports.length > 0){
if(reportObj.reports[0].compid != ""){
companyID = reportObj.reports[0].compid;
}
if(reportObj.reports[0].sourceid != ""){
dbSourceID = reportObj.reports[0].sourceid;
}
if(reportObj.reports[0].compid != ""){
userID = reportObj.reports[0].userid;
}
printUrl = "print://?comp="+companyID+"&type="+typeName+"&dbid="+dbSourceID+"&uid="+userID;//alert(printUrl);
window.location.href = window.location.href;
location.href = printUrl;
}
}else{
alert("没有要打印的报表");
return;
}
}else{
alert("费用未结算不能打印");
return;
}
}
function dialog()
{
this.width=450;
this.height=360;
this.title_height=20;
this.html='';
this.title='';
var self = this;
var bgObj,msgObj,titleObj;
this.close=function()
{
document.body.removeChild(document.getElementById("bgDiv"));
document.getElementById("msgDiv").removeChild(document.getElementById("msgTitle"));
document.body.removeChild(document.getElementById("msgDiv"));
}
this.show=function()
{
var msgw,msgh,bordercolor;
msgw=self.width;
msgh=self.height;
bordercolor="#336699";
titlecolor="#99CCFF";
var sWidth,sHeight;
sWidth=document.body.offsetWidth;
sHeight=screen.height;
bgObj=document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.background="#777";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.6";
bgObj.style.left="0";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
bgObj.style.zIndex = "10000";
document.body.appendChild(bgObj);
msgObj=document.createElement("div")
msgObj.setAttribute("id","msgDiv");
msgObj.setAttribute("align","center");
msgObj.style.background="white";
msgObj.style.border="1px solid " + bordercolor;
msgObj.style.position = "absolute";
msgObj.style.left = "50%";
msgObj.style.top = "30%";
msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
msgObj.style.marginLeft = "-225px" ;
msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
msgObj.style.width = msgw + "px";
msgObj.style.height =msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight ="25px";
msgObj.style.zIndex = "10001";
titleObj=document.createElement("h4");
titleObj.setAttribute("id","msgTitle");
titleObj.setAttribute("align","center");
titleObj.style.margin="0";
titleObj.style.padding="3px";
titleObj.style.background=bordercolor;
titleObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
titleObj.style.opacity="0.75";
titleObj.style.border="1px solid " + bordercolor;
titleObj.style.height=self.title_height+"px";
titleObj.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
titleObj.style.color="white";
titleObj.style.cursor="pointer";
titleObj.innerHTML=self.title;
//titleObj.onclick=function(){self.close();}
document.body.appendChild(msgObj);
document.getElementById("msgDiv").appendChild(titleObj);
var txt=document.createElement("div");
txt.style.margin="1em 0"
txt.setAttribute("id","msgTxt");
txt.innerHTML=self.html;
document.getElementById("msgDiv").appendChild(txt);
}
}
function msgBox(){
var dg=new dialog();
dg.html="正在保存中,请稍等……";//"<input type=button onclick='new dialog().close();' value='确定'>";
dg.width=200;
dg.height=100;
dg.title="";
dg.show();
}
function closeAction(){
window.parent.opener.location.href = window.parent.opener.location.href;
window.close();
}
function cwvouchersadd(gid) {
var url = "../CW/CwVouchersChFeeSettlementListGridSource.aspx?handle=isvouchers&gids=" + gid + "&uid=" + newGuid();
var loader = dhtmlxAjax.getSync(url);
var jsVal = loader.xmlDoc.responseText;
if (jsVal.trim() != "") {
alert(jsVal); //"有已生成的凭证,不能重复生成!"
return;
}
//
var url = "../CW/CwVouchersAddDoGridSource.aspx?read=isvouchers&gids=" + gid + "&uid=" + newGuid();
var loader = dhtmlxAjax.getSync(url);
var jsVal = loader.xmlDoc.responseText;
if (jsVal.trim() == "") {
alert("生成凭证失败!"); //"有已生成的凭证,不能重复生成!"
return;
}
//
var feature = "height=500, width=1000, toolbar=no, menubar=no,scrollbars=no, resizable=0,location=no, status=no,Top= " + (screen.height / 2 - 300) + ",Left= " + (screen.width / 2 - 500);
var URLs = "../CW/CwVouchersAddDo.aspx?ordno=" + jsVal;
window.open(URLs, "生成结算凭证信息", feature);
}
function newGuid() {
var guid = "";
for (var i = 1; i <= 32; i++) {
var n = Math.floor(Math.random() * 16.0).toString(16);
guid += n;
if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
guid += "-";
}
return guid.toUpperCase();
}
function getonload() {
createGrid();
setDiv();
}
function setDiv() {
if ($("h_ISADVANCE").value.trim() == "True") {
document.getElementById('YFDiv').style.display = "";
}
else {
document.getElementById('YFDiv').style.display = "none";
}
//
if ($("h_cur").value.trim() == "RMB") {
$("ddl_bb1").value = "RMB";
$("ddl_bb3").value = "RMB";
}
else if ($("h_cur").value.trim() == "USD") {
$("ddl_bb1").value = "USD";
$("ddl_bb3").value = "USD";
}
$("ddl_bb2").value = "RMB";
$("ddl_bb4").value = "RMB";
$("ddl_bb5").value = "RMB";
$("txt_hl1").value = "1.0000";
$("txt_hl2").value = "1.0000";
$("txt_hl3").value = "1.0000";
$("txt_hl4").value = "1.0000";
$("txt_hl5").value = "1.0000";
$("txt_je1").value = $("h_ctl").value.trim();
$("h_je1").value = $("h_ctl").value.trim();
$("txt_je2").value = "0.00";
$("txt_je3").value = $("h_ctl").value.trim();
$("txt_je4").value = "0.00";
$("txt_je5").value = "0.00";
//
txt_disabled();
}
//#region js计算函数
round2 = function (str, length) {
var r2 = parseFloat(str).toFixed(8);
var r1 = parseFloat(r2).toFixed(parseInt(length));
return r1;
}
//除法函数,用来得到精确的除法结果
//说明javascript的除法结果会有误差在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
//调用accDiv(arg1,arg2)
//返回值arg1除以arg2的精确结果
function accDiv(arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
with (Math) {
r1 = Number(arg1.toString().replace(".", ""))
r2 = Number(arg2.toString().replace(".", ""))
return (r1 / r2) * pow(10, t2 - t1);
}
}
//给Number类型增加一个div方法调用起来更加方便。
Number.prototype.div = function (arg) {
return accDiv(this, arg);
}
//乘法函数,用来得到精确的乘法结果
//说明javascript的乘法结果会有误差在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
//调用accMul(arg1,arg2)
//返回值arg1乘以arg2的精确结果
function accMul(arg1, arg2) {
var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
try { m += s1.split(".")[1].length } catch (e) { }
try { m += s2.split(".")[1].length } catch (e) { }
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
//给Number类型增加一个mul方法调用起来更加方便。
Number.prototype.mul = function (arg) {
return accMul(arg, this);
}
//加法函数,用来得到精确的加法结果
//说明javascript的加法结果会有误差在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
//调用accAdd(arg1,arg2)
//返回值arg1加上arg2的精确结果
function accAdd(arg1, arg2) {
var r1, r2, m;
try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
m = Math.pow(10, Math.max(r1, r2))
return (arg1 * m + arg2 * m) / m
}
//给Number类型增加一个add方法调用起来更加方便。
Number.prototype.add = function (arg) {
return accAdd(arg, this);
}
//加
function Add(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).add(parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
//减
function Cut(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).add(parseFloat(0) - parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
//乘
function Mul(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).mul(parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
//连乘
function Mul3(a, b, c, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = (parseFloat(a).mul(parseFloat(b)).mul(parseFloat(c))).toFixed(parseInt(length));
return parseFloat(_r);
}
//除
function Div(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).div(parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
//#endregion