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.
DS7/DSWeb/js/InvoiceMakeOutModify.js

1802 lines
70 KiB
JavaScript

2 years ago
var commonGirdObj_fname;
var commonGridObj_fee;
var comboCustomer;//委托单位
var comboBank;//开户银行
var comboAccount;//银行账户
var comboCurrency;//币别
var jsonCacheObj;
function $(id){
return document.getElementById(id);
}
function createInfo(){
//initComboCustomer();
initComboCustomer2();
initComboBank();
initComboAccount();
initComboCurrency();
initComboInvoiceno();
createComboCurrency();
createComboBank();
createComboAccount();
createComboInvoiceno();
initFeeName();
//initFee();
initInvoice();
}
function initFeeName(){
var headerArgs_fname = new Array("","类型","费用名称","费用");
//width
var widthArgs_fname = new Array("30","30","140","140");
//column align
var colAlignArgs_fname = new Array("center","center","center","center");
//column sort
var colSortArgs_fname = new Array("na","na","na","na");
//column type
var colTypeArgs_fname = new Array("ch","ro","ed","ed");
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){
var cacheName = "";//cachename
if($("h_cachename").value.trim() == ""){
$("h_cachename").value = commonGirdObj_fname.newGuid();
}
cacheName = "&cachename="+$("h_cachename").value;
var applyCurrency = $("h_settlecurrency").value.trim() == "RMB"?1:2;
var rowIndex = commonGirdObj_fname.getGridObj().getRowIndex(rId);
var feeName = commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,2).getValue().trim();
var money = ConvertToMoney(outputMoney(clearNoNum(commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,3).getValue().toString())));
var url = "InvoiceModifyGridSource.aspx?handle=addfee&settlectype="+applyCurrency+cacheName+"&directfeeid="+rId+"&directfeename="+escape(feeName)+"&directfeeamount="+money+"&guid="+commonGirdObj_fname.newGuid();
var loader = dhtmlxAjax.getSync(url);
var totalList = loader.xmlDoc.responseText;
var totalListObj = eval('(' + totalList + ')');
if(totalListObj != null){
if(applyCurrency == 1 && totalListObj.total[0].finaltotal != 0){
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 && totalListObj.total[0].finaltotal != 0){
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
}else{
$("txt_amountcapital").value = "";
$("txt_total").value = "";
}
}
return 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;
// }
// }//alert(iCount);
//
// //如果没有匹配的值,表示值是手动添加的,orig = 2
// if(iCount == 0){
// var newCache = jsonCacheObj.caches;
// var currency = $("h_settlecurrency").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"};
//
// jsonCacheObj.caches.push(newCache);
//
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
// }
// }else{
// var cacheBuffer = "";
// cacheBuffer += "{";
// cacheBuffer += "\"id\":\""+rId+"\",";
//
// cacheBuffer += "\"type\":\"\",";
// cacheBuffer += "\"bsno\":\"\",";
// cacheBuffer += "\"cus\":\"\",";
// cacheBuffer += "\"fname\":\""+commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,2).getValue()+"\",";
// var currency = $("h_settlecurrency").value.trim();
// cacheBuffer += "\"cur\":\""+currency+"\",";
// var money = ConvertToMoney(outputMoney(clearNoNum(commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,3).getValue().toString())));
// cacheBuffer += "\"stl\":\""+money+"\",";//应结
// cacheBuffer += "\"cstl\":\""+money+"\",";//本次结算
// cacheBuffer += "\"ustl\":\"0\",";//未结
// cacheBuffer += "\"orig\":\"2\"";//原始类型
// cacheBuffer += "}";
//
// var result = "";
// result += "{\"caches\":[";
// result += cacheBuffer;
// result += "]}";
//
// tempCache = result;
// jsonCacheObj = eval('(' + result + ')');
// $("h_feecache").value = JSON.stringify(jsonCacheObj);//alert($("h_feecache").value);
// }
//
//
// //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 = $("h_settlecurrency").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"};
//
// jsonCacheObj.caches.push(newCache);
//
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
// }
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
// }else{
// var cacheBuffer = "";
// cacheBuffer += "{";
// cacheBuffer += "\"id\":\""+rId+"\",";
//
// cacheBuffer += "\"type\":\"\",";
// cacheBuffer += "\"bsno\":\"\",";
// cacheBuffer += "\"cus\":\"\",";
// cacheBuffer += "\"fname\":\""+commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,2).getValue()+"\",";
// var currency = $("h_settlecurrency").value.trim();
// cacheBuffer += "\"cur\":\""+currency+"\",";
// var money = ConvertToMoney(outputMoney(clearNoNum(commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,3).getValue().toString())));
// cacheBuffer += "\"stl\":\""+money+"\",";//应结
// cacheBuffer += "\"cstl\":\""+money+"\",";//本次结算
// cacheBuffer += "\"ustl\":\"0\",";//未结
// cacheBuffer += "\"orig\":\"2\"";//原始类型
// cacheBuffer += "}";
//
// var result = "";
// result += "{\"caches\":[";
// result += cacheBuffer;
// result += "]}";
//
// tempCache = result;
// jsonCacheObj = eval('(' + result + ')');
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
// }
// ReCalculate();//重新计算费用
// }
// //$("h_feecache").value = JSON.stringify(jsonCacheObj);
// //alert($("h_feecache").value);
// 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;
// }
// }
// }
// });
}
function initInvoice(){
var handleName = $("h_handle").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
if($("h_cachename").value.trim() == ""){
$("h_cachename").value = commonGirdObj_fname.newGuid();
}
cacheName = "&cachename="+$("h_cachename").value;
if(handleName == "directmake"){
applyCurrency = $("h_settlecurrency").value.trim() == "RMB"?1:2;
rate = 0;
var url = "InvoiceModifyGridSource.aspx?handle=getdirectfee&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 if(handleName == "import"){
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+"&rname="+escape($("h_rename").value)+"&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);
}
}else if(handleName == "makeout"){
var invoiceAppID = $("h_invoiceappid").value.trim();
var url = "InvoiceModifyGridSource.aspx?handle=getinvoiceappmake&invoiceappid="+invoiceAppID+"&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);
}
}
if(applyCurrency != null && handleName != "makeout" && handleName != "directmake"){
//获取发票合计数
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;
var _currency = applyCurrency == 1?"RMB":"USD";
getRecvBankInfo(_currency);
getPayableName(_customer);
}else{
getRecvBankInfo("RMB");
getPayableName("");
}
}
function getRecvBankInfo(currency){
var url = "InvoiceApplicationGridSource.aspx?handle=bankinfo&currency="+currency+"&guid="+commonGirdObj_fname.newGuid();
var loader = dhtmlxAjax.getSync(url);
var bankVal = loader.xmlDoc.responseText;
var bankObj = eval('(' + bankVal + ')');
if(bankObj.banks.length > 0){
comboBank.setComboText(bankObj.banks[0].bank);
$("h_bank").value = bankObj.banks[0].bank;
comboAccount.setComboText(bankObj.banks[0].account);
$("h_account").value = bankObj.banks[0].account;
}
}
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 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(){
$("h_action").value = 3;//打印申请
//postEnterFee();
}
function saveApplication(){
$("h_action").value = 2;//保存申请
//saveInfo();
}
function makeOutInvoice(){
//$("h_action").value = 1;//开票
var handleName = $("h_handle").value.trim();
if(handleName == "import"){
$("h_enter").value = "1";
}else if(handleName == "makeout"){
$("h_enter").value = "2";
}else if(handleName == "directmake"){
$("h_enter").value = "3";
}
saveInfo();
}
function saveInfo(){
//提交时发票号码不能为空
var invoiceno = $("h_invoiceno").value.trim();
if (invoiceno.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);
// //alert(rowFeeIndex);
// 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); //alert($("h_list").value);
$("h_customer").value = comboCustomer.getComboText().trim();
if($("h_customer").value == ""){
alert("付款单位不能为空,请填写");
return;
}
$("h_account").value = comboAccount.getComboText().trim();
if ($("h_account").value == "") {
alert("开户银行不能为空,请填写");
return;
}
$("h_bank").value = comboBank.getComboText().trim();
if ($("h_bank").value == "") {
alert("银行账户不能为空,请填写");
return;
}
// alert($("h_customer").value);
// alert($("h_account").value);
// alert($("h_bank").value);
// 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_total").value = $("txt_total").value;
$("h_capitial").value = $("txt_amountcapital").value;
//$("h_saved").value = "1";
if($("h_settlecurrency").value == "USD"){
var usdToRmb = parseFloat($("h_usdtormb").value);
var rmbToUsd = parseFloat($("h_rmbtousd").value);
if(usdToRmb == 1 && rmbToUsd == 1){
openNewDiv("dvRate");
}else{
postEnterFee();
window.opener.location.href=window.opener.location.href;
}
}else{
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=600, width=970, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top= " +(screen.height-600)/2 + ",Left= "+(screen.width-970)/2
var openType = "_blank";
var openUrl = "importfee.aspx";
window.open (openUrl,openType,openSet);
}
//
function initComboCurrency(){
comboCurrency = dhtmlXComboFromSelect("sel_currency");
}
function createComboCurrency(){
if($("h_settlecurrency").value.trim() != ""){
comboCurrency.setComboText($("h_settlecurrency").value);
var handlName = $("h_handle").value.trim();
if(handlName == "import" || handlName == "makeout"){
comboCurrency.disable(true);
}
}else{
comboCurrency.addOption("RMB","RMB",null);
comboCurrency.addOption("USD","USD",null);
comboCurrency.setComboText("RMB");
$("h_settlecurrency").value = "RMB";
}
if($("h_posted").value.trim() != ""){
if(parseInt($("h_posted").value.trim()) == 1){
comboCurrency.disable(true);
}
}
comboCurrency.attachEvent("onSelectionChange", function(){
$("h_settlecurrency").value = comboCurrency.getComboText().trim();//alert($("h_account").value);
});
}
//
function initComboBank(){
comboBank = dhtmlXComboFromSelect("sel_bank");
}
function createComboBank(){
var currency = $("h_settlecurrency").value;
if(comboBank != null){
comboBank.loadXML("../FeeCodes/CompanyInfo.aspx?mask=0&pos=0&currency="+escape(currency)+"&type=1");
}else{
initComboBank();
comboBank.loadXML("../FeeCodes/CompanyInfo.aspx?mask=0&pos=0&currency="+escape(currency)+"&type=1");
}
if($("h_bank").value != ""){
comboBank.setComboText($("h_bank").value);
}
//获取银行值
comboBank.attachEvent("onSelectionChange", function(){
$("h_bank").value = comboBank.getComboText().trim();//alert($("h_bank").value);
var strCurrency = $("h_settlecurrency").value.trim();
if(strCurrency != ""){
var bankObj = null;
var url = "InvoiceApplicationGridSource.aspx?handle=getaccount&currency="+strCurrency+"&bankname="+escape($("h_bank").value)+"&uid="+newGuid();
var loader = dhtmlxAjax.getSync(url);
var bankVal = loader.xmlDoc.responseText;//alert(opInfo);
var bankObj = eval('(' + bankVal + ')');
if(bankObj.banks.length > 0){
comboAccount.setComboText(bankObj.banks[0].account);
$("h_account").value = bankObj.banks[0].account;
}
}
});
// comboBank.attachEvent("onBlur", function(){
// $("h_bank").value = comboBank.getComboText().trim();//alert($("h_bank").value);
// });
}
//
function initComboAccount() {
comboAccount = dhtmlXComboFromSelect("sel_account");
}
function createComboAccount(){
var currency = $("h_settlecurrency").value;
if(comboAccount != null){
comboAccount.loadXML("../FeeCodes/CompanyInfo.aspx?mask=0&pos=0&currency="+escape(currency)+"&type=2");
}
else{
initComboAccount();
comboAccount.loadXML("../FeeCodes/CompanyInfo.aspx?mask=0&pos=0&currency="+escape(currency)+"&type=2");
}
if($("h_account").value != ""){
comboAccount.setComboText($("h_account").value);
}
//获取账户值
comboAccount.attachEvent("onSelectionChange", function(){
$("h_account").value = comboAccount.getComboText().trim();//alert($("h_account").value);
});
// comboAccount.attachEvent("onBlur", function(){
// $("h_account").value = comboAccount.getComboText().trim();//alert($("h_account").value);
// });
}
//
function initComboCustomer() {
var handleName = $("h_handle").value.trim();
var customer = $("h_customername").value;
var jsonCacheObj = null;
//
comboCustomer = dhtmlXComboFromSelect("sel_customer");
if(handleName == "directmake"){//如果当前操作是直接开票 未引入任何费用也不是申请开票费用 则自动加载所有客户开票抬头
comboCustomer.loadXML("../FeeCodes/CRMClientInfo.aspx?mask=0&pos=0&type=2");
}else{
comboCustomer.loadXML("../FeeCodes/CRMClientInfo.aspx?mask=0&pos=0&name="+escape(customer)+"&type=1");
}
}
function initComboCustomer2() {//委托单位
comboCustomer.setComboText($("h_customer").value);
//获取客户信息
comboCustomer.attachEvent("onSelectionChange", function(){
$("h_customer").value = comboCustomer.getComboText().trim();
});
}
//
var comboInvoiceno;
function initComboInvoiceno()
{
comboInvoiceno = dhtmlXComboFromSelect("sel_invoiceno");
comboInvoiceno.loadXML("../FeeCodes/InvoicenoAdapter.aspx?mask=0&pos=0");
}
function createComboInvoiceno()
{
//if ($("hdEnabled").value == "false") {
// comboInvoiceno.disable(true);
//}
//
//comboInvoiceno.setOptionWidth(200);
comboInvoiceno.attachEvent("onChange", function () { comboInvoiceno.setComboText($("h_invoiceno").value); });
comboInvoiceno.setComboText($("h_invoiceno").value);
comboInvoiceno.attachEvent("onKeyPressed", function (keyCode) {
if (keyCode != "8") {
var arrayArg = new Array();
setTimeout(function () {
var is = -1;
var ishd = $("h_invoiceno").value.trim();
var filterCount = 0;
if ("" != comboInvoiceno.getComboText().trim()) {
while ("undefined" != typeof comboInvoiceno.getOptionByIndex(filterCount)) {
var comboValue = comboInvoiceno.getOptionByIndex(filterCount).text.toUpperCase(); //.value;
var enterValue = comboInvoiceno.getComboText().trim().toUpperCase();
$("h_invoiceno").value = comboInvoiceno.getComboText().trim().toUpperCase();
if (comboValue.indexOf(enterValue) == 0) {
comboInvoiceno.selectOption(filterCount, true, true);
is = filterCount;
break;
}
++filterCount;
}
// if (is == -1) {
// $("h_invoiceno").value = ishd;
// alert("无此内容,请重新选择!");
// }
}
}, 10);
}
})
comboInvoiceno.attachEvent("onSelectionChange", function () {
$("h_invoiceno").value = comboInvoiceno.getComboText().trim();
});
}
//删除费用明细只能用户手动添加费用
function deleteFee(){
if(commonGirdObj_fname != null){
var selArg = new Array();
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);
if(ckBox == 1){
selArg.push(rId);
}
}
if(selArg.length > 0){
if(window.confirm("您确定要删除此条费用,删除后无法恢复")){
for(var j = 0;j <selArg.length;j++){
var cacheName = "";//cachename
if($("h_cachename").value.trim() == ""){
$("h_cachename").value = commonGirdObj_fname.newGuid();
}
cacheName = "&cachename="+$("h_cachename").value;
var applyCurrency = $("h_settlecurrency").value.trim() == "RMB"?1:2;
var rowIndex = commonGirdObj_fname.getGridObj().getRowIndex(selArg[j]);
var feeName = commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,2).getValue().trim();
var money = ConvertToMoney(outputMoney(clearNoNum(commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,3).getValue().toString())));
var url = "InvoiceModifyGridSource.aspx?handle=deletefee&settlectype="+applyCurrency+cacheName+"&directfeeid="+selArg[j]+"&guid="+commonGirdObj_fname.newGuid();
var loader = dhtmlxAjax.getSync(url);
var totalList = loader.xmlDoc.responseText;
var totalListObj = eval('(' + totalList + ')');
if(totalListObj != null){
if(applyCurrency == 1 && totalListObj.total[0].finaltotal != 0){
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 && totalListObj.total[0].finaltotal != 0){
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
}
else{
$("txt_amountcapital").value = "";
$("txt_total").value = "";
}
}
commonGirdObj_fname.getGridObj().deleteRow(selArg[j]);
}
}
}
}
}
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
////删除费用
//function deleteFee(){
// if(commonGirdObj_fname != null && commonGridObj_fee != null){
// tempCache = $("h_list").value;
// if(tempCache.trim() == ""){
// tempCache = $("h_feecache").value;
// }
// jsonCacheObj = eval('(' + tempCache + ')');
//
//
// for(var i = 0;i <commonGirdObj_fname.getGridObj().getRowsNum();i++){
// var rId = commonGirdObj_fname.getGridObj().getRowId(i);//alert(rId);
// for(var j = jsonCacheObj.caches.length-1;j >= 0;j--){
// if(jsonCacheObj.caches[j].id == rId){
// if(jsonCacheObj.caches.length == 1){
// jsonCacheObj.caches.shift();
// $("h_list").value = "";
// initInvoice();
// break;
// }else{
// jsonCacheObj.caches.splice(j,1);
// $("h_list").value = JSON.stringify(jsonCacheObj);
// initInvoice();
// break;
// }
// }
// }
// }
// }
//}
function btnDisable(id){
$(id).disabled = true;
}
//重新加载Grid
function ReLoadGrid(){
var strList = $("h_feecache").value;
if(strList.trim() != ""){
jsonListObj = eval('(' + strList + ')');
//初始化Grid
commonGirdObj_fname.initGrid();
var IsRename = false;
for(var i=0;i<jsonCacheObj.caches.length;i++){
if(jsonCacheObj.caches[i].orig == 3){
IsRename = true;//orig==3是自定义名称费用
break;
}
}
if(IsRename){
var girdCount = 0;
for(var q = 0;q<jsonCacheObj.caches.length;q++){
if(jsonCacheObj.caches[q].orig == 2 || jsonCacheObj.caches[q].orig == 3){//只将自定义费用和手动添加费用添加到grid列表内
commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[q].id,["0","",jsonCacheObj.caches[q].fname,jsonCacheObj.caches[q].cstl],girdCount);
girdCount++;
}
}
}else{
var girdCount = 0;
for(var q = 0;q<jsonCacheObj.caches.length;q++){
if(jsonCacheObj.caches[q].orig == 1){//只将原始费用和手动添加费用添加到grid列表内
if(parseInt(jsonCacheObj.caches[q].type) == 1){
commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[q].id,["0","收",jsonCacheObj.caches[q].fname,jsonCacheObj.caches[q].cstl],girdCount);
girdCount++;
}else{
commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[q].id,["0","付",jsonCacheObj.caches[q].fname,jsonCacheObj.caches[q].cstl],girdCount);
girdCount++;
}
}else if(jsonCacheObj.caches[q].orig == 2){
commonGirdObj_fname.getGridObj().addRow(jsonCacheObj.caches[q].id,["0","",jsonCacheObj.caches[q].fname,jsonCacheObj.caches[q].cstl],girdCount);
girdCount++;
}
}
}
}else{
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;//alert(strList);
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;
}//alert(totalSettleFee);
var tempTotal = 0;
tempTotal = totalSettleFee < 0 ? (totalSettleFee * -1):totalSettleFee;
var currency = $("h_settlecurrency").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;
}
if(currency == "RMB"){
$("txt_total").value = "RMB "+moneyMath(totalSettleFee);
}else{
$("txt_total").value = "USD "+moneyMath(totalSettleFee);
}
}else{//如果Grid不存在任何费用,则金额大写和合计均为0
tempTotal = 0;
totalSettleFee = 0;
var currency = $("h_settlecurrency").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 = moneyMath(totalSettleFee);
if(currency == "RMB"){
$("txt_total").value = "RMB "+moneyMath(totalSettleFee);
}else{
$("txt_total").value = "USD "+moneyMath(totalSettleFee);
}
}
}
//添加费用
function addFee(){
var handleName = $("h_handle").value.trim();
if(handleName == "directmake"){
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;
// 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);
//
// 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();
// jsonCacheObj = null;
// $("h_feecache").value = "";
// break;
// }else{
// if(jsonCacheObj.caches[j].orig == 3){
// commonGirdObj_fname.getGridObj().deleteRow(jsonCacheObj.caches[j].id);
// jsonCacheObj.caches.splice(j,1);
//
// for(var z = jsonCacheObj.caches.length-1;z >= 0;z--){
// if(jsonCacheObj.caches[z].orig == 1){
// if(jsonCacheObj.caches.length == 1){
// jsonCacheObj.caches.shift();
// $("h_feecache").value = "";
// jsonCacheObj = null
// }else{
// jsonCacheObj.caches.splice(z,1);
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
//
// }
// }
// }
// }else{
// commonGirdObj_fname.getGridObj().deleteRow(jsonCacheObj.caches[j].id);
// jsonCacheObj.caches.splice(j,1);
// $("h_feecache").value = JSON.stringify(jsonCacheObj);
// }
// break;
// }
// }
// }
// iCount++;
// }
// }
// ReLoadGrid();//重新加载Grid
// GridEditHandleReload();//重新生成编辑框事件
// ReCalculate();
// }
//}
function GridEditHandleReload(){
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;//alert(tempCache);
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 = $("h_settlecurrency").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"};
jsonCacheObj.caches.push(newCache);
$("h_feecache").value = JSON.stringify(jsonCacheObj);
}
}else{
var cacheBuffer = "";
cacheBuffer += "{";
cacheBuffer += "\"id\":\""+rId+"\",";
cacheBuffer += "\"type\":\"\",";
cacheBuffer += "\"bsno\":\"\",";
cacheBuffer += "\"cus\":\"\",";
cacheBuffer += "\"fname\":\""+commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,2).getValue()+"\",";
var currency = $("h_settlecurrency").value.trim();
cacheBuffer += "\"cur\":\""+currency+"\",";
var money = ConvertToMoney(outputMoney(clearNoNum(commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,3).getValue().toString())));
cacheBuffer += "\"stl\":\""+money+"\",";//应结
cacheBuffer += "\"cstl\":\""+money+"\",";//本次结算
cacheBuffer += "\"ustl\":\"0\",";//未结
cacheBuffer += "\"orig\":\"2\"";//原始类型
cacheBuffer += "}";
var result = "";
result += "{\"caches\":[";
result += cacheBuffer;
result += "]}";
tempCache = result;
jsonCacheObj = eval('(' + result + ')');
$("h_feecache").value = JSON.stringify(jsonCacheObj);//alert($("h_feecache").value);
}
}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 = $("h_settlecurrency").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"};
jsonCacheObj.caches.push(newCache);
$("h_feecache").value = JSON.stringify(jsonCacheObj);
}
$("h_feecache").value = JSON.stringify(jsonCacheObj);
}else{
var cacheBuffer = "";
cacheBuffer += "{";
cacheBuffer += "\"id\":\""+rId+"\",";
cacheBuffer += "\"type\":\"\",";
cacheBuffer += "\"bsno\":\"\",";
cacheBuffer += "\"cus\":\"\",";
cacheBuffer += "\"fname\":\""+commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,2).getValue()+"\",";
var currency = $("h_settlecurrency").value.trim();
cacheBuffer += "\"cur\":\""+currency+"\",";
var money = ConvertToMoney(outputMoney(clearNoNum(commonGirdObj_fname.getGridObj().cellByIndex(rowIndex,3).getValue().toString())));
cacheBuffer += "\"stl\":\""+money+"\",";//应结
cacheBuffer += "\"cstl\":\""+money+"\",";//本次结算
cacheBuffer += "\"ustl\":\"0\",";//未结
cacheBuffer += "\"orig\":\"2\"";//原始类型
cacheBuffer += "}";
var result = "";
result += "{\"caches\":[";
result += cacheBuffer;
result += "]}";
tempCache = result;
jsonCacheObj = eval('(' + result + ')');
$("h_feecache").value = JSON.stringify(jsonCacheObj);//alert($("h_feecache").value);
}
ReCalculate();//重新计算费用
}
return true;
}
});
}
//生成税控
function invoiceAdapter(){
var strInvoiceID = "";
var typeName = "";
strInvoiceID = $("h_invoiceid").value;
var printUrl = "";
var companyID = "";
var typeName = "QDSK";
var dbSourceID = "";
var userID = "";
var url = "";
url = "../Reports/ReportService.aspx?handle=printinvoice&invoiceid="+strInvoiceID+"&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 = "qdsk://?comp="+companyID+"&type="+typeName+"&dbid="+strInvoiceID+"&uid="+userID;//alert(printUrl);
window.location.href = window.location.href;
location.href = printUrl;
}
}else{
alert("没有要打印的报表");
return;
}
}
//发票明细打印
function printInvoiceDetail(){
var strBillNO = "";
var typeName = "";
strBillNO = $("h_billno").value;
if(strBillNO.trim() != ""){
var printUrl = "";
var companyID = "";
var typeName = "INVOICEDETAIL";
var dbSourceID = "";
var userID = "";
var url = "";
url = "../Reports/ReportService.aspx?handle=printinvoicedetail&billno="+strBillNO+"&val="+commonGirdObj_fname.newGuid();
typeName = "INVOICEDETAIL";
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;
}
}
var docEle = function() {
return document.getElementById(arguments[0]) || false;
}
function openNewDiv(_id) {
var m = "mask";
if (docEle(_id)) document.removeChild(docEle(_id));
if (docEle(m)) document.removeChild(docEle(m));
// 新激活图层
var newDiv = document.createElement("div");
newDiv.id = _id;
newDiv.style.position = "absolute";
newDiv.style.zIndex = "9999";
newDiv.style.width = "400px";
newDiv.style.height = "120px";
newDiv.style.top = "100px";
newDiv.style.left = (parseInt(document.body.scrollWidth) - 300) / 2 + "px"; // 屏幕居中
newDiv.style.background = "#EFEFEF";
newDiv.style.border = "1px solid #860001";
newDiv.style.padding = "5px";
var urlVal = "../feecodes/CurrencyAdapter.aspx?handle=drate&val="+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(jsonCacheObj.drate[i].code == "RMB"){
rmbRate = parseFloat(jsonCacheObj.drate[i].drate);
}else if(jsonCacheObj.drate[i].code == "USD"){
usdRate = parseFloat(jsonCacheObj.drate[i].drate);
}
}
}
}
//人民币对美元汇率
var rmbToUsd = fomatFloat(1 / usdRate,5);
var usdToRmb = usdRate;
$("h_exrmbtousd").value = rmbToUsd;
$("h_exusdtormb").value = usdToRmb;
newDiv.innerHTML = "<table><tr><td colspan=\"5\" height=\"20px\"><div>币别汇率转换</div></td></tr><tr><td><div>1 RMB = </div></td><td><input type=\"hidden\" id=\"h_oldexusd\" value=\""+rmbToUsd+"\"/><input type=\"text\" id=\"txt_exusd\" width=\"40px\" value=\""+rmbToUsd+"\" onkeyup=\"exchangeCovert(this,txt_exrmb,1)\"/></td>"
+ "<td><div>&nbsp;&nbsp;USD</div></td><td width=\"15px\"></td><td><input type=\"button\" id=\"btn_enter\" value=\"确定\" class=\"btn\" onclick=\"rateEnter()\"/><td></tr><tr><td><div>1 USD = </div></td>"
+ "<td><input type=\"hidden\" id=\"h_oldexrmb\" value=\""+usdToRmb+"\"/><input type=\"text\" id=\"txt_exrmb\" width=\"40px\" value=\""+usdToRmb+"\" onkeyup=\"exchangeCovert(this,txt_exusd,2)\"/></td><td><div>&nbsp;&nbsp;RMB</div></td><td width=\"15px\"></td><td><input type=\"button\" id=\"btn_cancel\" value=\"取消\" class=\"btn\" onclick=\"rateCancel()\"/></td></tr></table>";
document.body.appendChild(newDiv);
// mask图层
var newMask = document.createElement("div");
newMask.id = m;
newMask.style.position = "absolute";
newMask.style.zIndex = "1";
newMask.style.width = document.body.scrollWidth + "px";
newMask.style.height = document.body.scrollHeight + "px";
newMask.style.top = "0px";
newMask.style.left = "0px";
newMask.style.background = "#000";
newMask.style.filter = "alpha(opacity=40)";
newMask.style.opacity = "0.40";
document.body.appendChild(newMask);
}
function fomatFloat(src,pos){
return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
}
function rateEnter(){
$("h_exrmbtousd").value = $("txt_exusd").value;
$("h_exusdtormb").value = $("txt_exrmb").value;
rateCancel();
if($("txt_total").value.trim() != ""){
var tempTotal = parseFloat($("txt_total").value.trim().substring($("txt_total").value.trim().indexOf("USD")+4,$("txt_total").value.trim().length - $("txt_total").value.trim().indexOf("USD")+1))
var exchangeRate = parseFloat($("h_exusdtormb").value);
var totalAmount = moneyMath(tempTotal*exchangeRate);
$("h_printamount").value = totalAmount;
var tempCapital = convertCurrency(moneyMath(totalAmount).toString(),1);
$("h_printcapital").value = tempCapital;
}
postEnterFee();
window.opener.location.href=window.opener.location.href;
}
//汇率设置取消
function rateCancel(){
document.body.removeChild(docEle("dvRate"));
document.body.removeChild(docEle("mask"));
}
function exchangeCovert(sourceObj,targetObj,type){
//RMB换算成USD
if(type == 1){
var rmbVal = clearNoNum(sourceObj.value);
if(rmbVal.trim() == ""){
rmbVal = 1;
}
var usdVal = clearNoNum(targetObj.value);
if(rmbVal == 0.0){
//sourceObj.value = rmbVal;
//targetObj.value = 0;//$("h_oldexusd").value;
return;
}
targetObj.value = fomatFloat(1/(usdVal*rmbVal),5);
}else if(type == 2){
//USD换算成RMB
var usdVal = sourceObj.value;
if(usdVal.trim() == ""){
usdVal = 0;
}
var rmbVal = targetObj.value;
targetObj.value = fomatFloat(1/usdVal,5);
}
}
//获取GUID
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 refresh(){
$("btn_makeout").disabled = true;
$("btn_makeout").onclick = clickNull;
}
function clickNull(){
}
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();
}