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/Settlements/SettlementEdit.aspx.cs

431 lines
23 KiB
C#

This file contains ambiguous Unicode characters!

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

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Data.SqlClient;
using WebSqlHelper;
namespace DSWeb.Settlements
{
public partial class SettlementEdit : System.Web.UI.Page
{
private string strSettlementID;//已开发票GID
private string strUserID;
private string strCompanyID;//公司GID
private string strShowName;//用户显示名
private string strDeptName;//部门名称
private string recvJSON_2;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
//
if (Request.QueryString["id"] != null)
{
strSettlementID = Request.QueryString["id"].ToString();
h_settlementid.Value = strSettlementID;
}
//
if (!IsPostBack)
{
//判断是否在结算页面显示预收预收信息录入
T_ALL_DA T_ALL_DA = new T_ALL_DA();
this.h_ISADVANCE.Value = T_ALL_DA.GetStrSQL("ISADVANCE", "select ISADVANCE from subcomp_seae_def where CORPID='" + strCompanyID + "'");
//是否取用预收预收默认是0 不取用
this.h_isAccess.Value = "0";
this.h_isSHOW.Value = "0";
this.h_enter.Value = "0";
//费用的结算单据用途1-收款2-收款
this.h_feetype.Value = "1";
//
this.h_bb5.Value = "RMB";
}
//
if (this.h_enter.Value.Trim() == "1")
{
//提交收费申请结算
RecordSettleFee();
}
else
{
if (strSettlementID != null)
{
GetSettlementInfo(strSettlementID);
}
}
//
}
#region 加载结算单信息
/// <summary>
/// 加载结算单信息
/// </summary>
/// <param name="tempSettlementID"></param>
private void GetSettlementInfo(string tempSettlementID)
{
//加载业务信息
FeeSettlementDA feeSettlementDA = new FeeSettlementDA();
//2013-02-05 修改
string strSql = " (SELECT BSNO,CASE WHEN BSSTATUS = 1 THEN '锁定' ELSE '未锁定' END as BSSTATUS,MBLNO,HBLNO,CUSTNO,INPUTBY,CREATETIME "
+ " FROM VW_Settlement WHERE BSNO IN (SELECT DISTINCT B.BSNO FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID = '" + strSettlementID + "' AND A.BILLNO LIKE '%DR%'))";
DataTable sourceTable = new DataTable();
sourceTable = feeSettlementDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("opinfo:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (i == 0)
{
sourceBuilder.Append("{bsno:\"" + sourceTable.Rows[i][0].ToString() + "\",");
}
else
{
sourceBuilder.Append(",{bsno:\"" + sourceTable.Rows[i][0].ToString() + "\",");
}
sourceBuilder.Append("\"bsstatus\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"mblno\":\"" + sourceTable.Rows[i][2].ToString() + "\",");
sourceBuilder.Append("\"hblno\":\"" + sourceTable.Rows[i][3].ToString() + "\",");
sourceBuilder.Append("\"custno\":\"" + sourceTable.Rows[i][4].ToString() + "\",");
sourceBuilder.Append("\"inputby\":\"" + sourceTable.Rows[i][5].ToString() + "\",");
sourceBuilder.Append("\"ctime\":\"" + sourceTable.Rows[i][6].ToString() + "\"}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
this.h_opcache.Value = sourceBuilder.ToString();
//加载结算信息
FeeSettlementEntity feeSettlementEntity = new FeeSettlementDA().GetFeeSettlementByGID(tempSettlementID);
if (feeSettlementEntity.GID != null)
{
this.txt_billno.Value = feeSettlementEntity.BillNO;
this.h_billno.Value = feeSettlementEntity.BillNO;
this.txt_customerName.Value = feeSettlementEntity.CustomerName;
switch(feeSettlementEntity.SettleMode)
{
case 1:
this.txt_billstatus.Value = "锁定";
break;
case 2:
this.txt_billstatus.Value = "未锁定";
break;
case 3:
this.txt_billstatus.Value = "结算撤销";
break;
default:
break;
}
this.h_settletype.Value = feeSettlementEntity.SettleType.ToString();
this.txt_voucherno.Value = feeSettlementEntity.VoucherNO;
this.txt_rmb.Value = feeSettlementEntity.AmountRMB.ToString();
this.txt_usd.Value = feeSettlementEntity.AmountUSD.ToString();
this.txt_remark.Text = feeSettlementEntity.Remark.ToString();
//
this.ddl_bb1.Value = feeSettlementEntity.ACCOUNTS_CURRENCY.ToString().Trim();
this.txt_hl1.Value = feeSettlementEntity.ACCOUNTS_RATE.ToString().Trim();
this.txt_je1.Value = feeSettlementEntity.ACCOUNTS_MONEY.ToString().Trim();
this.ddl_bb2.Value = feeSettlementEntity.PREPAY_CURRENCY.ToString().Trim();
this.txt_hl2.Value = feeSettlementEntity.PREPAY_RATE.ToString().Trim();
this.txt_je2.Value = feeSettlementEntity.PREPAY_MONEY.ToString().Trim();
this.ddl_bb3.Value = feeSettlementEntity.AHSR_CURRENCY.ToString().Trim();
this.txt_hl3.Value = feeSettlementEntity.AHSR_RATE.ToString().Trim();
this.txt_je3.Value = feeSettlementEntity.AHSR_MONEY.ToString().Trim();
this.ddl_bb4.Value = feeSettlementEntity.FINANCIAL_CURRENCY.ToString().Trim();
this.txt_hl4.Value = feeSettlementEntity.FINANCIAL_RATE.ToString().Trim();
this.txt_je4.Value = feeSettlementEntity.FINANCIAL_MONEY.ToString().Trim();
this.ddl_bb5.Value = feeSettlementEntity.ADVANCE_CURRENCY.ToString().Trim();
this.h_bb5.Value = feeSettlementEntity.ADVANCE_CURRENCY.ToString().Trim();
this.txt_hl5.Value = feeSettlementEntity.ADVANCE_RATE.ToString().Trim();
this.txt_je5.Value = feeSettlementEntity.ADVANCE_MONEY.ToString().Trim();
//
this.h_je1.Value = feeSettlementEntity.ACCOUNTS_MONEY.ToString().Trim();
this.h_je2.Value = feeSettlementEntity.PREPAY_MONEY.ToString().Trim();
this.h_je3.Value = feeSettlementEntity.AHSR_MONEY.ToString().Trim();
this.h_je4.Value = feeSettlementEntity.FINANCIAL_MONEY.ToString().Trim();
this.h_je5.Value = feeSettlementEntity.ADVANCE_MONEY.ToString().Trim();
//
T_ALL_DA T_ALL_DA = new T_ALL_DA();
this.txt_invoicenum.Value = T_ALL_DA.GetStrSQL("INVOICENUM", "select top 1 INVOICENUM from ch_fee where gid in (select top 1 feeid from ch_fee_do where billno='" + feeSettlementEntity.BillNO.ToString().Trim() + "')");
//
AccountDA accountDA = new AccountDA();
this.txt_rmbaccount.Value = "";
if (feeSettlementEntity.AccountRMB.Trim() != "")
{
AccountEntity accountEntity = new AccountEntity();
accountEntity = accountDA.GetAccountByID(feeSettlementEntity.AccountRMB.Trim());
if (accountEntity != null)
{
if (accountEntity.GID != null)
{
this.txt_rmbaccount.Value = accountEntity.BANKNAME;
}
}
}
this.txt_usdaccount.Value = "";
if (feeSettlementEntity.AccountUSD.Trim() != "")
{
AccountEntity accountEntity = new AccountEntity();
accountEntity = accountDA.GetAccountByID(feeSettlementEntity.AccountUSD.Trim());
if (accountEntity != null)
{
if (accountEntity.GID != null)
{
this.txt_usdaccount.Value = accountEntity.BANKNAME;
}
}
}
UserEntity userEntity = new UserEntity();
UserDA userDA = new UserDA();
userEntity = userDA.GetUserSignByID(feeSettlementEntity.SettleUser);
if (userEntity.Gid != null)
{
this.txt_settleuser.Value = userEntity.ShowName;
}
this.txt_settletime.Value = feeSettlementEntity.SettleTime.ToString() ;
}
}
#endregion
#region 执行更新预收预收信息
/// <summary>
/// 执行更新预收预收信息
/// </summary>
private void RecordSettleFee()
{
string ssql = "";
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
ArrayList alFeeDo = new ArrayList();
FeeSettlementEntity feeSettlementEntity = new FeeSettlementDA().GetFeeSettlementByGID(this.h_settlementid.Value.Trim());
#region 将页面post获取的信息解析
#region 预收支资料解析使用情况并形成sql语句
Decimal dlDOAMOUNT = this.txt_je2.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_je2.Value.Trim());
if (feeSettlementEntity.PREPAY_MONEY != dlDOAMOUNT)
{
ssql = "select count(*) as nums from ch_fee_advance_payment_detail where BILLNO='" + feeSettlementEntity.BillNO.ToString() + "' and (ISDELETE=0 or ISDELETE is null)";
int nums = int.Parse(T_ALL_DA.GetStrSQL("nums", ssql));
if (nums == 0)
{
if (dlDOAMOUNT != 0)
{
//更新主表
ssql = "update [ch_fee_advance_payment] set DOAMOUNT=DOAMOUNT+" + Decimal.Parse(this.txt_je2.Value.Trim()) + ",ISFINISH=0 where LINKGID='" + feeSettlementEntity.GID.ToString() + "' and (ISDELETE=0 or ISDELETE is null)";
alFeeDo.Add(ssql);
}
else
{
//删除主表
ssql = "delete from ch_fee_advance_payment where LINKGID='" + feeSettlementEntity.GID.ToString() + "'";
alFeeDo.Add(ssql);
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('此“预收支资料”已使用,不允许操作!请先删除已使用的“预收支取用资料”!');</script>");
return;
}
}
#endregion
if (this.h_isAccess.Value.Trim() == "1")
{
#region 反向更新和删除此结算以前的“预收预收取用”信息
ssql = "select * from ch_fee_advance_payment_detail where SETTLELINKGID='" + feeSettlementEntity.GID.ToString() + "' and (ISDELETE=0 or ISDELETE is null)";
DataSet ds = T_ALL_DA.GetAllSQL(ssql);
if (ds != null)
{
if (ds.Tables.Count > 0)
{
for (int i = 0; i < ds.Tables.Count; i++)
{
//更新主表
ssql = "update [ch_fee_advance_payment] set DOAMOUNT=DOAMOUNT-" + ds.Tables[0].Rows[i]["DOAMOUNT"].ToString() + ",ISFINISH=0 where GID='" + ds.Tables[0].Rows[i]["LINKGID"].ToString() + "' and (ISDELETE=0 or ISDELETE is null)";
alFeeDo.Add(ssql);
}
//删除明细表
ssql = "delete from ch_fee_advance_payment_detail where SETTLELINKGID='" + feeSettlementEntity.GID.ToString() + "'";
alFeeDo.Add(ssql);
}
}
#endregion
//
#region 预收预收取用解析post返回的值并形成插入更新的sql语句
recvJSON_2 = "";
recvJSON_2 = this.recvContainer_2.Value.Trim();
if (!recvJSON_2.Trim().Equals(""))
{
string tempSettle = recvJSON_2.Substring(recvJSON_2.IndexOf("[") + 1, recvJSON_2.IndexOf("]") - recvJSON_2.IndexOf("[") - 1);
string[] tempSettleFees = tempSettle.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries);
if (tempSettleFees.Length > 0)
{
for (int i = 0; i < tempSettleFees.Length; i++)
{
// 1 2 3 4 5 6 7
//客户名称,单号,实录时间,币别,实录金额,未核销金额,本次核销");
string GID = ""; //客户名称
string CUSTOMERNAME = ""; //客户名称
string BILLNO = ""; //单号
string CREATETIME = ""; //实录时间
string CURRENCY = ""; //币别
decimal AMOUNT = 0; //实录金额
decimal DOAMOUNT2 = 0; //未核销金额
decimal DOAMOUNT = 0; //本次核销
string ISFINISH = ""; //是否全部完成核销
tempSettleFees[i] = tempSettleFees[i].ToString().Replace("{", "");
tempSettleFees[i] = tempSettleFees[i].ToString().Replace("}", "");
string[] strCell = tempSettleFees[i].Split(new char[] { ',' });
if (strCell.Length > 0)
{
for (int j = 0; j < strCell.Length; j++)
{
string[] strArg = strCell[j].Split(new char[] { ':' });
switch (strArg[0].Replace("\"", ""))
{
case "GID":
GID = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "CUSTOMERNAME"://客户名称
UnicodeEncoding unicode = new UnicodeEncoding();
CUSTOMERNAME = unicode.GetString(unicode.GetBytes(Regex.Unescape(strArg[1].ToString().Replace("\"", "").Trim())));
break;
case "BILLNO"://单号
BILLNO = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "CREATETIME"://实录时间
CREATETIME = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "CURRENCY"://币别
CURRENCY = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "AMOUNT"://实录金额
AMOUNT = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "DOAMOUNT2"://未核销金额
DOAMOUNT2 = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "DOAMOUNT"://本次核销
DOAMOUNT = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "ISFINISH"://是否全部完成核销
ISFINISH = strArg[1].ToString().Replace("\"", "").Trim();
break;
default:
break;
}
}
}
if (DOAMOUNT != 0 && GID.Trim() != "")
{
//更新主表
ssql = "update [ch_fee_advance_payment] set DOAMOUNT=DOAMOUNT+" + DOAMOUNT + ",ISFINISH=" + ISFINISH + " where GID='" + GID + "' and (ISDELETE=0 or ISDELETE is null)";
alFeeDo.Add(ssql);
//插入明细表
ssql = "INSERT INTO [ch_fee_advance_payment_detail](GID,LINKGID,BILLNO,SETTLELINKGID,SETTLEBILLNO,FEETYPE,CUSTOMERNAME,CURRENCY,DOAMOUNT,SETTLEUSER,SETTLETIME,REMARK,ISDELETE,DELETEUSER,COMPANYID,VOUCHERNO) "
+ " values ('" + Guid.NewGuid().ToString() + "','" + GID + "','" + BILLNO + "','" + feeSettlementEntity.GID.ToString() + "','" + feeSettlementEntity.BillNO.ToString() + "',1,'" + CUSTOMERNAME + "','" + CURRENCY + "'," + DOAMOUNT + ",'" + strUserID.Trim() + "',getdate(),'',0,'','" + strCompanyID.Trim() + "','')";
alFeeDo.Add(ssql);
}
//
}
}
//
recvJSON_2 = "";
this.recvContainer_2.Value = "";
}
#endregion
}
#region 更新结算表中预收预收信息形成sql语句
//预收
feeSettlementEntity.ACCOUNTS_CURRENCY = this.ddl_bb1.Value.Trim();
feeSettlementEntity.ACCOUNTS_RATE = this.txt_hl1.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_hl1.Value.Trim());
feeSettlementEntity.ACCOUNTS_MONEY = this.txt_je1.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_je1.Value.Trim());
feeSettlementEntity.PREPAY_CURRENCY = this.ddl_bb2.Value.Trim();
feeSettlementEntity.PREPAY_RATE = this.txt_hl2.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_hl2.Value.Trim());
feeSettlementEntity.PREPAY_MONEY = this.txt_je2.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_je2.Value.Trim());
feeSettlementEntity.AHSR_CURRENCY = this.ddl_bb3.Value.Trim();
feeSettlementEntity.AHSR_RATE = this.txt_hl3.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_hl3.Value.Trim());
feeSettlementEntity.AHSR_MONEY = this.txt_je3.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_je3.Value.Trim());
feeSettlementEntity.FINANCIAL_CURRENCY = this.ddl_bb4.Value.Trim();
feeSettlementEntity.FINANCIAL_RATE = this.txt_hl4.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_hl4.Value.Trim());
feeSettlementEntity.FINANCIAL_MONEY = this.txt_je4.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_je4.Value.Trim());
//feeSettlementEntity.ADVANCE_CURRENCY = this.ddl_bb5.Value.Trim();
feeSettlementEntity.ADVANCE_CURRENCY = this.h_bb5.Value.Trim();
feeSettlementEntity.ADVANCE_RATE = this.txt_hl5.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_hl5.Value.Trim());
feeSettlementEntity.ADVANCE_MONEY = this.txt_je5.Value.Trim() == "" ? 0 : Decimal.Parse(this.txt_je5.Value.Trim());
ssql = "update [ch_fee_settlement] set "
+ "ACCOUNTS_CURRENCY = '" + feeSettlementEntity.ACCOUNTS_CURRENCY + "'"
+ ",ACCOUNTS_RATE = '" + feeSettlementEntity.ACCOUNTS_RATE + "'"
+ ",ACCOUNTS_MONEY = '" + feeSettlementEntity.ACCOUNTS_MONEY + "'"
+ ",PREPAY_CURRENCY = '" + feeSettlementEntity.PREPAY_CURRENCY + "'"
+ ",PREPAY_RATE = '" + feeSettlementEntity.PREPAY_RATE + "'"
+ ",PREPAY_MONEY = '" + feeSettlementEntity.PREPAY_MONEY + "'"
+ ",AHSR_CURRENCY = '" + feeSettlementEntity.AHSR_CURRENCY + "'"
+ ",AHSR_RATE = '" + feeSettlementEntity.AHSR_RATE + "'"
+ ",AHSR_MONEY = '" + feeSettlementEntity.AHSR_MONEY + "'"
+ ",FINANCIAL_CURRENCY = '" + feeSettlementEntity.FINANCIAL_CURRENCY + "'"
+ ",FINANCIAL_RATE = '" + feeSettlementEntity.FINANCIAL_RATE + "'"
+ ",FINANCIAL_MONEY = '" + feeSettlementEntity.FINANCIAL_MONEY + "'"
+ ",ADVANCE_CURRENCY = '" + feeSettlementEntity.ADVANCE_CURRENCY + "'"
+ ",ADVANCE_RATE = '" + feeSettlementEntity.ADVANCE_RATE + "'"
+ ",ADVANCE_MONEY = '" + feeSettlementEntity.ADVANCE_MONEY + "'"
+ " where GID='" + feeSettlementEntity.GID.ToString() + "'";
alFeeDo.Add(ssql);
#endregion
FeePaySettleApplicationDA feePaySettleApplicationDA = new FeePaySettleApplicationDA();
int iResult = feePaySettleApplicationDA.alDo(alFeeDo);
if (iResult == 1)
{
h_enter.Value = "0";
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('收费结算成功');window.parent.opener.location.href = window.parent.opener.location.href;window.close();</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('收费结算失败');</script>");
}
#endregion
}
#endregion
}
}