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.
D7QUANTAI/DSWeb/js/InvoiceApplicationModify.js

1645 lines
62 KiB
JavaScript

var commonGirdObj_fname;
var commonGridObj_fee;
var comboCustomer;//委托单位
var jsonCacheObj;
var jsonLinkObj;//自定义名称关联关系
function $(id){
return document.getElementById(id);
}
function createInfo(){
initFeeName();
initComboCustomer();
initInvoice();
createComboCustomer();
}
function initFeeName(){
var headerArgs_fname = new Array("","类型","费用名称","费用","type");
//width
var widthArgs_fname = new Array("30","30","140","140","0");
//column align
var colAlignArgs_fname = new Array("center","center","center","center","center");
//column sort
var colSortArgs_fname = new Array("na","na","na","na","na");
//column type
var colTypeArgs_fname = new Array("ch","ro","ed","ed","ro");
commonGirdObj_fname = new TGridCommon("mygrid_container_fname","form1",headerArgs_fname,widthArgs_fname,colAlignArgs_fname,colSortArgs_fname,colTypeArgs_fname);
//commonGirdObj_fname.showHeader(true);
commonGirdObj_fname.setResponseUrl("");
commonGirdObj_fname.setRequest("");
commonGirdObj_fname.setSourceType("json");
commonGirdObj_fname.setSkin("xp");
commonGirdObj_fname.setImageUrl("../images/");
commonGirdObj_fname.initGrid();
commonGirdObj_fname.getGridObj().enableEditEvents(true,false,true);
commonGirdObj_fname.getGridObj().attachEvent("onEditCell", function (stage, rId, cInd, nValue, oValue) {
if (stage == 0) {
return true;
}
if (stage == 1) {
var selectedId = commonGirdObj_fname.getGridObj().getSelectedRowId();
var rowIndex = commonGirdObj_fname.getGridObj().getRowIndex(selectedId);
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;
}
}
}
if (stage == 2) {
if (cInd == 2) {//更改费用名称
if (nValue.trim() == "") {
alert("费用名称不能为空");
return false;
}
var iCount = 0;
var rowIndex = commonGirdObj_fname.getGridObj().getRowIndex(rId);
var newName = nValue.toString();
commonGirdObj_fname.getGridObj().cellByIndex(rowIndex, 2).setValue(newName);
var tempCache = $("h_feecache").value;
if (tempCache.trim() != "") {
jsonCacheObj = eval('(' + tempCache + ')');
for (var i = 0; i < jsonCacheObj.caches.length; i++) {
if (jsonCacheObj.caches[i].id == rId) {
jsonCacheObj.caches[i].fname = nValue.trim();
iCount++;
break;
}
}
}
//如果没有匹配的值,表示值是手动添加的,orig = 2
// if(iCount == 0){
// var newCache = jsonCacheObj.caches;
// var currency = $("txt_currency").value.trim();
// var rowIndex = commonGirdObj_fname.getGridObj().getRowIndex(rId);
// var money = ConvertToMoney(outputMoney(clearNoNum(commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,3).getValue().toString())));
// newCache = {id:rId,type:"",bsno:"",cus:"",fname:newName,cur:currency,stl:money,cstl:money,ustl:0,orig:"2",oname:newName,ocstl:money};
//
// jsonCacheObj.caches.push(newCache);
//
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
// }
//alert(JSON.stringify(jsonCacheObj));
} else if (cInd == 3) {
if (nValue.trim() == "") {
alert("费用不能为空");
return false;
}
var iCount = 0;
var rowIndex = commonGirdObj_fname.getGridObj().getRowIndex(rId);
var money = ConvertToMoney(outputMoney(clearNoNum(nValue.toString())));
commonGirdObj_fname.getGridObj().cellByIndex(rowIndex, 3).setValue(money);
var tempCache = $("h_feecache").value;
if (tempCache.trim() != "") {
jsonCacheObj = eval('(' + tempCache + ')');
for (var i = 0; i < jsonCacheObj.caches.length; i++) {
if (jsonCacheObj.caches[i].id == rId) {
jsonCacheObj.caches[i].cstl = nValue;
iCount++;
break;
}
}
//如果没有匹配的值,表示值是手动添加的,orig = 2
// if(iCount == 0){//alert(JSON.stringify(jsonCacheObj));
// var newCache = jsonCacheObj.caches;
// var currency = $("txt_currency").value.trim();
// var rowIndex = commonGirdObj_fname.getGridObj().getRowIndex(rId);
// var newName = commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,2).getValue().trim();
// newCache = {id:rId,type:"",bsno:"",cus:"",fname:newName,cur:currency,stl:money,cstl:money,ustl:0,orig:"2",oname:newName,ocstl:money};
//
// jsonCacheObj.caches.push(newCache);
//
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
// }
$("h_feecache").value = JSON.stringify(jsonCacheObj);
}
ReCalculate();
}
//$("h_feecache").value = JSON.stringify(jsonCacheObj);
return true;
}
});
commonGirdObj_fname.getGridObj().attachEvent("onCheckbox", function(rId,cInd,state){
for(var i=0;i<commonGridObj_fee.getGridObj().getRowsNum();i++){
var feeRowID = "";
feeRowID = commonGridObj_fee.getGridObj().getRowId(i);
if(state == 1){
if(rId == feeRowID){
commonGirdObj_fname.getGridObj().setRowColor(rId,"#ebf48a");
//commonGridObj_fee.getGridObj().setRowColor(rId,"#ebf48a");
break;
}
}else{
if(rId == feeRowID){
commonGirdObj_fname.getGridObj().setRowColor(rId,"#ffffff");
//commonGridObj_fee.getGridObj().setRowColor(rId,"#ffffff");
break;
}
}
}
});
if($("h_feelist").value.trim() == ""){
//折算币别
var applyCurrency = parseInt($("h_currency").value);
//美元对人民币折算汇率
var usdToRMB = parseFloat($("h_usdtormb").value);
//人民币对美元折算汇率
var rmbToUSD = parseFloat($("h_rmbtousd").value);
//汇率
var rate = 0;
if(applyCurrency == 1){
rate = usdToRMB;
}else{
rate = rmbToUSD;
}
var cacheName = "";//cachename
cacheName = "&cachename="+$("h_cachename").value;
if($("h_isdetail").value == "1"){
var url = "InvoiceModifyGridSource.aspx?handle=getinvoiceapp&settlectype="+applyCurrency+"&rate="+rate+cacheName+"&guid="+commonGirdObj_fname.newGuid();
var loader = dhtmlxAjax.getSync(url);
var feelist = loader.xmlDoc.responseText;
var feeListObj = eval('(' + feelist + ')');
for(var i=0;i<feeListObj.invoice.length;i++){
var newId = commonGirdObj_fname.newGuid();
var rowCount = commonGirdObj_fname.getGridObj().getRowsNum();
var feeTypeName = "";
if(feeListObj.invoice[i].ftype == "1"){
feeTypeName = "收";
}else{
feeTypeName = "付";
}
commonGirdObj_fname.getGridObj().addRow(feeListObj.invoice[i].id,[0,feeTypeName,feeListObj.invoice[i].feename,ConvertToMoney(outputMoney(feeListObj.invoice[i].doamount.toString())),1],rowCount);
}
}else{
var newId = commonGirdObj_fname.newGuid();
var url = "InvoiceModifyGridSource.aspx?handle=getinvoiceapptotal&settlectype="+applyCurrency+"&rate="+rate+cacheName+"&guid="+commonGirdObj_fname.newGuid();
var loader = dhtmlxAjax.getSync(url);
var feelist = loader.xmlDoc.responseText;
var feeListObj = eval('(' + feelist + ')');
feeTypeName = "收";
commonGirdObj_fname.getGridObj().addRow(newId,[0,feeTypeName,$("h_rename").value, ConvertToMoney(outputMoney(feeListObj.total[0].finaltotal.toString())),1],rowCount);
}
}
// var feeListCache = $("h_feelist").value;
//
// var feeListObj = eval('(' + feeListCache + ')');
//
// 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);
// }
}
//function initInvoice(tempBSNO){
// var isVesselState = parseInt($("h_isvessel").value);
// var isCustnoState = parseInt($("h_iscustno").value);
// var isMoblnoState = parseInt($("h_ismblno").value);
// var isEteState = parseInt($("h_isetd").value);
// var isPolState = parseInt($("h_ispol").value);
// var isPodState = parseInt($("h_ispod").value);
//
// //获取委托信息
// if(isVesselState == 1 || isCustnoState == 1 || isMoblnoState == 1 || isEteState == 1 || isPolState == 1 || isPodState == 1){
// var opSeaeObj = null;
// var url = "";
//
// url = "InvoiceApplicationGridSource.aspx?handle=opseae&bsno="+tempBSNO;
//
//
// var loader = dhtmlxAjax.getSync(url);
//
// var opInfo = loader.xmlDoc.responseText;//alert(opInfo);
// var opSeaeObj = eval('(' + opInfo + ')');
//
// if(opSeaeObj.opinfo.length > 0){
// if(isVesselState == 1){
// $("txt_vesselvoyage").value = opSeaeObj.opinfo[0].vessel;
// }
// if(isCustnoState == 1){
// $("txt_custno").value = opSeaeObj.opinfo[0].custno;
// }
// if(isMoblnoState == 1){
// $("txt_mblno").value = opSeaeObj.opinfo[0].mblno;
// }
// if(isEteState == 1){
// $("txt_etd").value = opSeaeObj.opinfo[0].etd;
// }
// if(isPolState == 1){
// $("txt_pol").value = opSeaeObj.opinfo[0].pol;
// }
// if(isPodState == 1){
// $("txt_pod").value = opSeaeObj.opinfo[0].pod;
// }
// }
// }
//}
function initInvoice(){
//折算币别
var applyCurrency = parseInt($("h_currency").value);
//美元对人民币折算汇率
var usdToRMB = parseFloat($("h_usdtormb").value);
//人民币对美元折算汇率
var rmbToUSD = parseFloat($("h_rmbtousd").value);
//汇率
var rate = 0;
if(applyCurrency == 1){
rate = usdToRMB;
}else{
rate = rmbToUSD;
}
var cacheName = "";//cachename
cacheName = "&cachename="+$("h_cachename").value;
//获取发票合计数
var url = "InvoiceModifyGridSource.aspx?handle=getinvoiceapptotal&settlectype="+applyCurrency+"&rate="+rate+cacheName+"&guid="+commonGirdObj_fname.newGuid();
var loader = dhtmlxAjax.getSync(url);
var totalList = loader.xmlDoc.responseText;
var totalListObj = eval('(' + totalList + ')');
if(totalListObj != null){
if(applyCurrency == 1){
var curCapital = convertCurrency(moneyMath(totalListObj.total[0].finaltotal).toString(),1);
if(totalListObj.total[0].finaltotal < 0){
$("txt_amountcapital").value = "负"+curCapital;
}else{
$("txt_amountcapital").value = curCapital;
}
$("txt_total").value = "RMB "+totalListObj.total[0].finaltotal
}else if(applyCurrency == 2){
var curCapital = convertCurrency(moneyMath(totalListObj.total[0].finaltotal).toString(),2);
if(totalListObj.total[0].finaltotal < 0){
$("txt_amountcapital").value = "负"+curCapital;
}else{
$("txt_amountcapital").value = curCapital;
}
$("txt_total").value = "USD "+totalListObj.total[0].finaltotal
}
}
var _customer = $("h_customername").value;
getPayableName(_customer);
}
function getPayableName(customer){
var url = "InvoiceApplicationGridSource.aspx?handle=cuspayable&customer="+escape(customer)+"&guid="+commonGirdObj_fname.newGuid();
var loader = dhtmlxAjax.getSync(url);
var clientInfo = loader.xmlDoc.responseText;
var clientObj = eval('(' + clientInfo + ')');
if(clientObj.clients.length > 0){
if(clientObj.clients[0].pay1.trim() != ""){
$("h_payable").value = clientObj.clients[0].pay1;
}else{
$("h_payable").value = clientObj.clients[0].pay2;
}
comboCustomer.setComboText($("h_payable").value);
}
}
//function initInvoice(){
// //初始化值
// var jsonCacheObj = null;
// var totalFee = 0.0;
// var customerName = "";
//
// var totalRmbFee = 0;//RMB费用合计
// var totalUsdFee = 0;//USD费用合计
// var totalOtherFee = 0;//其他费用合计
// var totalCutRmbFee = 0;//应付人民币费用
// var totalCutUsdFee = 0;//应付美元费用
// var totalMegerRmbFee = 0;//自定义名称人民币费用
// var totalMegerCutRmb = 0;
// var totalMegerUsdFee = 0;//自定义名称美元费用
// var totalMegerCutUsd = 0;
//
// //折算币别
// var applyCurrency = parseInt($("h_currency").value);
// //美元对人民币折算汇率
// var usdToRMB = parseFloat($("h_usdtormb").value);
// //人民币对美元折算汇率
// var rmbToUSD = parseFloat($("h_rmbtousd").value);
// //获取缓存数据
// var tempCache = $("h_feecache").value;
// //是否有自定义名称
// var rename = $("h_rename").value.trim();
// //如果缓存内有数据,则进行操作
// if($("h_posted").value.trim() != ""){
// $("txt_custno").value = $("h_custno").value;
// $("txt_vesselvoyage").value = $("h_vesselvoyage").value;
// $("txt_mblno").value = $("h_mblno").value;
// $("txt_etd").value = $("h_etd").value;
// $("txt_pol").value = $("h_pol").value;
// $("txt_pod").value = $("h_pod").value;
// }
// if($("h_posted").value.trim() == ""){
// if(tempCache != ""){//alert(tempCache);
// jsonCacheObj = eval('(' + tempCache + ')');
// if(jsonCacheObj.caches.length > 0){
// var iCount = 0;
// //如果是自定义名称,则只计算orig=3的值
// for(var i=0;i<jsonCacheObj.caches.length;i++){
// if(parseInt(jsonCacheObj.caches[i].orig) == 3){
// var totalFee = parseFloat(jsonCacheObj.caches[i].cstl);
//
// //查看页面是否需要提取委托海运信息
// //var isShowOpInfo = parseInt($("h_opinfo").value);
// var isVesselState = parseInt($("h_isvessel").value);
// var isCustnoState = parseInt($("h_iscustno").value);
// var isMoblnoState = parseInt($("h_ismblno").value);
// var isEteState = parseInt($("h_isetd").value);
// var isPolState = parseInt($("h_ispol").value);
// var isPodState = parseInt($("h_ispod").value);
//
//
// if(isVesselState == 1 || isCustnoState == 1 || isMoblnoState == 1 || isEteState == 1 || isPolState == 1 || isPodState == 1){
// var opSeaeObj = null;
// var url = "";
// if(i>=1){
// url = "InvoiceApplicationGridSource.aspx?handle=opseae&bsno="+jsonCacheObj.caches[0].bsno;
// }else{
// url = "InvoiceApplicationGridSource.aspx?handle=opseae&bsno="+jsonCacheObj.caches[i+1].bsno;
// }
//
// var loader = dhtmlxAjax.getSync(url);
//
// var opInfo = loader.xmlDoc.responseText;//alert(opInfo);
// var opSeaeObj = eval('(' + opInfo + ')');
//
// if(opSeaeObj.opinfo.length > 0){
// if(isVesselState == 1){
// $("txt_vesselvoyage").value = opSeaeObj.opinfo[0].vessel;
// }
// if(isCustnoState == 1){
// $("txt_custno").value = opSeaeObj.opinfo[0].custno;
// }
// if(isMoblnoState == 1){
// $("txt_mblno").value = opSeaeObj.opinfo[0].mblno;
// }
// if(isEteState == 1){
// $("txt_etd").value = opSeaeObj.opinfo[0].etd;
// }
// if(isPolState == 1){
// $("txt_pol").value = opSeaeObj.opinfo[0].pol;
// }
// if(isPodState == 1){
// $("txt_pod").value = opSeaeObj.opinfo[0].pod;
// }
// }
// }
//
// var tempCustomerName = "";
// if(i>=1){
// tempCustomerName = jsonCacheObj.caches[0].cus;
// }else{
// tempCustomerName = jsonCacheObj.caches[i+1].cus;
// }
//
// var clientObj = null;
// if(tempCustomerName.trim() != ""){
// var url = "InvoiceApplicationGridSource.aspx?handle=cuspayable&customer="+escape(tempCustomerName);
// var loader = dhtmlxAjax.getSync(url);
//
// var clientInfo = loader.xmlDoc.responseText;
// var clientObj = eval('(' + clientInfo + ')');
//
// if(clientObj.clients.length > 0){
// if(clientObj.clients[0].pay1.trim() != ""){
// $("h_payable").value = clientObj.clients[0].pay1;
// }else{
// $("h_payable").value = clientObj.clients[0].pay2;
// }
//
// comboCustomer.setComboText($("h_payable").value);
// }
// }
//
// if(applyCurrency == 1){
// var tempTotal = 0;
// tempTotal = totalFee < 0 ? (totalFee * -1):totalFee;
// var curCapital = convertCurrency(moneyMath(tempTotal).toString(),1);
//
// if(totalRmbFee < 0){
// $("txt_amountcapital").value = "负"+curCapital;
// }else{
// $("txt_amountcapital").value = curCapital;
// }
//
// var ShowTotal = ConvertToMoney(outputMoney(moneyMath(totalFee).toString()));
// $("txt_total").value = "RMB "+ShowTotal;
//
// commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[i].id,["0","",jsonCacheObj.caches[i].fname,jsonCacheObj.caches[i].cstl],0);
// return;
// }else if(applyCurrency == 2){
// var tempTotal = 0;
// tempTotal = totalFee < 0 ? (totalFee * -1):totalFee;
// var curCapital = convertCurrency(moneyMath(tempTotal).toString(),2);
//
// if(totalRmbFee < 0){
// $("txt_amountcapital").value = "负"+curCapital;
// }else{
// $("txt_amountcapital").value = curCapital;
// }
//
// var ShowTotal = ConvertToMoney(outputMoney(moneyMath(totalFee).toString()));
// $("txt_total").value = "USD "+ShowTotal;
//
// commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[i].id,["0","",jsonCacheObj.caches[i].fname,jsonCacheObj.caches[i].cstl],0);
// return;
// }
// }
// }
// for(var i=0;i<jsonCacheObj.caches.length;i++){
// //第一次加载时,判断是否要提取委托信息
// var feeType = 0;//费用类型 1应收 2应付
// if(i == 0){
// //查看页面是否需要提取委托海运信息
// //var isShowOpInfo = parseInt($("h_opinfo").value);
// var isVesselState = parseInt($("h_isvessel").value);
// var isCustnoState = parseInt($("h_iscustno").value);
// var isMoblnoState = parseInt($("h_ismblno").value);
// var isEteState = parseInt($("h_isetd").value);
// var isPolState = parseInt($("h_ispol").value);
// var isPodState = parseInt($("h_ispod").value);
//
// if(isVesselState == 1 || isCustnoState == 1 || isMoblnoState == 1 || isEteState == 1 || isPolState == 1 || isPodState == 1){
// var opSeaeObj = null;
// var url = "InvoiceApplicationGridSource.aspx?handle=opseae&bsno="+jsonCacheObj.caches[i].bsno
// var loader = dhtmlxAjax.getSync(url);
//
// var opInfo = loader.xmlDoc.responseText;//alert(opInfo);
// var opSeaeObj = eval('(' + opInfo + ')');
//
//// if(opSeaeObj.opinfo.length > 0){
//// $("txt_vesselvoyage").value = opSeaeObj.opinfo[0].vessel;
//// $("txt_custno").value = opSeaeObj.opinfo[0].custno;
//// $("txt_mblno").value = opSeaeObj.opinfo[0].mblno;
//// $("txt_etd").value = opSeaeObj.opinfo[0].etd;
//// $("txt_pol").value = opSeaeObj.opinfo[0].pol;
//// $("txt_pod").value = opSeaeObj.opinfo[0].pod;
//// }
// if(opSeaeObj.opinfo.length > 0){
// if(isVesselState == 1){
// $("txt_vesselvoyage").value = opSeaeObj.opinfo[0].vessel;
// }
// if(isCustnoState == 1){
// $("txt_custno").value = opSeaeObj.opinfo[0].custno;
// }
// if(isMoblnoState == 1){
// $("txt_mblno").value = opSeaeObj.opinfo[0].mblno;
// }
// if(isEteState == 1){
// $("txt_etd").value = opSeaeObj.opinfo[0].etd;
// }
// if(isPolState == 1){
// $("txt_pol").value = opSeaeObj.opinfo[0].pol;
// }
// if(isPodState == 1){
// $("txt_pod").value = opSeaeObj.opinfo[0].pod;
// }
// }
// }
//
// var tempCustomerName = jsonCacheObj.caches[i].cus;
// var clientObj = null;
// if(tempCustomerName.trim() != ""){
// var url = "InvoiceApplicationGridSource.aspx?handle=cuspayable&customer="+escape(tempCustomerName);
// var loader = dhtmlxAjax.getSync(url);
//
// var clientInfo = loader.xmlDoc.responseText;
// var clientObj = eval('(' + clientInfo + ')');
//
// if(clientObj.clients.length > 0){
// if(clientObj.clients[0].pay1.trim() != ""){
// $("h_payable").value = clientObj.clients[0].pay1;
// }else{
// $("h_payable").value = clientObj.clients[0].pay2;
// }
//
// comboCustomer.setComboText($("h_payable").value);
// }
// }
//
// }
//
// feeType = parseInt(jsonCacheObj.caches[i].type);
// var cstl = 0;
// //结算金额
// cstl = parseFloat(jsonCacheObj.caches[i].cstl);//alert(cstl);
// //币别
// var cur = jsonCacheObj.caches[i].cur;
// //如果自定义名称为空 表示显示费用明细
// if(rename == ""){
// if(feeType == 1){//应收费用
// var tempWorkOut = 0;
// if(cur == "RMB"){
// if(applyCurrency == 2){
// tempWorkOut = moneyMath(cstl * rmbToUSD);
// totalUsdFee += parseFloat(tempWorkOut);//美元累加
// }else{
// tempWorkOut = cstl;
// totalRmbFee += parseFloat(tempWorkOut);//人民币累加
// }
// }else if(cur == "USD"){
// if(applyCurrency == 1){
// tempWorkOut = moneyMath(cstl * usdToRMB);
// totalRmbFee += parseFloat(tempWorkOut);//人民币累加
// }else{
// tempWorkOut = cstl.toString();
// totalUsdFee += parseFloat(tempWorkOut);//美元累加
// }
// }
// var ShowMoney = ConvertToMoney(outputMoney(tempWorkOut.toString()));
// commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[i].id,["0","收",jsonCacheObj.caches[i].fname,ShowMoney],i);
// //写入缓存
// jsonCacheObj.caches[i].cstl = tempWorkOut;
// }else if(feeType == 2){//应付费用
// var tempWorkOut = 0;
// if(cur == "RMB"){
// if(applyCurrency == 2){
// tempWorkOut = moneyMath(cstl * rmbToUSD);
// totalCutUsdFee += parseFloat(tempWorkOut);//美元累减
// }else{
// tempWorkOut = cstl;
// totalCutRmbFee += tempWorkOut;//人民币累减
// }
// }else if(cur == "USD"){
// if(applyCurrency == 1){
// tempWorkOut = moneyMath(cstl * usdToRMB);
// totalCutRmbFee += parseFloat(tempWorkOut);//人民币累减
// }else{
// tempWorkOut = cstl;
// totalCutUsdFee += tempWorkOut;//美元累减
// }
// }
// var ShowMoney = ConvertToMoney(outputMoney(tempWorkOut.toString()));//alert(tempWorkOut);
// commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[i].id,["0","付",jsonCacheObj.caches[i].fname,ShowMoney],i);
// //写入缓存
// jsonCacheObj.caches[i].cstl = tempWorkOut;
// }
// }else{//有自定义名称,则将应收、应付置累加统计,然后合并到自定义名称费用内
// if(feeType == 1){//应收费用
//
//
// var tempWorkOut = 0;
// if(cur == "RMB"){
// if(applyCurrency == 2){
// tempWorkOut = moneyMath(cstl * rmbToUSD);
// totalUsdFee += parseFloat(tempWorkOut);//美元累加
// totalMegerUsdFee += parseFloat(tempWorkOut);
// }else{
// tempWorkOut = cstl;
// totalRmbFee += parseFloat(tempWorkOut);//人民币累加
// totalMegerRmbFee += parseFloat(tempWorkOut);
// }
// jsonCacheObj.caches[i].cstl = tempWorkOut;
// }else if(cur == "USD"){
// if(applyCurrency == 1){
// tempWorkOut = moneyMath(cstl * usdToRMB);
// totalRmbFee += parseFloat(tempWorkOut);//人民币累加
// totalMegerRmbFee += parseFloat(tempWorkOut);
// }else{
// tempWorkOut = cstl.toString();
// totalUsdFee += parseFloat(tempWorkOut);//美元累加
// totalMegerUsdFee += parseFloat(tempWorkOut);
// }
// jsonCacheObj.caches[i].cstl = tempWorkOut;
// }
//// //写入缓存
//// jsonCacheObj.caches[i].cstl = tempWorkOut;
// }else if(feeType == 2){//应付费用
// var tempWorkOut = 0;
// if(cur == "RMB"){
// if(applyCurrency == 2){
// tempWorkOut = moneyMath(cstl * rmbToUSD);
// totalCutUsdFee += parseFloat(tempWorkOut);//美元累减
// totalMegerCutUsd += parseFloat(tempWorkOut);
// }else{
// tempWorkOut = cstl;
// totalCutRmbFee += parseFloat(tempWorkOut);//人民币累减
// totalMegerCutRmb += parseFloat(tempWorkOut);
// }
// jsonCacheObj.caches[i].cstl = tempWorkOut;
// }else if(cur == "USD"){
// if(applyCurrency == 1){
// tempWorkOut = moneyMath(cstl * usdToRMB);
// totalCutRmbFee += parseFloat(tempWorkOut);//人民币累减
// totalMegerCutRmb += parseFloat(tempWorkOut);
// }else{
// tempWorkOut = cstl;
// totalCutUsdFee += parseFloat(tempWorkOut);//美元累减
// totalMegerCutUsd += parseFloat(tempWorkOut);
// }
// jsonCacheObj.caches[i].cstl = tempWorkOut;
// }
//// //写入缓存
//// jsonCacheObj.caches[i].cstl = tempWorkOut;
// }
// }
// }
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
// //循环遍历完成,统计数据信息
// if(applyCurrency == 1){
// //累加费用
// totalFee = (totalRmbFee - totalCutRmbFee);
//
// var tempTotal = 0;
// tempTotal = totalFee < 0 ? (totalFee * -1):totalFee;
// var curCapital = convertCurrency(moneyMath(tempTotal).toString(),1);
//
// if(totalFee < 0){
// $("txt_amountcapital").value = "负"+curCapital;
// }else{
// $("txt_amountcapital").value = curCapital;
// }
//
// var ShowTotal = ConvertToMoney(outputMoney(moneyMath(totalFee).toString()));
// $("txt_total").value = "RMB "+ShowTotal;
//
// totalMegerRmbFee = (totalMegerRmbFee - totalMegerCutRmb);
// if(totalMegerRmbFee != 0){
// var newCache = jsonCacheObj.caches;
// var newCacheGuid = commonGirdObj_fname.newGuid();
// newCache = {id:newCacheGuid,type:"",bsno:"",cus:"",fname:rename,cur:"RMB",
// stl:totalMegerRmbFee,cstl:totalMegerRmbFee,ustl:0,orig:"3",oname:rename,ocstl:totalMegerRmbFee};
// //缓存数据
// jsonCacheObj.caches.push(newCache);
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
// var ShowMoney = ConvertToMoney(outputMoney(totalMegerRmbFee.toString()));
// commonGirdObj_fname.getGridObj().addRow(newCacheGuid,["0","",rename,ShowMoney],0);
// }
// }else{
// //累加费用
// totalFee = (totalUsdFee - totalCutUsdFee);
//
// var tempTotal = 0;
// tempTotal = totalFee < 0 ? (totalFee * -1):totalFee;
// var curCapital = convertCurrency(moneyMath(tempTotal).toString(),2);
//
// if(totalFee < 0){
// $("txt_amountcapital").value = "负"+curCapital;
// }else{
// $("txt_amountcapital").value = curCapital;
// }
//
// var ShowTotal = ConvertToMoney(outputMoney(moneyMath(totalFee).toString()));
// $("txt_total").value = "USD "+ShowTotal;
//
// var newCache = jsonCacheObj.caches;
// totalMegerUsdFee = (totalMegerUsdFee - totalMegerCutUsd);
// if(totalMegerUsdFee != 0){
// var newCache = jsonCacheObj.caches;
// var newCacheGuid = commonGirdObj_fname.newGuid();
// newCache = {id:newCacheGuid,type:"",bsno:"",cus:"",fname:rename,cur:"USD",stl:totalMegerUsdFee,cstl:totalMegerUsdFee,ustl:0,orig:"3",oname:rename,ocstl:totalMegerUsdFee};
// //缓存数据
// jsonCacheObj.caches.push(newCache);
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
// var ShowMoney = ConvertToMoney(outputMoney(totalMegerUsdFee.toString()));
// commonGirdObj_fname.getGridObj().addRow(newCacheGuid,["0","",rename,ShowMoney],0);
// }
// }
// }
// }else{
// //如果缓存没有记录,则不进行Grid加载和费用统计操作
// }
// }else{//如果是已经提交过申请了
// var jsonCacheObj = null;//alert(tempCache);
// var tempCache = $("h_feecache").value;
// if(tempCache.trim() != ""){
// jsonCacheObj = eval('(' + tempCache + ')');
// }
//
// var iCount = 0;
// for(var q = 0;q<jsonCacheObj.caches.length;q++){
// if(parseInt(jsonCacheObj.caches[q].orig) == 3){
// iCount++;
// break;
// }
// }//alert(iCount);
// if(iCount > 0){
// for(var q = 0;q<jsonCacheObj.caches.length;q++){
// if(parseInt(jsonCacheObj.caches[q].orig) != 1){
// commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[q].id,["0","",jsonCacheObj.caches[q].fname,jsonCacheObj.caches[q].cstl],q);
// }
// }
// }else{
// for(var q = 0;q<jsonCacheObj.caches.length;q++){
// var typeName = jsonCacheObj.caches[q].type.toString().trim();
// //alert(typeName);
// if(typeName != ""){
// if(parseInt(jsonCacheObj.caches[q].type) == 1){
// commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[q].id,["0","收",jsonCacheObj.caches[q].fname,jsonCacheObj.caches[q].cstl],q);
// }else{
// commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[q].id,["0","付",jsonCacheObj.caches[q].fname,jsonCacheObj.caches[q].cstl],q);
// }
// }else{
// commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[q].id,["0","",jsonCacheObj.caches[q].fname,jsonCacheObj.caches[i].cstl],q);
// }
// }
// }
// //统计总费用
// $("txt_total").value = $("h_total").value;//alert($("h_capitial").value);
// $("txt_amountcapital").value = $("h_capitial").value;
// }
//
//}
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();
}
//人民币转换成大写
function convertCurrency(currencyDigits,type) {
// Constants:
var MAXIMUM_NUMBER = 99999999999.99;
// Predefine the radix characters and currency symbols for output:
var CN_ZERO = "零";
var CN_ONE = "壹";
var CN_TWO = "贰";
var CN_THREE = "叁";
var CN_FOUR = "肆";
var CN_FIVE = "伍";
var CN_SIX = "陆";
var CN_SEVEN = "柒";
var CN_EIGHT = "捌";
var CN_NINE = "玖";
var CN_TEN = "拾";
var CN_HUNDRED = "佰";
var CN_THOUSAND = "仟";
var CN_TEN_THOUSAND = "万";
var CN_HUNDRED_MILLION = "亿";
var CN_SYMBOL = "人民币";
var CN_SYUSD = "美元";
var CN_DOLLAR = "元";
var CN_TEN_CENT = "角";
var CN_CENT = "分";
var CN_INTEGER = "整";
// Variables:
var integral; // Represent integral part of digit number.
var decimal; // Represent decimal part of digit number.
var outputCharacters; // The output result.
var parts;
var digits, radices, bigRadices, decimals;
var zeroCount;
var i, p, d;
var quotient, modulus;
// Validate input string:
currencyDigits = currencyDigits.toString();
if (currencyDigits == "") {
alert("Empty input!");
return "";
}
if (currencyDigits.match(/[^,.\d]/) != null) {
alert("Invalid characters in the input string!");
return "";
}
if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
alert("Illegal format of digit number!");
return "";
}
// Normalize the format of input digits:
currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
// Assert the number is not greater than the maximum number.
if (Number(currencyDigits) > MAXIMUM_NUMBER) {
alert("Too large a number to convert!");
return "";
}
// Process the coversion from currency digits to characters:
// Separate integral and decimal parts before processing coversion:
parts = currencyDigits.split(".");
if (parts.length > 1) {
integral = parts[0];
decimal = parts[1];
// Cut down redundant decimal digits that are after the second.
decimal = decimal.substr(0, 2);
}
else {
integral = parts[0];
decimal = "";
}
// Prepare the characters corresponding to the digits:
digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
decimals = new Array(CN_TEN_CENT, CN_CENT);
// Start processing:
outputCharacters = "";
// Process integral part if it is larger than 0:
if (Number(integral) > 0) {
zeroCount = 0;
for (i = 0; i < integral.length; i++) {
p = integral.length - i - 1;
d = integral.substr(i, 1);
quotient = p / 4;
modulus = p % 4;
if (d == "0") {
zeroCount++;
}
else {
if (zeroCount > 0)
{
outputCharacters += digits[0];
}
zeroCount = 0;
outputCharacters += digits[Number(d)] + radices[modulus];
}
if (modulus == 0 && zeroCount < 4) {
outputCharacters += bigRadices[quotient];
zeroCount = 0;
}
}
outputCharacters += CN_DOLLAR;
}
// Process decimal part if there is:
if (decimal != "") {
for (i = 0; i < decimal.length; i++) {
d = decimal.substr(i, 1);
if (d != "0") {
outputCharacters += digits[Number(d)] + decimals[i];
}
}
}
// Confirm and return the final output string:
if (outputCharacters == "") {
outputCharacters = CN_ZERO + CN_DOLLAR;
}
if (decimal == "") {
outputCharacters += CN_INTEGER;
}
if(type == 1){
outputCharacters = CN_SYMBOL + outputCharacters;
}else if(type == 2){
outputCharacters = CN_SYUSD + outputCharacters;
}
return outputCharacters;
}
function addApplication(){
$("h_action").value = 5;//添加申请
//postEnterFee();
}
function deleteApplication(){
$("h_action").value = 4;//删除申请
//postEnterFee();
}
function printInvoice(){
var strBSNO = "";
strBSNO = $("h_invoiceappid").value;
var printUrl = "";
var companyID = "";
var typeName = "PrintInvoiceApplicationReport";
var dbSourceID = "";
var userID = "";
var url = "../Reports/ReportService.aspx?handle=printinvoiceapplication&invoiceid=" + strBSNO + "&val=" + commonGirdObj_fname.newGuid();
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;
var dfg = "";
}
} else {
alert("没有要打印的报表");
return;
}
}
function saveApplication(){
$("h_action").value = 2;//保存申请
saveInfo();
}
function postApplication(){
// $("h_action").value = 1;//提交申请
//
// //提交申请以前先根据申请编号查看是否是已经保存的开票申请,如果是则自动将申请信息更新为已提交状态,否则继续执行提交申请操作
// if($("h_billno").value.trim() != ""){
// var strBillNO = $("h_billno").value.trim();
// var url = "InvoiceApplicationGridSource.aspx?billno="+strBillNO+"&handle=postapplybillno&uid="+commonGirdObj_fname.newGuid();
// var loader = dhtmlxAjax.getSync(url);
// var postStatus = loader.xmlDoc.responseText;
//
// var status = parseInt(postStatus);
// switch(status){
// case 1:
// alert("开票申请提交成功");
// $("btn_apply").disabled = true;//提交申请按钮置灰不能点击
// $("txt_invoiceno").disabled = true;//发票号码不能填写
// $("txt_paycustomer").disabled = true;//付款单位不能填写
// break;
// case -1:
// saveInfo();
// break;
// case -2:
// alert("开票申请已提交,不能重复提交");
// break;
// case -3:
// alert("开票申请提交异常");
// break;
// }
// }else{
// saveInfo();
// }
msgBox();
$("h_total").value = $("txt_total").value;
$("h_etd").value = $("txt_etd").value;
$("h_pod").value = $("txt_pod").value;
$("h_pol").value = $("txt_pol").value;
$("h_mblno").value = $("txt_mblno").value;
$("h_custno").value = $("txt_custno").value;
$("h_vesselvoyage").value = $("txt_vesselvoyage").value;
$("h_payable").value = comboCustomer.getComboText().trim();
$("h_total").value = $("txt_total").value;//alert($("h_total").value);
$("h_capitial").value = $("txt_amountcapital").value;
$("h_enter").value = 1;//提交申请
postEnterFee();
}
function saveInfo(){
//提交时发票号码不能为空
// if($("txt_invoiceno").value.trim() == ""){
// alert("发票号码不能为空,请填写");
// return;
// }
// //提交时付款单位不能为空
// if($("txt_invoiceno").value.trim() == ""){
// alert("付款单位不能为空,请填写");
// return;
// }
// var jsonListObj = null;
//
// var cacheBuffer = "";
// for(var i = 0;i <commonGirdObj_fname.getGridObj().getRowsNum();i++){
// var rId = commonGirdObj_fname.getGridObj().getRowId(i);
// var rowNameIndex = commonGirdObj_fname.getGridObj().getRowIndex(rId);
// var rowFeeIndex = commonGridObj_fee.getGridObj().getRowIndex(rId);
//
// cacheBuffer += "{";
// cacheBuffer += "\"id\":\""+rId+"\",";
// cacheBuffer += "\"fname\":\""+commonGirdObj_fname.getGridObj().cellByIndex(rowNameIndex,1).getValue()+"\",";//费用名称
// cacheBuffer += "\"amount\":\""+commonGridObj_fee.getGridObj().cellByIndex(rowFeeIndex,0).getValue()+"\"";//金额
// if(i == commonGirdObj_fname.getGridObj().getRowsNum() - 1){
// cacheBuffer += "}";
// }else{
// cacheBuffer += "},";
// }
// }
// var result = "";
// result += "{\"list\":[";
// result += cacheBuffer;
// result += "]}";
//
//
// jsonListObj = eval('(' + result + ')');
//
// $("h_list").value = JSON.stringify(jsonListObj);
// var tempCache = "";
//
// tempCache = $("h_list").value;
// if(tempCache.trim() == ""){
// tempCache = $("h_feecache").value;
// }
//
// jsonCacheObj = eval('(' + tempCache + ')');
//
// if(jsonCacheObj.caches.length > 0){
// for(var i = 0;i <commonGirdObj_fname.getGridObj().getRowsNum();i++){
// var rId = commonGirdObj_fname.getGridObj().getRowId(i);
// var rowNameIndex = commonGirdObj_fname.getGridObj().getRowIndex(rId);
// var rowFeeIndex = commonGridObj_fee.getGridObj().getRowIndex(rId);
//
// for(var j = 0;j<jsonCacheObj.caches.length;j++){
// if(rId == jsonCacheObj.caches[j].id){
// jsonCacheObj.caches[j].fname = commonGirdObj_fname.getGridObj().cellByIndex(rowNameIndex,2).getValue().trim();
// jsonCacheObj.caches[j].cstl = commonGridObj_fee.getGridObj().cellByIndex(rowNameIndex,0).getValue().trim();
// }
// }
// }
// }
//
// $("h_list").value = JSON.stringify(jsonCacheObj);
//alert($("h_feecache").value);
$("h_etd").value = $("txt_etd").value;
$("h_pod").value = $("txt_pod").value;
$("h_pol").value = $("txt_pol").value;
$("h_mblno").value = $("txt_mblno").value;
$("h_custno").value = $("txt_custno").value;
$("h_vesselvoyage").value = $("txt_vesselvoyage").value;
$("h_payable").value = comboCustomer.getComboText().trim();
$("h_total").value = $("txt_total").value;//alert($("h_total").value);
$("h_capitial").value = $("txt_amountcapital").value;
$("h_posted").value = "1";
postEnterFee();
window.opener.location.href=window.opener.location.href;
}
function checkInfo(){
}
//将当前开票费用明细删除
function deletePostFee(){
if(window.confirm("您确定要将所选开票费用删除")){
}
}
//四舍五入
function moneyMath(original){
var result = Math.round(original*100)/100;
return result;
}
function importFee(){
var openSet = "height=700, width=1050, toolbar=no, menubar=no,scrollbars=no, resizable=1,location=no, status=no,Top= " +(screen.height-710)/2 + ",Left= "+(screen.width-800)/2
var openType = "_blank";
var openUrl = "CommonInvoiceApplication.aspx";
window.open (openUrl,openType,openSet);
}
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
////添加费用
//function addFee(){
// if(commonGirdObj_fname != null){
// var newRowID = commonGirdObj_fname.newGuid();
// commonGirdObj_fname.getGridObj().addRow(newRowID,["0","","",0.00],commonGirdObj_fname.getGridObj().getRowsNum());
//
// }
//}
//删除费用
function deleteFee(){
if(window.confirm("您确定要删除此条费用,删除后无法恢复")){
var iCount = 0;
var tempCache = "";
tempCache = $("h_feecache").value;
if (tempCache.trim() != "") {
jsonCacheObj = eval('(' + tempCache + ')');
for (var i = 0; i < commonGirdObj_fname.getGridObj().getRowsNum(); i++) {
var ckBox = parseInt(commonGirdObj_fname.getGridObj().cellByIndex(i, 0).getValue());
var rId = commonGirdObj_fname.getGridObj().getRowId(i);
//var rowIndex = commonGirdObj_fname.getGridObj().getRowIndex(rId);
if (ckBox == 1) {
for (var j = jsonCacheObj.caches.length - 1; j >= 0; j--) {
if (jsonCacheObj.caches[j].id == rId) {
if (jsonCacheObj.caches.length == 1) {
jsonCacheObj.caches.shift();
gridObj.cellByIndex(j, 0).setValue(0);
$("h_feecache").value = "";
//$("dvResult").innerHTML = "";
} else {
jsonCacheObj.caches.splice(i, 1);
gridObj.cellByIndex(j, 0).setValue(0);
$("h_feecache").value = JSON.stringify(jsonCacheObj);
//$("dvResult").innerHTML = JSON.stringify(jsonCacheObj);
break;
}
}
}
iCount++;
}
}
}
}
}
function createNewCacheItem(cacheObj,typeName,tempValue,ObjGuid){
var tempCache = "";
//获取费用缓存数据
tempCache = $("h_list").value;
if(tempCache.trim() == ""){
tempCache = $("h_feecache").value;
}
if (tempCache.trim() != "") {
jsonCacheObj = eval('(' + tempCache + ')');
//遍历缓存数据
var iCount = 0;
for(var i=0;i<jsonCacheObj.caches.length;i++){
if(jsonCacheObj.caches[i].id == ObjGuid){
iCount++;
break;
}
}
//如果没有相同的记录,则创建一条新记录
if(iCount == 0){
//如果缓存不为空则添加一条新记录进入缓存
if(jsonCacheObj.caches.length != 0){
var newCache = jsonCacheObj.caches;
var name = "";
var money = 0;
var currency = $("txt_currency").value;
if(typeName == "fname"){
fname = tempValue;
}else{
money = tempValue;
}
newCache = {id:ObjGuid,type:1,bsno:"",cus:"",fname:name,cur:currency,stl:money,cstl:money,ustl:0};
//alert(newCache);
jsonCacheObj.caches.push(newCache);
}
}
}
}
//重新加载Grid
function ReLoadGrid(){
var strList = $("h_feecache").value;
if(strList.trim() != ""){
jsonListObj = eval('(' + strList + ')');
commonGirdObj_fname.initGrid();
}
}
//重新计算费用
function ReCalculate(){
var jsonListObj = null;
var tempFeeTotal = 0;
var tempAddTotal = 0;
var tempRnTotal = 0;
var totalSettleFee = 0;
var strList = $("h_feecache").value;
if(strList.trim() != ""){
jsonListObj = eval('(' + strList + ')');
for(var i = 0;i < jsonListObj.caches.length;i++)
{
var tempOrig = 0;
tempOrig = parseInt(jsonListObj.caches[i].orig);
if(tempOrig == 1){//原始数据将费用统计到tempFeeTotal内暂存
var tempFeeType = 0;
tempFeeType = parseInt(jsonCacheObj.caches[i].type);
if(tempFeeType == 1){
tempFeeTotal += parseFloat(jsonListObj.caches[i].cstl);
}else{
tempFeeTotal -= parseFloat(jsonListObj.caches[i].cstl);
}
}else if(tempOrig == 2){//如果是手动添加的费用则orig=2并自动统计到tempAddTotal内暂存
tempAddTotal += parseFloat(jsonListObj.caches[i].cstl);
}else if(tempOrig == 3){//如果是自定义费用,则将orig=3费用统计到tempRnTotal内暂存
tempRnTotal += parseFloat(jsonListObj.caches[i].cstl);
}
}
//如果自定义费用统计不为0,则不统计原始数据费用值将自定义费用统计
if(tempRnTotal != 0){
totalSettleFee += tempRnTotal;
totalSettleFee += tempAddTotal;
}else{
totalSettleFee += tempFeeTotal;
totalSettleFee += tempAddTotal;
}
var tempTotal = 0;
tempTotal = totalSettleFee < 0 ? (totalSettleFee * -1):totalSettleFee;
var currency = $("txt_currency").value;
var curCapital = "";
if(currency == "RMB"){
curCapital = convertCurrency(moneyMath(totalSettleFee).toString(),1);
}else{
curCapital = convertCurrency(moneyMath(totalSettleFee).toString(),2);
}
if(totalSettleFee < 0){
$("txt_amountcapital").value = "负"+curCapital;
}else{
$("txt_amountcapital").value = curCapital;
}
$("txt_total").value =currency+" "+moneyMath(totalSettleFee);
}
}
//function window.onbeforeunload()
//{
// if(event.clientX> 360&&event.clientY <0||event.altKey)
// {
// return showConfirm();
// }
//}
//function showConfirm(){
// if(window.confirm("您确定要关闭")){
// return true;
// }else{
// return false;
// }
//}
function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,' ');
}
}
function initComboCustomer(){
comboCustomer = dhtmlXComboFromSelect("sel_customer");
if($("h_payable").value.trim() != ""){
comboCustomer.setComboText($("h_payable").value);
}
if($("h_posted").value.trim() != ""){
if(parseInt($("h_posted").value.trim()) == 1){
comboCustomer.disable(true);
}
}
}
function createComboCustomer(){//委托单位
var jsonCacheObj = null;
var tempCache = $("h_feecache").value;//alert(tempCache);
if(tempCache.trim() != ""){
jsonCacheObj = eval('(' + tempCache + ')');
var customer = "";
customer = jsonCacheObj.caches[0].cus;//alert(customer);
$("h_customer").value = customer;//alert($("h_customer").value);
if(comboCustomer != null){
comboCustomer.loadXML("../FeeCodes/CRMClientInfo.aspx?mask=0&pos=0&name="+escape(customer)+"&type=1");
}else{
initComboCustomer();
comboCustomer.loadXML("../FeeCodes/CRMClientInfo.aspx?mask=0&pos=0&name="+escape(customer)+"&type=1");
}
if($("h_payable").value != ""){
comboCustomer.setComboText($("h_payable").value);
}
//获取客户信息
comboCustomer.attachEvent("onSelectionChange", function(){
$("h_payable").value = comboCustomer.getComboText().trim();//alert($("h_customer").value);
});
}
// comboCustomer.attachEvent("onChange", function(){
// $("h_customer").value = comboCustomer.getComboText().trim();//alert($("h_customer").value);
// });
}
var isIe=(document.all)?true:false;
//设置select的可见状态
function setSelectState(state){
var objl=document.getElementsByTagName('select');
for(var i=0;i<objl.length;i++)
{
objl[i].style.visibility=state;
}
}
function mousePosition(ev){
if(ev.pageX || ev.pageY)
{
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
//弹出方法
function showMessageBox(wTitle,content,pos,wWidth){
closeWindow();
var bWidth=parseInt(document.documentElement.scrollWidth);
var bHeight=parseInt(document.documentElement.scrollHeight);
if(isIe){
setSelectState('hidden');}
var back=document.createElement("div");
back.id="back";
var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
back.style.cssText=styleStr;
document.body.appendChild(back);
showBackground(back,50);
var mesW=document.createElement("div");
mesW.id="mesWindow";
mesW.className="mesWindow";
mesW.innerHTML = "<div class='mesWindowTop'><table width='100%' height='100%'><tr><td>"+wTitle+"</td><td style='width:1px;'>"
+ "<input type='button' onclick='closeWindow();' title='关闭窗口' class='close' value='关闭' style='width:60px;'/></td></tr></table></div>"
+ "<div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
var v_top=(document.body.clientHeight-mesW.clientHeight)/2;
v_top+=document.documentElement.scrollTop;
styleStr="top:"+(v_top-180)+"px;left:"+(document.body.clientWidth/2-mesW.clientWidth/2)+"px;position:absolute;width:600px;margin-left:-300px;left:50%;z-index:9999;";
mesW.style.cssText=styleStr;
document.body.appendChild(mesW);
}
//让背景渐渐变暗
function showBackground(obj,endInt){
if(isIe){
obj.filters.alpha.opacity+=5;
if(obj.filters.alpha.opacity<endInt){
setTimeout(function(){showBackground(obj,endInt)},5);
}
}else{
var al=parseFloat(obj.style.opacity);al+=0.05;
obj.style.opacity=al;
if(al<(endInt/100)){
setTimeout(function(){showBackground(obj,endInt)},5);}
}
}
//关闭窗口
function closeWindow(){
if(document.getElementById('back')!=null){
document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
}
if(document.getElementById('mesWindow')!=null){
document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
}
if(isIe){
setSelectState('');
}
}
//测试弹出
function openMsg(ev,type)
{
var isFinish = false;
if(window.confirm("您确定要发送消息给开票人")){
isFinish = false;
var objPos = mousePosition(ev);
messContent = "<div style=\"padding:20px 0 20px 0;text-align:center\">"
+"<div style=\"float:left;width:100%\"></div> "
+"<div style=\"float:left;width:100%;padding-left:80px;\"> "
+"<table style=\"width:350px;\"><tr><td><select id=\"sel_customer\" multiple style=\"width:150px; height:60px;\"></select></td><td> "
+"<table style=\"height:60px; width:20px;\"><tr><td height=\"20px\"><div id=\"dvRemove\"><img src=\"../images/icons/edit_left.gif\" "
+"onmouseover=\"mouseMoveImg(this,1)\" onmouseout=\"mouseMoveImg(this,1)\" title=\"移除\" onclick=\"removeCustomer()\"/></div></td> "
+"</tr><tr><td height=\"20px\"><div id=\"dvAdd\"><img src=\"../images/icons/edit_right.gif\" onmouseover=\"mouseMoveImg(this,2)\" "
+"onmouseout=\"mouseMoveImg(this,2)\" title=\"添加\" onclick=\"addCustomer()\"/></div></td> "
+"</tr></table></td><td><select id=\"sel_print\" multiple style=\"width:150px; height:60px;\" class=\"select\"></select></td></tr></table></div>"
+"<input type=\"button\" id=\"btn_print_report\" value=\"打印\" class=\"btn\" onclick=\"printReport()\"/></div> ";
showMessageBox('消息接收人',messContent,objPos,350);
}
isFinish = true;
return isFinish;
}
function saveApplication(){
$("h_enter").value = "1";
msgBox();
postEnterFee();
}
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 refresh(){
$("btn_apply").onclick = clickNull;
}
function clickNull(){
}