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/Invoice/InvoiceApplicationModify.as...

1390 lines
67 KiB
C#

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 System.Collections.Generic;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Xml;
namespace DSWeb.Invoice
{
public partial class InvoiceApplicationModify : System.Web.UI.Page
{
private string strShowName;
private string strUserID;
private string strCacheName;
private string strSettleCurrency;
private decimal usdToRmb;
private decimal rmbToUsd;
private string strRename;//自定义名称
private int isShowDetail;//是否显示明细数据 值1-显示 值0-不显示
//private int iAction;//值1-提交申请 值2-保存申请 值3-打印申请 值4-删除申请 值5-添加申请
private int isCustNo;//是否显示委托编号
private int isVessel;//是否显示船名航次
private int isMblno;//是否显示提单号
private int isEtd;//是否显示开船日期
private int isPol;//是否显示起运港
private int isPod;//是否显示卸货港
private string strCompanyID;//分公司GID
private string strDeptName;//部门名称
private string stroplb;//业务类别
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["postsession"] != null)
{
strCacheName = Request.QueryString["postsession"].ToString();
h_cachename.Value = strCacheName;
this.txt_type.Value = "申请发票";
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
#region ####
//if (this.h_action.Value.Trim().Equals(""))
//{
// if (strFeeCache != null)
// {
// //if (strFeeCache.Trim().ToLower().Equals("ivappsession"))
// //{
// // if (Session[strFeeCache.Trim().ToLower()] != null)
// // {
// // strFeeCache = Session[strFeeCache.Trim().ToLower()].ToString();
// // Session.Remove(strFeeCache.Trim().ToLower());
// // h_feecache.Value = strFeeCache;
// // }
// //}
// if (Session[strFeeCache.Trim()] != null)
// {
// strFeeCache = Session[strFeeCache.Trim()].ToString();
// Session.Remove(strFeeCache.Trim());
// h_feecache.Value = strFeeCache;
// }
// }
//}
#endregion
if (Request.QueryString["currency"] != null)
{
strSettleCurrency = Request.QueryString["currency"].ToString();
int iCurrencyType = int.Parse(strSettleCurrency);
this.h_currency.Value = iCurrencyType.ToString();
switch (iCurrencyType)
{
case 1:
this.txt_currency.Value = "RMB";
break;
case 2:
this.txt_currency.Value = "USD";
break;
}
h_settlecurrency.Value = strSettleCurrency;
}
if (Request.QueryString["uex"] != null)
{
rmbToUsd = decimal.Parse(Request.QueryString["uex"].ToString());
h_rmbtousd.Value = rmbToUsd.ToString();
}
if (Request.QueryString["rex"] != null)
{
usdToRmb = decimal.Parse(Request.QueryString["rex"].ToString());
h_usdtormb.Value = usdToRmb.ToString();
}
if (Request.QueryString["cno"] != null)
{
isCustNo = int.Parse(Request.QueryString["cno"].ToString());
this.h_iscustno.Value = isCustNo.ToString();
}
if (Request.QueryString["vel"] != null)
{
isVessel = int.Parse(Request.QueryString["vel"].ToString());
this.h_isvessel.Value = isVessel.ToString();
}
if (Request.QueryString["mbl"] != null)
{
isMblno = int.Parse(Request.QueryString["mbl"].ToString());
this.h_ismblno.Value = isMblno.ToString();
}
if (Request.QueryString["etd"] != null)
{
isEtd = int.Parse(Request.QueryString["etd"].ToString());
this.h_isetd.Value = isEtd.ToString();
}
if (Request.QueryString["pol"] != null)
{
isPol = int.Parse(Request.QueryString["pol"].ToString());
this.h_ispol.Value = isPol.ToString();
}
if (Request.QueryString["pod"] != null)
{
isPod = int.Parse(Request.QueryString["pod"].ToString());
this.h_ispod.Value = isPod.ToString();
}
if (Request.QueryString["oplb"] != null)
{
stroplb = UnicodeToGB(Request.QueryString["oplb"].ToString());
}
if (Request.QueryString["rn"] != null)
{
strRename = UnicodeToGB(Request.QueryString["rn"].ToString());
this.h_rename.Value = strRename;
}
if (Request.QueryString["detail"] != null)
{
isShowDetail = int.Parse(Request.QueryString["detail"].ToString());
h_isdetail.Value = isShowDetail.ToString();
}
if (ViewState["enter"] == null)
{
ResovlePostSessionTable(strCacheName);
ViewState["enter"] = "0";//已经完成初始化
}
if (h_enter.Value.Trim() == "1")
{
PostInvoiceApplication(strCacheName);
}
else if (h_enter.Value.Trim() == "2")
{
}
//if (!this.h_action.Value.Trim().Equals(""))
//{
// iAction = int.Parse(this.h_action.Value.Trim());
// switch (iAction)
// {
// case 1:
// //PostApplication();
// break;
// case 2:
// //SaveApplication();
// break;
// case 3:
// break;
// case 4:
// break;
// }
//}
}
#region 获取缓存付费结算合计信息
/// <summary>
/// 获取缓存付费结算合计信息
/// </summary>
/// <param name="tempPostSessionName">缓存名称</param>
private void ResovlePostSessionTable(string tempPostSessionName)
{
DataTable bsnoTable = null;
DataTable feeTable = null;
DataTable totalTable = null;
DataSet postSet = null;
if (Session[tempPostSessionName] != null)
{
postSet = (DataSet)Session[tempPostSessionName];
}
bsnoTable = (DataTable)postSet.Tables[0];
feeTable = (DataTable)postSet.Tables[1];
totalTable = (DataTable)postSet.Tables[2];
int i = 0;
while (i < 1)
{
string strBSNO = bsnoTable.Rows[i]["BSNO"].ToString();
InvoiceDA invoiceDA = new InvoiceDA();
DataTable sourceTable;
string strSql="";
//if (stroplb == "op_Seae")
//{
// strSql = "SELECT BSNO,VESSEL+' '+VOYNO as VESSELVOYAGE,MBLNO,CASE WHEN ETD IS NULL THEN '' ELSE ETD END AS ETD,PORTLOAD,PORTDISCHARGE,CUSTNO FROM op_seae WHERE BSNO = '" + strBSNO + "'";
//}
//else if (stroplb == "op_Seai")
//{
// strSql = "SELECT BSNO,VESSEL+' '+VOYNO as VESSELVOYAGE,MBLNO,CASE WHEN ETD IS NULL THEN '' ELSE ETD END AS ETD,PORTLOAD,PORTDISCHARGE,CUSTNO FROM op_seai WHERE BSNO = '" + strBSNO + "'";
//}
//2013-02-05 修改 begin
string sOPLBCondition = "";
switch (stroplb.ToLower())
{
case "op_seae"://海运出口op_Seae
sOPLBCondition = " and OPLBNAME='海运出口' ";
break;
case "op_seai"://海运进口op_Seai
sOPLBCondition = " and OPLBNAME='海运进口' ";
break;
//case 3:
// sOPLBCondition = " and OPLBNAME='空运出口' ";
// break;
//case 4:
// sOPLBCondition = " and OPLBNAME='空运进口' ";
// break;
case "tmswlbshead"://陆运托运
sOPLBCondition = " and OPLBNAME='陆运托运' ";
break;
case "wms_fee"://仓储费
sOPLBCondition = " and OPLBNAME='仓储费' ";
break;
case "wms"://仓储入库
sOPLBCondition = " and OPLBNAME='仓储入库' ";
break;
case "wms_out"://仓储出库
sOPLBCondition = " and OPLBNAME='仓储出库' ";
break;
case "tmswlpchead"://陆运派车
sOPLBCondition = " and OPLBNAME='陆运派车' ";
break;
default:
break;
}
strSql = "SELECT BSNO,VESSEL+' '+VOYNO as VESSELVOYAGE,MBLNO,CASE WHEN ETD IS NULL THEN '' ELSE ETD END AS ETD,PORTLOAD,PORTDISCHARGE,CUSTNO FROM VW_Settlement WHERE BSNO = '" + strBSNO + "'" + sOPLBCondition;
//End
sourceTable = invoiceDA.GetExcuteSql(strSql).Tables[0];
if (isCustNo == 1) this.txt_custno.Value = sourceTable.Rows[0]["CUSTNO"].ToString();
if (isVessel == 1) this.txt_vesselvoyage.Value = sourceTable.Rows[0]["VESSELVOYAGE"].ToString();
if (isMblno == 1) this.txt_mblno.Value = sourceTable.Rows[0]["MBLNO"].ToString();
if (isEtd == 1) this.txt_etd.Value = (sourceTable.Rows[0]["ETD"].ToString() == "1900-1-1 0:00:00") ? "" : sourceTable.Rows[0]["ETD"].ToString();
if (isPol == 1) this.txt_pol.Value = sourceTable.Rows[0]["PORTLOAD"].ToString();
if (isPod == 1) this.txt_pod.Value = sourceTable.Rows[0]["PORTDISCHARGE"].ToString();
i++;
}
h_customername.Value = feeTable.Rows[0]["CUSTOMERNAME"].ToString();
#region ####
//StringBuilder totalBuilder = new StringBuilder();
//totalBuilder.Append("{");
//totalBuilder.Append("\"invoice\":");
//totalBuilder.Append("[");
//totalBuilder.Append("{");
//decimal totalRmb = decimal.Parse(totalTable.Rows[0]["TOTALRMB"].ToString());
//decimal totalUsd = decimal.Parse(totalTable.Rows[0]["TOTALUSD"].ToString());
//decimal FinalRmd = 0;
//decimal FinalUsd = 0;
//if (strSettleCurrency == "1")
//{
// //人民币结算
// FinalRmd = (StatisticSettleAmount(totalUsd, usdToRmb) + totalRmb);
//}
//else if (strSettleCurrency == "2")
//{
// //美元结算
// FinalUsd = (StatisticSettleAmount(totalRmb, rmbToUsd) + totalUsd);
//}
//else if (strSettleCurrency == "3")
//{
// FinalRmd = totalRmb;
// FinalUsd = totalUsd;
//}
//totalBuilder.Append("\"recvrmb\":" + totalTable.Rows[0]["RECVRMB"].ToString() + ",");
//totalBuilder.Append("\"recvusd\":" + totalTable.Rows[0]["RECVUSD"].ToString() + ",");
//totalBuilder.Append("\"payrmb\":" + totalTable.Rows[0]["PAYRMB"].ToString() + ",");
//totalBuilder.Append("\"payusd\":" + totalTable.Rows[0]["PAYUSD"].ToString() + ",");
//totalBuilder.Append("\"totalrmb\":" + FinalRmd.ToString() + ",");
//totalBuilder.Append("\"totalusd\":" + FinalUsd.ToString() + "");
//totalBuilder.Append("}");
//totalBuilder.Append("]");
//totalBuilder.Append("}");
//h_total.Value = totalBuilder.ToString();
#endregion
}
#endregion
#region ####
//#region 保存开票申请
///// <summary>
///// 保存开票申请
///// </summary>
//private void SaveApplication()
//{
// int iResult = 0;
// InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
// InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
// //生成业务申请编号
// string strBillNO = CreateBillNO();
// IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
// if (!this.h_feecache.Value.Trim().Equals(""))
// {
// string strList = this.h_feecache.Value.Trim();
// string strFilter = "";
// #region
// if (strList.IndexOf("[") >= 0 && strList.IndexOf("]") > 0)
// {
// strFilter = strList.Substring(strList.IndexOf("[") + 1, strList.IndexOf("]") - strList.IndexOf("[") - 1);
// string[] strFees = strFilter.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().Equals("") ? "0" : strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "cur":
// feeDoEntity.Currency = strArg[1].ToString().Replace("\"", "").Trim().ToUpper();
// 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":
// feeDoEntity.Orig = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "oname":
// feeDoEntity.OriginalFeeName = strArg[1].ToString().Replace("\"", "").Trim();
// break;
// case "ocstl":
// feeDoEntity.OriginalFeeCSTL = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// default:
// break;
// }
// }
// if (strSettleCurrency != feeDoEntity.Currency)
// {
// if (strSettleCurrency == "RMB")
// {
// feeDoEntity.ExchangeRate = usdToRmb;
// }
// else if (strSettleCurrency == "USD")
// {
// feeDoEntity.ExchangeRate = rmbToUsd;
// }
// }
// //feeDoEntity.BSNO = "";
// feeDoEntity.MBLNO = "";
// feeDoEntity.HBLNO = "";
// //feeDoEntity.CustomerName = "";
// //feeDoEntity.FeeName = "";
// feeDoEntity.BillNO = strBillNO;
// feeDoEntity.GID = Guid.NewGuid().ToString();
// feeDoEntity.Category = 6;
// feeDoEntity.BSType = 1;
// feeDoEntity.BillStatus = 2;
// feeDoEntity.Remark = "";
// feeDoEntities.Add(feeDoEntity);
// }
// }
// }
// }
// #endregion
// invoiceApplicationEntity.GID = Guid.NewGuid().ToString();
// invoiceApplicationEntity.InvoiceNO = this.txt_invoiceno.Value.Trim();
// invoiceApplicationEntity.BillStatus = 1;//未提交
// invoiceApplicationEntity.Currency = this.txt_currency.Value.Trim().ToUpper();
// invoiceApplicationEntity.InvoiceCustomer = this.h_payable.Value.Trim();
// invoiceApplicationEntity.CustomerName = this.h_customer.Value.Trim(); ;
// invoiceApplicationEntity.FeeItem = CreateFeeDoXml(feeDoEntities).OuterXml;
// invoiceApplicationEntity.AmountList = "";
// invoiceApplicationEntity.BillNO = strBillNO;
// invoiceApplicationEntity.BSNO = this.h_mblno.Value.Trim();//this.txt_mblno.Value.Trim();
// invoiceApplicationEntity.Applicant = strUserID;
// invoiceApplicationEntity.Remark = this.txt_remark.Value.Trim();
// invoiceApplicationEntity.AmountCapital = this.txt_amountcapital.Value.Trim();
// invoiceApplicationEntity.VesselVoyage = this.h_vesselvoyage.Value.Trim();//this.txt_vesselvoyage.Value.Trim();
// string[] strApplyAmount = this.txt_total.Value.Trim().Split(new char[] { ' ' });
// invoiceApplicationEntity.ApplyAmount = decimal.Parse(strApplyAmount[1]);
// invoiceApplicationEntity.MBLNO = this.h_mblno.Value.Trim();//this.txt_mblno.Value.Trim();
// invoiceApplicationEntity.ETD = this.h_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.h_etd.Value.Trim());//this.txt_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.txt_etd.Value.Trim());
// invoiceApplicationEntity.POL = this.h_pol.Value.Trim();//this.txt_pol.Value.Trim();
// invoiceApplicationEntity.POD = this.h_pod.Value.Trim();//this.txt_pod.Value.Trim();
// invoiceApplicationEntity.Applicant = this.strUserID;
// invoiceApplicationEntity.IsApply = false;
// //插入数据
// iResult = invoiceApplicationDA.InsertInvoiceApplicationNoApply(invoiceApplicationEntity, feeDoEntities);
// if (iResult > 0)
// {
// IList<UserAuthorityRangeEntity> userAuthorityRangeEntities = new List<UserAuthorityRangeEntity>();
// UserAuthorityDA userAuthorityDA = new UserAuthorityDA();
// userAuthorityRangeEntities = userAuthorityDA.GetAuthorityUsersByNameAndRange("modInvoiceManagement", 2);
// IList<MessageEntity> messageEntities = new List<MessageEntity>();
// MessageDA messageDA = new MessageDA();
// if (userAuthorityRangeEntities.Count > 0)
// {
// foreach (UserAuthorityRangeEntity userAuthorityRangeEntity in userAuthorityRangeEntities)
// {
// //插入消息提醒
// MessageEntity messageEntity = new MessageEntity();
// messageEntity.GID = Guid.NewGuid().ToString();
// messageEntity.Name = "InvoiceApplicationNotice";
// messageEntity.Description = "发票申请通知";
// messageEntity.IsRead = false;
// messageEntity.ReadCount = 0;
// messageEntity.MessageContent = strShowName + " 提交 [发票申请] 请及时处理 ";
// messageEntity.TaskID = "";
// messageEntity.Receiver = userAuthorityRangeEntity.UserID;
// messageEntity.TaskUrl = "invoice/invoicemakeout.aspx";
// messageEntity.Type = messageDA.GetMessageType(MessageType.INVOICE);
// messageEntity.RecvType = 2;//申请审核类型
// messageEntities.Add(messageEntity);
// }
// }
// if (messageEntities.Count > 0)
// {
// messageDA.CreateMessage(MessageType.INVOICE, messageEntities);
// }
// //this.btn_save.Disabled = true;//保存按钮不可选
// this.h_billno.Value = strBillNO;
// //this.txt_invoiceno.Disabled = true;//状态变为只读
// this.h_posted.Value = "1";//标识当前发票申请是否已提交
// Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>javascript:alert('发票申请保存成功');</script>");
// }
// }
//}
//#endregion
#endregion
#region 保存未提交发票申请
/// <summary>
/// 保存未提交发票申请
/// </summary>
/// <param name="tempPostSessionName">缓存名称</param>
private void SaveInvoiceApplication(string tempPostSessionName)
{
int billtype = 0;//1收费2付费
DataTable bsnoTable = null;
DataTable feeTable = null;
DataTable totalTable = null;
DataSet postSet = null;
if (Session[tempPostSessionName] != null)
{
postSet = (DataSet)Session[tempPostSessionName];
}
bsnoTable = (DataTable)postSet.Tables[0];
feeTable = (DataTable)postSet.Tables[1];
totalTable = (DataTable)postSet.Tables[2];
RunFeeDoDA runFeeDoDA = new RunFeeDoDA();
if (ViewState["SaveState"] == null)
{
string strCustomerName = "";
string strRunSettleID = Guid.NewGuid().ToString();
//付费申请费用明细信息
IList<RunFeeDoEntity> runFeeDoEntities = new List<RunFeeDoEntity>();
for (int j = 0; j < bsnoTable.Rows.Count; j++)
{
for (int i = 0; i < feeTable.Rows.Count; i++)
{
if (i == 0)
{
strCustomerName = feeTable.Rows[i]["CUSTOMERNAME"].ToString();
}
if (bsnoTable.Rows[j]["BSNO"].ToString().Trim() != feeTable.Rows[i]["BSNO"].ToString().Trim())
{
continue;
}
RunFeeDoEntity runFeeDoEntity = new RunFeeDoEntity();
runFeeDoEntity.FeeID = feeTable.Rows[i]["GID"].ToString();
runFeeDoEntity.FeeType = int.Parse(feeTable.Rows[i]["FEETYPE"].ToString());
billtype = runFeeDoEntity.FeeType;
runFeeDoEntity.Currency = feeTable.Rows[i]["CURRENCY"].ToString();
runFeeDoEntity.Amount = decimal.Parse(feeTable.Rows[i]["AMOUNT"].ToString());
runFeeDoEntity.DoAmount = decimal.Parse(feeTable.Rows[i]["CTL"].ToString());
runFeeDoEntity.UnsettleAmount = decimal.Parse(feeTable.Rows[i]["UCTL"].ToString());
runFeeDoEntity.CustomerName = feeTable.Rows[i]["CUSTOMERNAME"].ToString();
runFeeDoEntity.FeeName = feeTable.Rows[i]["FEENAME"].ToString();
runFeeDoEntity.OriginalFeeName = feeTable.Rows[i]["CUSTOMERNAME"].ToString();
runFeeDoEntity.OriginalFeeCSTL = decimal.Parse(feeTable.Rows[i]["CTL"].ToString());
if (strSettleCurrency == "1")
{
runFeeDoEntity.ExchangeRate = usdToRmb;
}
else if (strSettleCurrency == "2")
{
runFeeDoEntity.ExchangeRate = rmbToUsd;
}
runFeeDoEntity.BSNO = bsnoTable.Rows[j]["BSNO"].ToString();
runFeeDoEntity.MBLNO = bsnoTable.Rows[j]["MBLNO"].ToString();
runFeeDoEntity.HBLNO = bsnoTable.Rows[j]["HBLNO"].ToString();
runFeeDoEntity.GID = Guid.NewGuid().ToString();
runFeeDoEntity.Category = 6;
runFeeDoEntity.BSType = 1;
runFeeDoEntity.BillStatus = 2;
runFeeDoEntity.Remark = "";
runFeeDoEntity.OrigCurrency = "";
runFeeDoEntity.RunSettleID = strRunSettleID;
runFeeDoEntity.InvoiceSettleNO = "";
runFeeDoEntity.CreateUser = strUserID;
runFeeDoEntity.CompanyID = strCompanyID;
runFeeDoEntities.Add(runFeeDoEntity);
}
}
RunFeeSettlementEntity runFeeSettlementEntity = new RunFeeSettlementEntity();
runFeeSettlementEntity.GID = strRunSettleID;
runFeeSettlementEntity.BillType= billtype;//由runFeeDoEntity.FeeType决定
runFeeSettlementEntity.BillStatus = 1;
runFeeSettlementEntity.CreateUser = strUserID;
runFeeSettlementEntity.PayableTime = System.DateTime.MinValue;
runFeeSettlementEntity.CustomerName = strCustomerName;//结算单位
runFeeSettlementEntity.SettleType = 1;//int.Parse(this.sel_settlemode.Value);
runFeeSettlementEntity.Remark = txt_remark.Value.Trim();
runFeeSettlementEntity.BillType = 2;//
runFeeSettlementEntity.Type = 2;//付费结算
runFeeSettlementEntity.VoucherNO = "";//凭证号
runFeeSettlementEntity.FinancialVoucher = "";
runFeeSettlementEntity.CompanyID = strCompanyID;
decimal totalRmb = decimal.Parse(totalTable.Rows[0]["TOTALRMB"].ToString());
decimal totalUsd = decimal.Parse(totalTable.Rows[0]["TOTALUSD"].ToString());
decimal FinalRmd = 0;
decimal FinalUsd = 0;
if (strSettleCurrency == "1")
{
//人民币结算
FinalRmd = (StatisticSettleAmount(totalUsd, usdToRmb) + totalRmb);
//折算汇率
runFeeSettlementEntity.Rate = totalUsd != 0 ? usdToRmb : 1;
}
else if (strSettleCurrency == "2")
{
//美元结算
FinalUsd = (StatisticSettleAmount(totalRmb, rmbToUsd) + totalUsd);
//折算汇率
runFeeSettlementEntity.Rate = totalRmb != 0 ? rmbToUsd : 1;
}
else if (strSettleCurrency == "3")
{
FinalRmd = totalRmb;
FinalUsd = totalUsd;
runFeeSettlementEntity.Rate = 1;
}
runFeeSettlementEntity.AmountRMB = FinalRmd;
runFeeSettlementEntity.AmountUSD = FinalUsd;
runFeeSettlementEntity.AccountRMB = "";
runFeeSettlementEntity.AccountUSD = "";
runFeeSettlementEntity.ChequeNo = "";
runFeeSettlementEntity.ChequeNoUsd = "";
runFeeSettlementEntity.CHEQUENUMREMARK = "";//支票号备注
int iResult = runFeeDoDA.InsertRunSettle(runFeeDoEntities, runFeeSettlementEntity, strUserID, strShowName, "UNPAYSETTLE");
if (iResult == 1)
{
ViewState["enter"] = "1";//已经保存成功
ViewState["SaveState"] = "1";//已经保存成功
ViewState["RunSettleID"] = runFeeSettlementEntity.GID;//保存运行结算表GID
//this.txt_customerName.Value = runFeeSettlementEntity.CustomerName;//结算单位
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('付费结算保存成功');refresh();window.parent.opener.location.href = window.parent.opener.location.href;</script>");
}
else
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('付费结算保存失败');refresh()</script>");
}
}
}
#endregion
#region 提交发票申请
/// <summary>
/// 提交发票申请
/// </summary>
/// <param name="tempPostSessionName">缓存名称</param>
private void PostInvoiceApplication(string tempPostSessionName)
{
DataTable bsnoTable = null;
DataTable feeTable = null;
DataTable totalTable = null;
DataSet postSet = null;
if (Session[tempPostSessionName] != null)
{
postSet = (DataSet)Session[tempPostSessionName];
}
bsnoTable = (DataTable)postSet.Tables[0];
feeTable = (DataTable)postSet.Tables[1];
totalTable = (DataTable)postSet.Tables[2];
string strInvoiceAppGID = Guid.NewGuid().ToString();
string strCustomerName = "";
InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
if (ViewState["RunSettleID"] == null && ViewState["InvoiceAppID"] == null)
{
decimal totalRmb = decimal.Parse(totalTable.Rows[0]["TOTALRMB"].ToString());
decimal totalUsd = decimal.Parse(totalTable.Rows[0]["TOTALUSD"].ToString());
decimal FinalTotal = 0;
if (strSettleCurrency == "1")
{
//人民币结算
FinalTotal = (StatisticSettleAmount(totalUsd, usdToRmb) + totalRmb);
//折算汇率
invoiceApplicationEntity.Rate = totalUsd != 0 ? usdToRmb : 1;
}
else if (strSettleCurrency == "2")
{
//美元结算
FinalTotal = (StatisticSettleAmount(totalRmb, rmbToUsd) + totalUsd);
//折算汇率
invoiceApplicationEntity.Rate = totalRmb != 0 ? rmbToUsd : 1;
}
//付费申请费用明细信息
IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
IList<FeeDoEntity> feeDoEntities2 = new List<FeeDoEntity>();
for (int j = 0; j < bsnoTable.Rows.Count; j++)
{
for (int i = 0; i < feeTable.Rows.Count; i++)
{
if (i == 0)
{
strCustomerName = feeTable.Rows[i]["CUSTOMERNAME"].ToString();
}
if (bsnoTable.Rows[j]["BSNO"].ToString().Trim() != feeTable.Rows[i]["BSNO"].ToString().Trim())
{
continue;
}
FeeDoEntity feeDoEntity = new FeeDoEntity();
feeDoEntity.FeeID = feeTable.Rows[i]["GID"].ToString();
feeDoEntity.FeeType = int.Parse(feeTable.Rows[i]["FEETYPE"].ToString());
feeDoEntity.Currency = feeTable.Rows[i]["CURRENCY"].ToString();
feeDoEntity.Amount = decimal.Parse(feeTable.Rows[i]["AMOUNT"].ToString());
feeDoEntity.DoAmount = decimal.Parse(feeTable.Rows[i]["CTL"].ToString());
feeDoEntity.UnsettleAmount = decimal.Parse(feeTable.Rows[i]["UCTL"].ToString());
feeDoEntity.CustomerName = feeTable.Rows[i]["CUSTOMERNAME"].ToString();
feeDoEntity.FeeName = feeTable.Rows[i]["FEENAME"].ToString();
feeDoEntity.OriginalFeeName = feeTable.Rows[i]["FEENAME"].ToString();
feeDoEntity.OriginalFeeCSTL = decimal.Parse(feeTable.Rows[i]["CTL"].ToString());
feeDoEntity.BSNO = bsnoTable.Rows[j]["BSNO"].ToString();
feeDoEntity.MBLNO = bsnoTable.Rows[j]["MBLNO"].ToString();
feeDoEntity.HBLNO = bsnoTable.Rows[j]["HBLNO"].ToString();
feeDoEntity.BillNO = "";
feeDoEntity.GID = Guid.NewGuid().ToString();
feeDoEntity.Category = 6;
feeDoEntity.BSType = 1;
feeDoEntity.BillStatus = 2;
feeDoEntity.Remark = "";
feeDoEntity.Orig = 1;
feeDoEntity.OrigCurrency = feeTable.Rows[i]["CURRENCY"].ToString();
if (feeDoEntity.Currency == "USD")
{
feeDoEntity.ExchangeRate = usdToRmb;
}
else if (feeDoEntity.Currency == "RMB")
{
feeDoEntity.ExchangeRate = rmbToUsd;
}
else
{
feeDoEntity.ExchangeRate = 1;
}
feeDoEntity.CompanyID = strCompanyID;
feeDoEntities.Add(feeDoEntity);
feeDoEntities2.Add(feeDoEntity);
}
}
//
if (h_rename.Value.Trim() != "")
{
FeeDoEntity feeDoEntity = new FeeDoEntity();
feeDoEntity.FeeID = Guid.NewGuid().ToString();
feeDoEntity.FeeType = 1;
feeDoEntity.Currency = strSettleCurrency == "1" ? "RMB" : "USD";
string[] strMakeAmount = this.h_total.Value.Trim().Split(new char[] { ' ' });
feeDoEntity.Amount = decimal.Parse(strMakeAmount[1]);
feeDoEntity.DoAmount = decimal.Parse(strMakeAmount[1]);
feeDoEntity.UnsettleAmount = 0;
feeDoEntity.CustomerName = feeDoEntities[feeDoEntities.Count - 1].CustomerName;
feeDoEntity.FeeName = strRename;
feeDoEntity.OriginalFeeName = strRename;
feeDoEntity.OriginalFeeCSTL = decimal.Parse(strMakeAmount[1]);
feeDoEntity.BSNO = "";
feeDoEntity.MBLNO = h_mblno.Value.Trim();
feeDoEntity.HBLNO = "";
feeDoEntity.BillNO = "";
feeDoEntity.GID = Guid.NewGuid().ToString();
feeDoEntity.Category = 7;
feeDoEntity.BSType = 1;
feeDoEntity.BillStatus = 2;
feeDoEntity.Remark = "";
feeDoEntity.Orig = 3;
feeDoEntity.OrigCurrency = strSettleCurrency == "1" ? "RMB" : "USD";
if (feeDoEntity.Currency == "USD")
{
feeDoEntity.ExchangeRate = usdToRmb;
}
else if (feeDoEntity.Currency == "RMB")
{
feeDoEntity.ExchangeRate = rmbToUsd;
}
else
{
feeDoEntity.ExchangeRate = 1;
}
feeDoEntity.CompanyID = strCompanyID;
feeDoEntities2.Clear();
feeDoEntities2.Add(feeDoEntity);
}
invoiceApplicationEntity.GID = strInvoiceAppGID;
invoiceApplicationEntity.InvoiceNO = this.txt_invoiceno.Value.Trim();
invoiceApplicationEntity.BillStatus = 2;//未提交
invoiceApplicationEntity.Currency = this.txt_currency.Value.Trim().ToUpper();
invoiceApplicationEntity.InvoiceCustomer = this.h_payable.Value.Trim();
invoiceApplicationEntity.CustomerName = strCustomerName;
invoiceApplicationEntity.FeeItem = CreateFeeDoXml(feeDoEntities2).OuterXml;//feeDoEntities
invoiceApplicationEntity.AmountList = "";
invoiceApplicationEntity.BillNO = "";
invoiceApplicationEntity.BSNO = this.h_custno.Value.Trim();//this.txt_mblno.Value.Trim();
invoiceApplicationEntity.Applicant = strUserID;
invoiceApplicationEntity.Remark = this.txt_remark.Value.Trim();
invoiceApplicationEntity.AmountCapital = this.h_capitial.Value.Trim();
invoiceApplicationEntity.VesselVoyage = this.h_vesselvoyage.Value.Trim();//this.txt_vesselvoyage.Value.Trim();
string[] strApplyAmount = this.h_total.Value.Trim().Split(new char[] { ' ' });
invoiceApplicationEntity.ApplyAmount = decimal.Parse(strApplyAmount[1]);
invoiceApplicationEntity.MBLNO = this.h_mblno.Value.Trim();//this.txt_mblno.Value.Trim();
invoiceApplicationEntity.ETD = this.h_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.h_etd.Value.Trim());//this.txt_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.txt_etd.Value.Trim());
invoiceApplicationEntity.POL = this.h_pol.Value.Trim();//this.txt_pol.Value.Trim();
invoiceApplicationEntity.POD = this.h_pod.Value.Trim();//this.txt_pod.Value.Trim();
invoiceApplicationEntity.IsApply = true;//提交开票申请
invoiceApplicationEntity.CompanyID = strCompanyID;
int iResult = invoiceApplicationDA.InsertInvoiceApplication(invoiceApplicationEntity, feeDoEntities);
if (iResult == 1)
{
ViewState["enter"] = "1";//已经保存成功
ViewState["SaveState"] = "1";//已经保存成功
ViewState["InvoiceAppID"] = invoiceApplicationEntity.GID;//保存运行结算表GID
this.h_invoiceappid.Value = invoiceApplicationEntity.GID;//保存运行结算表GID
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strNewBillNo = T_ALL_DA.GetStrSQL("BILLNO", "select BILLNO from ch_fee_invoiceapplication where GID='" + invoiceApplicationEntity.GID + "'");
DataTable table = invoiceApplicationDA.GetMessageAuditor(strCompanyID);
IList<MessageEntity> messageEntities = new List<MessageEntity>();
MessageDA messageDA = new MessageDA();
MessageEntity messEntity = new MessageEntity();
if (table.Rows.Count > 0)
{
for (int i = 0; i < table.Rows.Count; i++)
{
string userid = table.Rows[i]["userid"].ToString();
messEntity.GID = Guid.NewGuid().ToString();
messEntity.Name = "InvoiceAppAudit";
messEntity.Description = "发票申请审核";
messEntity.IsRead = false;
messEntity.ReadCount = 0;
messEntity.MessageContent = strShowName + " 提交了"+"发票号为:"+strNewBillNo.ToString()+"的[发票审核] 申请";
messEntity.TaskID = "";
messEntity.TaskUrl = "Invoice/InvoiceMakeOut.aspx";
messEntity.Receiver =userid;
messEntity.Type = messageDA.GetMessageType(MessageType.INVOICEAPP);
messEntity.RecvType = 2;
messageEntities.Add(messEntity);
messageDA.CreateMessage(MessageType.INVOICEAPP, messageEntities);
messageEntities.Clear();
}
}
//this.txt_customerName.Value = runFeeSettlementEntity.CustomerName;//结算单位
this.btn_apply.Disabled = true;
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('发票申请提交成功');refresh();window.parent.opener.location.href = window.parent.opener.location.href;window.close();</script>");
}
else
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('发票申请提交失败');refresh();</script>");
}
}
}
#endregion
#region ####
//#region 提交开票申请
///// <summary>
///// 提交开票申请
///// </summary>
//private void PostApplication()
//{
// int iResult = 0;
// InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
// InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
// if (!this.h_feecache.Value.Trim().Equals(""))
// {
// string strList = this.h_feecache.Value.Trim();
// string strFilter = "";
// string strBillNO = CreateBillNO();
// IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
// #region
// if (strList.IndexOf("[") >= 0 && strList.IndexOf("]") > 0)
// {
// strFilter = strList.Substring(strList.IndexOf("[") + 1, strList.IndexOf("]") - strList.IndexOf("[") - 1);
// //IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
// string[] strFees = strFilter.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().Equals("") ? "0" : 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":
// feeDoEntity.Orig = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "origcur":
// feeDoEntity.OrigCurrency = strArg[1].ToString().Replace("\"", "").Trim().ToUpper();
// break;
// case "ocstl":
// if (!strArg[1].ToString().Replace("\"", "").Trim().Equals(""))
// {
// feeDoEntity.OriginalFeeCSTL = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// }
// break;
// default:
// break;
// }
// }
// if (strSettleCurrency != feeDoEntity.Currency)
// {
// if (strSettleCurrency == "RMB")
// {
// feeDoEntity.ExchangeRate = usdToRmb;
// }
// else if (strSettleCurrency == "USD")
// {
// feeDoEntity.ExchangeRate = rmbToUsd;
// }
// }
// //feeDoEntity.BSNO = "";
// feeDoEntity.MBLNO = "";
// feeDoEntity.HBLNO = "";
// //feeDoEntity.CustomerName = "";
// //feeDoEntity.FeeName = "";
// feeDoEntity.BillNO = strBillNO;
// feeDoEntity.GID = Guid.NewGuid().ToString();
// feeDoEntity.Category = 6;
// feeDoEntity.BSType = 1;
// feeDoEntity.BillStatus = 2;
// feeDoEntity.Remark = "";
// feeDoEntities.Add(feeDoEntity);
// }
// }
// }
// }
// #endregion
// invoiceApplicationEntity.GID = Guid.NewGuid().ToString();
// invoiceApplicationEntity.InvoiceNO = this.txt_invoiceno.Value.Trim();
// invoiceApplicationEntity.BillStatus = 2;//未提交
// invoiceApplicationEntity.Currency = this.txt_currency.Value.Trim().ToUpper();
// invoiceApplicationEntity.InvoiceCustomer = this.h_payable.Value.Trim();
// invoiceApplicationEntity.CustomerName = this.h_customer.Value.Trim();
// invoiceApplicationEntity.FeeItem = CreateFeeDoXml(feeDoEntities).OuterXml;
// invoiceApplicationEntity.AmountList = "";
// invoiceApplicationEntity.BillNO = strBillNO;
// invoiceApplicationEntity.BSNO = this.h_custno.Value.Trim();//this.txt_mblno.Value.Trim();
// invoiceApplicationEntity.Applicant = strUserID;
// invoiceApplicationEntity.Remark = this.txt_remark.Value.Trim();
// invoiceApplicationEntity.AmountCapital = this.h_capitial.Value.Trim();
// invoiceApplicationEntity.VesselVoyage = this.h_vesselvoyage.Value.Trim();//this.txt_vesselvoyage.Value.Trim();
// string[] strApplyAmount = this.h_total.Value.Trim().Split(new char[] { ' ' });
// invoiceApplicationEntity.ApplyAmount = decimal.Parse(strApplyAmount[1]);
// invoiceApplicationEntity.MBLNO = this.h_mblno.Value.Trim();//this.txt_mblno.Value.Trim();
// invoiceApplicationEntity.ETD = this.h_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.h_etd.Value.Trim());//this.txt_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.txt_etd.Value.Trim());
// invoiceApplicationEntity.POL = this.h_pol.Value.Trim();//this.txt_pol.Value.Trim();
// invoiceApplicationEntity.POD = this.h_pod.Value.Trim();//this.txt_pod.Value.Trim();
// invoiceApplicationEntity.IsApply = true;//提交开票申请
// //插入数据
// iResult = invoiceApplicationDA.InsertInvoiceApplication(invoiceApplicationEntity, feeDoEntities);
// if (iResult > 0)
// {
// IList<UserAuthorityRangeEntity> userAuthorityRangeEntities = new List<UserAuthorityRangeEntity>();
// UserAuthorityDA userAuthorityDA = new UserAuthorityDA();
// userAuthorityRangeEntities = userAuthorityDA.GetAuthorityUsersByNameAndRange("modInvoiceManagement", 2);
// IList<MessageEntity> messageEntities = new List<MessageEntity>();
// MessageDA messageDA = new MessageDA();
// if (userAuthorityRangeEntities.Count > 0)
// {
// foreach (UserAuthorityRangeEntity userAuthorityRangeEntity in userAuthorityRangeEntities)
// {
// UserDA userDA = new UserDA();
// CompanyDA companyDA = new CompanyDA();
// CompanyEntity companyEntity = new CompanyEntity();
// //先获取提交销售订舱申请人的分公司、部门信息
// string applyCompanyID = strCompanyID;
// string applyDeptName = userDA.GetUserDepartmentName(strUserID);
// //再获取具有销售订舱审核权限的审核人分公司、部门信息
// companyEntity = companyDA.GetCompanyByUserID(userAuthorityRangeEntity.UserID);
// if (companyEntity != null)
// {
// if (companyEntity.GID != null)
// {
// string auditorCompanyID = companyEntity.GID;
// string auditorDeptName = userDA.GetUserDepartmentName(userAuthorityRangeEntity.UserID);
// if (applyCompanyID == auditorCompanyID)
// {
// //相同分公司下
// if (applyDeptName == auditorDeptName)
// {
// //插入消息提醒
// MessageEntity messageEntity = new MessageEntity();
// messageEntity.GID = Guid.NewGuid().ToString();
// messageEntity.Name = "InvoiceApplicationNotice";
// messageEntity.Description = "发票申请通知";
// messageEntity.IsRead = false;
// messageEntity.ReadCount = 0;
// messageEntity.MessageContent = strShowName + " 提交 [发票申请] 请及时处理 ";
// messageEntity.TaskID = "";
// messageEntity.Receiver = userAuthorityRangeEntity.UserID;
// messageEntity.TaskUrl = "invoice/invoicemakeout.aspx";
// messageEntity.Type = messageDA.GetMessageType(MessageType.INVOICE);
// messageEntity.RecvType = 2;//申请审核类型
// messageEntities.Add(messageEntity);
// }
// }
// }
// }
// }
// }
// if (messageEntities.Count > 0)
// {
// messageDA.CreateMessage(MessageType.INVOICE, messageEntities);
// }
// this.btn_apply.Disabled = true;//提交申请按钮不可选
// //this.btn_save.Disabled = true;//保存按钮不可用
// this.txt_invoiceno.Disabled = true;//状态变为只读
// this.h_billno.Value = strBillNO;
// this.h_posted.Value = "1";//标识当前发票申请是否已提交
// InvoiceApplicationEntity invoiceAppEntity = invoiceApplicationDA.GetInvoiceApplicationByBillNO(strBillNO);
// if (invoiceAppEntity != null)
// {
// if (invoiceAppEntity.GID != null)
// {
// h_applytime.Value = invoiceAppEntity.ApplyTime.ToString("yyyy-MM-dd hh:mm:ss");
// }
// }
// //IList<MessageEntity> messageEntities = new List<MessageEntity>();
// //MessageDA messageDA = new MessageDA();
// //MessageEntity messageEntity = new MessageEntity();
// //messageEntity.GID = Guid.NewGuid().ToString();
// //messageEntity.Name = "FeePayAudit";
// //messageEntity.Description = "付费申请审核";
// //messageEntity.IsRead = false;
// //messageEntity.ReadCount = 0;
// //messageEntity.MessageContent = strShowName + " 批准 [付费申请] 业务编号:" + strBillNO + " 审核通过 ";
// //messageEntity.TaskID = strBillNO;
// //messageEntity.Receiver = feePayApplicationEntity.Applicant;
// //messageEntity.TaskUrl = messageEntity.TaskUrl = "settlements/paysettleapplication.aspx";
// //messageEntity.Type = messageDA.GetMessageType(MessageType.FEEPAYAPP);
// //messageEntities.Add(messageEntity);
// //if (messageEntities.Count > 0)
// //{
// // messageDA.CreateMessage(MessageType.FEEPAYAPP, messageEntities);
// //}
// //Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>javascript:alert('发票申请提交成功');</script>");
// }
// }
//}
//#endregion
#endregion
/// <summary>
/// 生成开票申请编号
/// </summary>
/// <returns></returns>
private string CreateBillNO()
{
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+"IV";
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 "
+ " (SELECT BILLNO FROM ch_fee_invoice WHERE BILLNO LIKE '" + strFeeType + strDateTime + "%' UNION "
+ " SELECT BILLNO FROM ch_fee_invoiceapplication WHERE BILLNO LIKE '" + strFeeType + strDateTime + "%') as A 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;
}
#region Unicode-GB Code转换
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB(string text)
{
UnicodeEncoding unicode = new UnicodeEncoding();
text = unicode.GetString(unicode.GetBytes(Regex.Unescape(text.Trim())));
return text;
}
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB_Old(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;
}
}
#endregion
#region 不同币别金额换算
/// <summary>
/// 不同币别金额换算
/// </summary>
/// <param name="tempOrigAmount">原币别金额</param>
/// <param name="tempRate">汇率</param>
/// <returns>返回折算后的金额</returns>
private decimal StatisticSettleAmount(decimal tempOrigAmount, decimal tempRate)
{
decimal result = 0;
result = decimal.Parse(C1Round((double.Parse((tempOrigAmount * tempRate).ToString())), 2).ToString());
return result;
}
#endregion
#region 金额四舍五入
/// <summary>
/// 金额四舍五入
/// </summary>
/// <param name="value">金额值</param>
/// <param name="digit">小数点后位数</param>
/// <returns>返回Double型四舍五入金额</returns>
public double C1Round(double value, int digit)
{
double vt = Math.Pow(10, digit);
double vx = value * vt;
vx += 0.5;
return (Math.Floor(vx) / vt);
}
#endregion
private XmlDocument CreateFeeDoXml(IList<FeeDoEntity> tempFeeDoEntities)
{
XmlDocument xmlDoc = new XmlDocument();
XmlElement root = xmlDoc.CreateElement("fees");
//xmlDoc.AppendChild(root);
XmlElement xItems = xmlDoc.CreateElement("it");
foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
{
XmlElement xDo = xmlDoc.CreateElement("do");
XmlElement xGid = xmlDoc.CreateElement("g");
xGid.InnerText = feeDoEntity.FeeID;
xDo.AppendChild(xGid);
XmlElement xFeeName = xmlDoc.CreateElement("n");
xFeeName.InnerText = feeDoEntity.FeeName;
xDo.AppendChild(xFeeName);
XmlElement xPrice = xmlDoc.CreateElement("p");
xPrice.InnerText = feeDoEntity.DoAmount.ToString();
xDo.AppendChild(xPrice);
XmlElement xCategory = xmlDoc.CreateElement("c");//type值1表示应收费用
xCategory.InnerText = feeDoEntity.Category.ToString();
xDo.AppendChild(xCategory);
XmlElement xType = xmlDoc.CreateElement("t");//type值1表示应收费用
xType.InnerText = feeDoEntity.FeeType.ToString();
xDo.AppendChild(xType);
XmlElement xOrig = xmlDoc.CreateElement("o");//值1-原值 值2-手动添加费用 值3-自定义费用
xOrig.InnerText = feeDoEntity.Orig.ToString();
xDo.AppendChild(xOrig);
xItems.AppendChild(xDo);
}
root.AppendChild(xItems);
xmlDoc.AppendChild(root);
return xmlDoc;
}
}
}