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/Invoice/InvoiceVerificationEdit.asp...

477 lines
22 KiB
C#

11 months ago
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.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace DSWeb.Invoice
{
public partial class InvoiceVerificationEdit : System.Web.UI.Page
{
private string strHandle;
private string strInvoiceID;
private string strUserID;
private string strCompanyID;//公司GID
private string strDeptName;//部门名称
private string strShowName;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString();
}
if (Request.QueryString["id"] != null)
{
strInvoiceID = Request.QueryString["id"].ToString();
h_invoiceid.Value = strInvoiceID;
GetBankInfoList();
}
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Session["SHOWNAME"] != null)
{
this.strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
if (!IsPostBack)
{
if (this.txt_settleTime.Value.Trim() == "")
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string rq = T_ALL_DA.GetStrSQL("rq", "select getdate() as rq");//convert(char(10),getdate(),20)
this.txt_settleTime.Value = rq;
}
}
if (h_post.Value.Trim() != "")
{
if (h_post.Value.Trim().Equals("1"))
{
SaveRecvVerification();
}
}
}
public void GetBankInfoList()
{
FeeSettlementDA feeSettlementDA = new FeeSettlementDA();
DataTable sourceTable;
string strSql = "SELECT GID,CODENAME,CURRENCY,BANKNAME,ACCOUNT FROM sys_bank";
sourceTable = feeSettlementDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("banks:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (i == 0)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
}
else
{
sourceBuilder.Append(",{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
}
sourceBuilder.Append("\"code\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"cur\":\"" + sourceTable.Rows[i][2].ToString() + "\",");
sourceBuilder.Append("\"bank\":\"" + sourceTable.Rows[i][3].ToString() + "\",");
sourceBuilder.Append("\"acc\":\"" + sourceTable.Rows[i][4].ToString() + "\"}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
this.h_bankcache.Value = sourceBuilder.ToString();
}
#region
private int SaveRecvVerification()
{
int billtype = 0;//1收费2付费
int iResult = 0;
string strInvoiceBillNO = "";
//string settleFee = "";
//string customerName = "";
//string strFeeCache = "";
string strBillNO = "";
strBillNO = CreateSettleCode();
IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
#region
//strFeeCache = h_feelist.Value;
//if (strFeeCache.IndexOf("[") >= 0 && strFeeCache.IndexOf("]") > 0)
//{
// strBillNO = CreateSettleCode();
// settleFee = strFeeCache.Substring(strFeeCache.IndexOf("[") + 1, strFeeCache.IndexOf("]") - strFeeCache.IndexOf("[") - 1);
// IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
// //settleFee = settleFee.Replace(, "#");
// string[] strFees = settleFee.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries);
// if (strFees.Length > 0)
// {
// for (int i = 0; i < strFees.Length; i++)
// {
// strFees[i] = strFees[i].ToString().Replace("{", "");
// strFees[i] = strFees[i].ToString().Replace("}", "");
// string[] strCell = strFees[i].Split(new char[] { ',' });
// if (strCell.Length > 0)
// {
// FeeDoEntity feeDoEntity = new FeeDoEntity();
// for (int j = 0; j < strCell.Length; j++)
// {
// string[] strArg = strCell[j].Split(new char[] { ':' });
// switch (strArg[0].Replace("\"", ""))
// {
// case "id":
// feeDoEntity.FeeID = strArg[1].ToString().Replace("\"", "").Trim();
// break;
// case "type":
// feeDoEntity.FeeType = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "cur":
// feeDoEntity.Currency = strArg[1].ToString().Replace("\"", "").Trim();
// break;
// case "stl":
// feeDoEntity.Amount = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "cstl":
// feeDoEntity.DoAmount = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "ustl":
// break;
// case "cus":
// feeDoEntity.CustomerName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "fname":
// feeDoEntity.FeeName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "bsno":
// feeDoEntity.BSNO = strArg[1].ToString().Replace("\"", "").Trim();
// break;
// case "orig":
// if (!strArg[1].ToString().Replace("\"", "").Trim().Equals(""))
// {
// feeDoEntity.Orig = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// }
// break;
// case "oname":
// if (!strArg[1].ToString().Replace("\"", "").Trim().Equals(""))
// {
// feeDoEntity.OriginalFeeName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
// }
// break;
// case "ocstl":
// if (!strArg[1].ToString().Replace("\"", "").Trim().Equals(""))
// {
// feeDoEntity.OriginalFeeCSTL = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// }
// break;
// default:
// break;
// }
// }
// //feeDoEntity.BSNO = "";
// feeDoEntity.MBLNO = "";
// feeDoEntity.HBLNO = "";
// //feeDoEntity.CustomerName = "";
// //feeDoEntity.FeeName = "";
// feeDoEntity.BillNO = strBillNO;
// feeDoEntity.GID = Guid.NewGuid().ToString();
// feeDoEntity.Category = 2;
// feeDoEntity.BSType = 1;
// feeDoEntity.BillStatus = 1;
// feeDoEntity.Remark = "";
// feeDoEntities.Add(feeDoEntity);
// }
// }
// }
#endregion
DataTable sourceTable = new DataTable();
string strCacheName = h_cacheid.Value.Trim();
if (Session[strCacheName] != null)
{
InvoiceDA invoiceDA = new InvoiceDA();
InvoiceEntity invoiceEntity = invoiceDA.GetInvoiceByGID(strInvoiceID);
if (invoiceEntity != null)
{
if (invoiceEntity.GID != null)
{
strInvoiceBillNO = invoiceEntity.BillNO;
}
}
//获取缓存数据
sourceTable = (DataTable)Session[strCacheName];
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
FeeDoEntity feeDoEntity = new FeeDoEntity();
feeDoEntity.FeeID = sourceTable.Rows[i]["GID"].ToString();
feeDoEntity.FeeType = sourceTable.Rows[i]["FEETYPE"].ToString().Trim().Equals("收") ? 1 : 2;
billtype = feeDoEntity.FeeType;
feeDoEntity.Currency = sourceTable.Rows[i]["CURRENCY"].ToString();
feeDoEntity.Amount = decimal.Parse(sourceTable.Rows[i]["SETTLEMENT"].ToString());
feeDoEntity.DoAmount = decimal.Parse(sourceTable.Rows[i]["SETTLEMENT"].ToString());
feeDoEntity.CustomerName = sourceTable.Rows[i]["CUSTOMERNAME"].ToString();
feeDoEntity.FeeName = sourceTable.Rows[i]["FEENAME"].ToString();
feeDoEntity.BSNO = sourceTable.Rows[i]["BSNO"].ToString();
feeDoEntity.Orig = 1;
feeDoEntity.OriginalFeeName = sourceTable.Rows[i]["FEENAME"].ToString();
feeDoEntity.OriginalFeeCSTL = decimal.Parse(sourceTable.Rows[i]["SETTLEMENT"].ToString());
feeDoEntity.MBLNO = "";
feeDoEntity.HBLNO = "";
feeDoEntity.BillNO = strBillNO;
feeDoEntity.GID = Guid.NewGuid().ToString();
feeDoEntity.Category = 2;
feeDoEntity.BSType = 1;
feeDoEntity.BillStatus = 1;
feeDoEntity.Remark = this.h_remark.Value.Trim();
feeDoEntity.InvoiceSettleNO = strInvoiceBillNO;
feeDoEntities.Add(feeDoEntity);
}
if (feeDoEntities.Count > 0)
{
IList<FeeSettlementEntity> feeSettlementEntities = new List<FeeSettlementEntity>();
FeeSettlementEntity feeSettlementEntity = new FeeSettlementEntity();
feeSettlementEntity.GID = Guid.NewGuid().ToString();
if (ck_rmb.Checked)
{
feeSettlementEntity.AccountRMB = this.sel_rmbbank.Value.Trim();
feeSettlementEntity.AmountRMB = decimal.Parse(this.h_rmbtotal.Value.Trim());
feeSettlementEntity.AccountUSD = "";
feeSettlementEntity.AmountUSD = 0;
}
else if (ck_usd.Checked)
{
feeSettlementEntity.AccountUSD = this.sel_usdbank.Value.Trim();
feeSettlementEntity.AmountUSD = decimal.Parse(this.h_usdtotal.Value.Trim());
feeSettlementEntity.AccountRMB = "";
feeSettlementEntity.AmountRMB = 0;
}
else
{
feeSettlementEntity.AccountRMB = this.sel_rmbbank.Value.Trim();
feeSettlementEntity.AmountRMB = decimal.Parse(this.h_rmbtotal.Value.Trim());
feeSettlementEntity.AccountUSD = this.sel_usdbank.Value.Trim();
feeSettlementEntity.AmountUSD = decimal.Parse(this.h_usdtotal.Value.Trim());
}
//预收预付自由结算时,赋值
feeSettlementEntity.ACCOUNTS_CURRENCY = (feeSettlementEntity.AmountUSD == 0) ? "RMB" : "USD";//记账资料_币别
feeSettlementEntity.ACCOUNTS_RATE = feeSettlementEntity.Rate;//记账资料_汇率
feeSettlementEntity.ACCOUNTS_MONEY = (feeSettlementEntity.AmountUSD == 0) ? feeSettlementEntity.AmountRMB : feeSettlementEntity.AmountUSD;//记账资料_金额
feeSettlementEntity.PREPAY_CURRENCY = (feeSettlementEntity.AmountUSD == 0) ? "RMB" : "USD";//预付支资料_币别
feeSettlementEntity.PREPAY_RATE = feeSettlementEntity.Rate;//预付支资料_汇率
feeSettlementEntity.PREPAY_MONEY = 0;//预付支资料_金额
feeSettlementEntity.AHSR_CURRENCY = (feeSettlementEntity.AmountUSD == 0) ? "RMB" : "USD";//实付支资料_币别
feeSettlementEntity.AHSR_RATE = feeSettlementEntity.Rate;//实付支资料_汇率
feeSettlementEntity.AHSR_MONEY = (feeSettlementEntity.AmountUSD == 0) ? feeSettlementEntity.AmountRMB : feeSettlementEntity.AmountUSD;//实付支资料_金额
feeSettlementEntity.FINANCIAL_CURRENCY = (feeSettlementEntity.AmountUSD == 0) ? "RMB" : "USD";//财务费用_币别
feeSettlementEntity.FINANCIAL_RATE = feeSettlementEntity.Rate;//财务费用_汇率
feeSettlementEntity.FINANCIAL_MONEY = 0;//财务费用_金额
feeSettlementEntity.ADVANCE_CURRENCY = (feeSettlementEntity.AmountUSD == 0) ? "RMB" : "USD";//预付支取用资料_币别
feeSettlementEntity.ADVANCE_RATE = feeSettlementEntity.Rate;//预付支取用资料_汇率
feeSettlementEntity.ADVANCE_MONEY = 0;//预付支取用资料_金额
//
feeSettlementEntity.BillNO = strBillNO;
feeSettlementEntity.BillType = billtype;//由feeDoEntity.FeeType决定
feeSettlementEntity.VoucherNO = "";
feeSettlementEntity.SettleUser = strUserID;//txt_settleUser.Value.Trim();
feeSettlementEntity.BillStatus = 1;
feeSettlementEntity.SettleMode = 3;//自由结算
feeSettlementEntity.FinancialVoucher = "";
feeSettlementEntity.CustomerName = h_customer.Value.Trim();//结算单位
feeSettlementEntity.SettleType = int.Parse(this.h_settlemode.Value);
feeSettlementEntity.Remark = this.h_remark.Value.Trim();
feeSettlementEntity.CompanyID = strCompanyID;
if (this.txt_settleTime.Value.Trim() != "" && this.txt_settleTime.Value.Trim().IndexOf("0001") < 0)
{
feeSettlementEntity.SettleTime = DateTime.Parse(this.txt_settleTime.Value.Trim());
}
feeSettlementEntities.Add(feeSettlementEntity);
FeeDoDA feeDoDA = new FeeDoDA();
//InvoiceEntity invoiceEntity = new InvoiceEntity();
//InvoiceDA invoiceDA = new InvoiceDA();
//invoiceEntity = invoiceDA.GetInvoiceByGID(strInvoiceID);
iResult = feeDoDA.SettleInvoice(feeDoEntities, feeSettlementEntities, strInvoiceID, invoiceEntity.InvoiceNO);
if (iResult == 1)
{
this.btn_settle.Disabled = true;
this.h_feelist.Value = "";
this.h_post.Value = "";
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('操作成功');window.parent.opener.location.href=window.parent.opener.location.href;window.close();</script>");
}
}
}
return iResult;
}
#endregion
private string CreateSettleCode()
{
int CodeLength = 4;
string strSettleCode = "";
//获取分公司的票号头字符
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'");
string strFeeType = tempBANKSHEAD+"DR";
FeeDoDA feeDoDA = new FeeDoDA();
DateTime nowDateTime = feeDoDA.getServerDateTime();
string strYear = nowDateTime.Year.ToString();
string strMonth = nowDateTime.Month.ToString().Length < 2 ? "0" + nowDateTime.Month.ToString() : nowDateTime.Month.ToString();
//string strDay = nowDateTime.Day.ToString();
string strDateTime = strYear + strMonth;
string strCodePrefix = strFeeType + strDateTime;
string strSql = "SELECT TOP 1 BILLNO FROM ch_fee_do WHERE BILLNO LIKE '" + strFeeType + strDateTime + "%' ORDER BY BILLNO DESC";
DataTable billTable = feeDoDA.GetExcuteSql(strSql).Tables[0];
ArrayList codeArg = new ArrayList();
for (int i = 0; i < CodeLength; i++)
{
codeArg.Add(0);
}
string strCode = "";//编号
if (billTable.Rows.Count > 0)
{
string oldCode = billTable.Rows[0][0].ToString();
if (oldCode.IndexOf(strCodePrefix) >= 0)
{
oldCode = oldCode.Substring(strCodePrefix.Length, oldCode.Length - strCodePrefix.Length);
if (oldCode.Length == CodeLength)
{
for (int i = 0; i < oldCode.Length; i++)
{
if (oldCode[i].ToString().IndexOf("0") == 0)
{
oldCode = oldCode.Remove(i, 1);
i = -1;
continue;
}
else
{
break;
}
}
}
}
int newNum = int.Parse(oldCode);
newNum = newNum + 1;
string strNewNum = newNum.ToString();
int codeArgCount = codeArg.Count - 1;
for (int i = strNewNum.Length - 1; i >= 0; i--)
{
codeArg[codeArgCount] = strNewNum[i];
codeArgCount--;
}
//for (int i = 0; i < strNewNum.Length; i++)
//{
// codeArg[i] = strNewNum[i];
//}
}
else
{
int iOld = int.Parse(codeArg[codeArg.Count - 1].ToString());
codeArg[codeArg.Count - 1] = (iOld + 1).ToString();
}
for (int i = 0; i < codeArg.Count; i++)
{
strCode += codeArg[i].ToString();
}
strSettleCode = strFeeType + strDateTime + strCode;
return strSettleCode;
}
public string UnicodeToGB(string text)
{
MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
if (mc != null && mc.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (Match m2 in mc)
{
string v = m2.Value;
if (v.IndexOf("\\") >= 0)
{
string word = v.Substring(2);
byte[] codes = new byte[2];
int code = Convert.ToInt32(word.Substring(0, 2), 16);
int code2 = Convert.ToInt32(word.Substring(2), 16);
codes[0] = (byte)code2;
codes[1] = (byte)code;
sb.Append(Encoding.Unicode.GetString(codes));
}
else
{
sb.Append(v);
}
}
return sb.ToString();
}
else
{
return text;
}
}
}
}