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

496 lines
18 KiB
JavaScript

var commonGridObj_do;
var jsonCacheObj;
function $(id){
return document.getElementById(id);
}
function createGrid(){
//header
var headerArgs_do = new Array("币别","金额","入账账户");
//width
var widthArgs_do = new Array("70","80","400");
//column align
var colAlignArgs_do = new Array("center","center","center");
//column sort
var colSortArgs_do = new Array("str","str","str");
//column type
var colTypeArgs_do = new Array("ro","ro","co");
commonGridObj_do = new TGridCommon("mygrid_container_do","form1",headerArgs_do,widthArgs_do,colAlignArgs_do,colSortArgs_do,colTypeArgs_do);
commonGridObj_do.setResponseUrl("SettlementGridSourceApp.aspx");
//var _billno = $("billno").value;
commonGridObj_do.setRequest("SettlementGridSourceApp.aspx?handle=billlist&billno="+1);
commonGridObj_do.setSourceType("json");
commonGridObj_do.setSkin("xp");
commonGridObj_do.setImageUrl("../images/");
commonGridObj_do.initGrid();
commonGridObj_do.bind();
setTimeout(function(){
if($("h_settleinfo").value != ""){
var tempSettleInfo = $("h_settleinfo").value;
jsonSettleObj = eval('(' + tempSettleInfo + ')');
var isRun = false;
for(var i=0;i < commonGridObj_do.getGridObj().getRowsNum();i++){
var rowId = commonGridObj_do.getGridObj().getRowId(i);
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rowId);
for(var j = 0;j<jsonSettleObj.settles.length;j++){
if(jsonSettleObj.settles[i].id = rowId){
commonGridObj_do.getGridObj().cellByIndex(rowIndex,2).setLabel(jsonSettleObj.settles[i].bank);
isRun = true;
break;
}
}
commonGridObj_do.bind();
}
if(isRun){
commonGridObj_do.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
if(stage == 0){
return false;
}
});
}
}
},50);
commonGridObj_do.getGridObj().enableEditEvents(true,false,true);
var tempCache = $("h_feecache").value;
jsonCacheObj = eval('(' + tempCache + ')');
var totalFee = 0.0;
var totalRmbFee = 0.0;//RMB费用合计
var totalUsdFee = 0.0;//USD费用合计
var totalOtherFee = 0.0;//其他费用合计
var customerName = "";
if(jsonCacheObj.caches.length > 0){
for(var i=0;i<jsonCacheObj.caches.length;i++){
var feeType = 0;
if(i == 0){
customerName = jsonCacheObj.caches[i].cus;
$("txt_customerName").value = customerName;
}
feeType = parseInt(jsonCacheObj.caches[i].type);
var cstl = parseFloat(jsonCacheObj.caches[i].cstl);
var cur = jsonCacheObj.caches[i].cur;
if(cur == "RMB"){//如果此条费用为RMB
if(feeType == 1){//如果是应收则累加费用
totalRmbFee += cstl;
}else{//如果是应付则累减数据
totalRmbFee -= cstl;
}
}else if(cur == "USD"){//如果此条费用为USD
if(feeType == 1){//如果是应收则累加费用
totalUsdFee += cstl;
}else{//如果是应付则累减数据
totalUsdFee -= cstl;
}
}else{
if(feeType == 1){//如果是应收则累加费用
totalOtherFee += cstl;
}else{//如果是应付则累减数据
totalOtherFee -= cstl;
}
}
}
//
if (totalUsdFee == 0 && totalRmbFee == 0) {
var newId = commonGridObj_do.newGuid();
var usdToRmbRate = parseFloat($("h_usdtormb").value);
var sumRmdFee = totalRmbFee;
commonGridObj_do.getGridObj().addRow(newId, ["RMB", sumRmdFee, ""], 0);
commonGridObj_do.bind();
}
else {
//alert(totalRmbFee);
var settleCurrency = $("h_settlecurrency").value;
var url = "SettlementGridSourceApp.aspx?handle=bankinfo&uid=" + commonGridObj_do.newGuid();
var loader = dhtmlxAjax.getSync(url);
var bankInfo = loader.xmlDoc.responseText;
var jsonCacheObj = eval('(' + bankInfo + ')');
if (settleCurrency == 1) {
if (totalUsdFee != 0) {
var newId = commonGridObj_do.newGuid();
var usdToRmbRate = parseFloat($("h_usdtormb").value);
totalFee = moneyMath(totalUsdFee * usdToRmbRate);
if (totalRmbFee != 0) {
totalFee += totalRmbFee;
}
commonGridObj_do.getGridObj().addRow(newId, ["RMB", totalFee, ""], 0);
commonGridObj_do.bind();
for (var k = 0; k < jsonCacheObj.banks.length; k++) {
if (jsonCacheObj.banks[k].cur == "RMB") {
var newCombo = commonGridObj_do.getGridObj().getCustomCombo(newId, 2);
newCombo.put(jsonCacheObj.banks[k].id, jsonCacheObj.banks[k].bank);
}
}
commonGridObj_do.bind();
}
if (totalRmbFee != 0) {
var newId = commonGridObj_do.newGuid();
totalFee = totalRmbFee;
commonGridObj_do.getGridObj().addRow(newId, ["RMB", totalFee, ""], 0);
commonGridObj_do.bind();
for (var k = 0; k < jsonCacheObj.banks.length; k++) {
if (jsonCacheObj.banks[k].cur == "RMB") {
var newCombo = commonGridObj_do.getGridObj().getCustomCombo(newId, 2);
newCombo.put(jsonCacheObj.banks[k].id, jsonCacheObj.banks[k].bank);
}
}
commonGridObj_do.bind();
}
}
else if (settleCurrency == 2) {
if (totalRmbFee != 0) {
var newId = commonGridObj_do.newGuid();
var rmbToUsdRate = parseFloat($("h_rmbtousd").value);
totalFee = moneyMath(totalRmbFee * rmbToUsdRate);
if (totalUsdFee != 0) {
totalFee += totalUsdFee;
}
//alert(totalFee);
commonGridObj_do.getGridObj().addRow(newId, ["USD", totalFee, ""], 0);
commonGridObj_do.bind();
for (var k = 0; k < jsonCacheObj.banks.length; k++) {
if (jsonCacheObj.banks[k].cur == "USD") {
var newCombo = commonGridObj_do.getGridObj().getCustomCombo(newId, 2);
newCombo.put(jsonCacheObj.banks[k].id, jsonCacheObj.banks[k].bank);
}
}
commonGridObj_do.bind();
}
if (totalUsdFee != 0) {
var newId = commonGridObj_do.newGuid();
totalFee = totalUsdFee;
commonGridObj_do.getGridObj().addRow(newId, ["USD", totalFee, ""], 0);
commonGridObj_do.bind();
for (var k = 0; k < jsonCacheObj.banks.length; k++) {
if (jsonCacheObj.banks[k].cur == "USD") {
var newCombo = commonGridObj_do.getGridObj().getCustomCombo(newId, 2);
newCombo.put(jsonCacheObj.banks[k].id, jsonCacheObj.banks[k].bank);
}
}
commonGridObj_do.bind();
}
}
else {
if (totalRmbFee != 0) {
var newId = commonGridObj_do.newGuid();
var usdToRmbRate = parseFloat($("h_usdtormb").value);
var sumRmdFee = totalRmbFee //+ (totalUsdFee * usdToRmbRate);
commonGridObj_do.getGridObj().addRow(newId, ["RMB", sumRmdFee, ""], 0);
commonGridObj_do.bind();
for (var k = 0; k < jsonCacheObj.banks.length; k++) {
if (jsonCacheObj.banks[k].cur == "RMB") {
var newCombo = commonGridObj_do.getGridObj().getCustomCombo(newId, 2);
newCombo.put(jsonCacheObj.banks[k].id, jsonCacheObj.banks[k].bank);
}
}
}
if (totalUsdFee != 0) {
var newId = commonGridObj_do.newGuid();
var rmbToUsdRate = parseFloat($("h_rmbtousd").value);
var sumUsdFee = totalUsdFee;
if (totalRmbFee != 0) {
commonGridObj_do.getGridObj().addRow(newId, ["USD", sumUsdFee, ""], 1);
} else {
commonGridObj_do.getGridObj().addRow(newId, ["USD", sumUsdFee, ""], 0);
}
commonGridObj_do.bind();
for (var k = 0; k < jsonCacheObj.banks.length; k++) {
if (jsonCacheObj.banks[k].cur == "USD") {
var newCombo = commonGridObj_do.getGridObj().getCustomCombo(newId, 2);
newCombo.put(jsonCacheObj.banks[k].id, jsonCacheObj.banks[k].bank);
}
}
}
commonGridObj_do.bind();
}
}
}
}
function saveSettle(){
if(commonGridObj_do != null){
// var currency = commonGridObj_do.getGridObj().cellByIndex(0,0).getValue();
// var amount = commonGridObj_do.getGridObj().cellByIndex(0,1).getValue();
// var account = commonGridObj_do.getGridObj().cellByIndex(0,2).getValue();
// var bankinfo = commonGridObj_do.getGridObj().cellByIndex(0,2).getText();
//
// if(account == ""){
// alert("请选择要入账的账户");
// return;
// }
// $("h_currency").value = currency;
// $("h_amount").value = amount;
// $("h_account").value = account;
// $("h_bankinfo").value = bankinfo;
var jsonSettleObj = null;
for(var i = 0;i <commonGridObj_do.getGridObj().getRowsNum();i++){
//alert(commonGridObj_do.getGridObj().getRowId(0));alert(commonGridObj_do.getGridObj().getRowId(1));
var rId = commonGridObj_do.getGridObj().getRowId(i);
var rowIndex = commonGridObj_do.getGridObj().getRowIndex(rId);
var tempSettleInfo = $("h_settleinfo").value;
if(tempSettleInfo == ""){
var cacheBuffer = "";
cacheBuffer += "{";
cacheBuffer += "\"id\":\""+rId+"\",";
cacheBuffer += "\"cur\":\""+commonGridObj_do.getGridObj().cellByIndex(rowIndex,0).getValue()+"\",";//币别
cacheBuffer += "\"amount\":\""+commonGridObj_do.getGridObj().cellByIndex(rowIndex,1).getValue()+"\",";//金额.toFixed(2)
cacheBuffer += "\"account\":\""+commonGridObj_do.getGridObj().cellByIndex(rowIndex,2).getValue()+"\",";//入账账户GID
cacheBuffer += "\"bank\":\""+commonGridObj_do.getGridObj().cellByIndex(rowIndex,2).getText()+"\"";//入账账户显示信息
cacheBuffer += "}";
var result = "";
result += "{\"settles\":[";
result += cacheBuffer;
result += "]}";
jsonSettleObj = eval('(' + result + ')');
$("h_settleinfo").value = JSON.stringify(jsonSettleObj);
}else{
jsonSettleObj = eval('(' + tempSettleInfo + ')');
var newSettles = jsonSettleObj.settles;
newSettles = {id:rId,cur:commonGridObj_do.getGridObj().cellByIndex(rowIndex,0).getValue(),amount:commonGridObj_do.getGridObj().cellByIndex(rowIndex,1).getValue(),account:commonGridObj_do.getGridObj().cellByIndex(rowIndex,2).getValue(),bank:commonGridObj_do.getGridObj().cellByIndex(rowIndex,2).getText()};//.toFixed(2)
jsonSettleObj.settles.push(newSettles);
$("h_settleinfo").value = JSON.stringify(jsonSettleObj);
}
}
if($("h_billno").value.trim() == ""){
$("h_enter").value = "1";
$("h_post").value = "1";
postEnterFee();
//window.opener.location.href = window.opener.location.href;
}
}
}
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(){
var strBillNO = "";
strBillNO = $("txt_billNO").value;
if(strBillNO.trim() != ""){
var url = "SettlementGridSourceApp.aspx?handle=cancelrecvsettle&billno="+strBillNO+"&uid="+commonGridObj_do.newGuid();
var loader = dhtmlxAjax.getSync(url);
var stateInfo = loader.xmlDoc.responseText;
var state = parseInt(stateInfo);
if(state == 1){
alert("收费结算撤销完成");
}else if(state == -3){
alert("收费结算撤销已完成,不能重复操作");
}else if(state == -4){
alert("收费结算信息不存在");
}
$("btn_enter").disabled = true;
}else{
alert("费用未结算,不能进行撤销操作");
}
}
function printSettle(){
var strBillNO = "";
var typeName = "";
strBillNO = $("txt_billNO").value;
if(strBillNO.trim() != ""){
var printUrl = "";
var companyID = "";
var typeName = "RECVSETTLE";
var dbSourceID = "";
var userID = "";
var url = "";
url = "../Reports/ReportService.aspx?handle=printrecvsettle&billno="+strBillNO+"&val="+commonGridObj_do.newGuid();
typeName = "RECVSETTLE";
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;
}
}
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
function closeAction() {
window.parent.opener.location.href = window.parent.opener.location.href;
window.close();
}
function refresh() {
closeAction();
}
function cwvouchersadd(gid) {
var url = "../CW/CwVouchersChFeeSettlementListGridSource.aspx?handle=isvouchers&gids=" + gid + "&uid=" + newGuid();
var loader = dhtmlxAjax.getSync(url);
var jsVal = loader.xmlDoc.responseText;
if (jsVal.trim() != "") {
alert(jsVal); //"有已生成的凭证,不能重复生成!"
return;
}
//
var url = "../CW/CwVouchersAddDoGridSource.aspx?read=isvouchers&gids=" + gid + "&uid=" + newGuid();
var loader = dhtmlxAjax.getSync(url);
var jsVal = loader.xmlDoc.responseText;
if (jsVal.trim() == "") {
alert("生成凭证失败!"); //"有已生成的凭证,不能重复生成!"
return;
}
//
var feature = "height=500, width=1000, toolbar=no, menubar=no,scrollbars=no, resizable=0,location=no, status=no,Top= " + (screen.height / 2 - 300) + ",Left= " + (screen.width / 2 - 500);
var URLs = "../CW/CwVouchersAddDo.aspx?ordno=" + jsVal;
window.open(URLs, "生成结算凭证信息", feature);
}
function newGuid() {
var guid = "";
for (var i = 1; i <= 32; i++) {
var n = Math.floor(Math.random() * 16.0).toString(16);
guid += n;
if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
guid += "-";
}
return guid.toUpperCase();
}