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.
DS7HYRD/DSWeb/Invoice/InvoiceMakeOutModify.aspx.cs

1926 lines
101 KiB
C#

9 months ago
using System;
using System.Collections;
using System.Collections.Generic;
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.Text.RegularExpressions;
using System.Globalization;
using System.Xml;
namespace DSWeb.Invoice
{
public partial class InvoiceMakeOutModify : System.Web.UI.Page
{
#region 私有信息
private string strHandle;
private string strInvoiceAppGID;//开票申请GID
private string strUserID;//用户GID
private string strCacheName;
private decimal usdToRmb;
private decimal rmbToUsd;
private string strSettleCurrency;
private string strRename;//自定义名称
private int isShowDetail;//是否显示明细数据 值1-显示 值0-不显示
private string strOldBillNO;//原始申请业务编号
private int isCustNo;//是否显示委托编号
private int isVessel;//是否显示船名航次
private int isMblno;//是否显示提单号
private int isEtd;//是否显示开船日期
private int isPol;//是否显示起运港
private int isPod;//是否显示卸货港
private string strShowName;
private string strCompanyID;//公司GID
private string strDeptName;//部门名称
#endregion
protected void Page_Load(object sender, EventArgs e)
{
#region 获取Session信息
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();
}
#endregion
#region 获取Request信息
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString().ToLower().Trim();
this.h_handle.Value = strHandle;
}
if (Request.QueryString["id"] != null)
{
strInvoiceAppGID = Request.QueryString["id"].ToString();
this.h_invoiceappid.Value = strInvoiceAppGID;
}
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.h_settlecurrency.Value = "RMB";
break;
case 2:
this.h_settlecurrency.Value = "USD";
break;
}
h_settlecurrency.Value = h_settlecurrency.Value;
}
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["rn"] != null)
{
strRename = UnicodeToGB(Request.QueryString["rn"].ToString());
this.h_rename.Value = strRename.Trim();
}
if (Request.QueryString["detail"] != null)
{
isShowDetail = int.Parse(Request.QueryString["detail"].ToString());
h_isdetail.Value = isShowDetail.ToString();
}
if (Request.QueryString["postsession"] != null)
{
strCacheName = Request.QueryString["postsession"].ToString();
h_cachename.Value = strCacheName;
}
//
if (!IsPostBack)
{
if (strHandle == "directmake" && ViewState["enter"] == null)
{
InitBookItems();//初始发票号
InitMakeOutTime();//初始开票时间
this.txt_type.Value = "自由开票";
}
else if (strHandle == "import" && ViewState["enter"] == null)
{
InitBookItems();//初始发票号
InitMakeOutTime();//初始开票时间
ResovlePostSessionTable(strCacheName);
this.txt_type.Value = "自由开票";
}
else if (strHandle == "makeout" && ViewState["enter"] == null)
{
InitBookItems();//初始发票号
InitMakeOutTime();//初始开票时间
this.txt_type.Value = "申请发票";
if (strInvoiceAppGID != null)
{
InitInvoiceApplicationInfo(strInvoiceAppGID);
}
}
}
#endregion
if (h_enter.Value.Trim() == "1" && ViewState["enter"] == null && strHandle == "import" && strCacheName != null)
{
MakeOutImportFeeInvoice(strCacheName);
}
else if (h_enter.Value.Trim() == "2" && ViewState["enter"] == null && strHandle == "makeout" && strInvoiceAppGID != null)
{
MakeOutInvoiceApplication(strInvoiceAppGID);//开出申请发票
}
else if (h_enter.Value.Trim() == "3" && ViewState["enter"] == null && strHandle == "directmake" && h_cachename.Value.Trim() != "")
{
MakeOutDirectInvoice(h_cachename.Value.Trim());
}
#region ####
//#region
//if (strHandle != null)
//{
// if (strHandle == "makeout" && strInvoiceAppGID != null)
// {
// #region 如果是发票申请开票将费用信息解析到web页面内
// if (this.h_saved.Value.Trim() == "")
// {
// //先获取开票申请信息
// InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
// InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
// invoiceApplicationEntity = invoiceApplicationDA.GetInvoiceApplicationByGID(strInvoiceAppGID);
// if (invoiceApplicationEntity.GID != null)
// {
// strOldBillNO = invoiceApplicationEntity.BillNO;
// this.h_billno.Value = invoiceApplicationEntity.BillNO;
// this.h_settlecurrency.Value = invoiceApplicationEntity.Currency;
// if (!invoiceApplicationEntity.Currency.Trim().Equals(""))
// {
// this.h_currency.Value = (invoiceApplicationEntity.Currency.Trim().ToUpper().Equals("RMB") ? 1 : 2).ToString();
// }
// this.txt_type.Value = "申请发票";
// //this.txt_paycustomer.Value = invoiceApplicationEntity.InvoiceCustomer;
// this.txt_mblno.Value = invoiceApplicationEntity.MBLNO == null ? "" : invoiceApplicationEntity.MBLNO;
// this.txt_etd.Value = invoiceApplicationEntity.ETD == DateTime.MinValue ? "" : invoiceApplicationEntity.ETD.ToString("yyyy-MM-dd hh:mm:ss");
// this.txt_pod.Value = invoiceApplicationEntity.POD == null ? "" : invoiceApplicationEntity.POD;
// this.txt_pol.Value = invoiceApplicationEntity.POL == null ? "" : invoiceApplicationEntity.POL;
// this.txt_custno.Value = invoiceApplicationEntity.BSNO == null ? "" : invoiceApplicationEntity.BSNO;
// this.txt_mblno.Value = invoiceApplicationEntity.MBLNO == null ? "" : invoiceApplicationEntity.MBLNO;
// this.txt_vesselvoyage.Value = invoiceApplicationEntity.VesselVoyage == null ? "" : invoiceApplicationEntity.VesselVoyage;
// //this.h_payable.Value = invoiceApplicationEntity.InvoiceCustomer == null ? "" : invoiceApplicationEntity.InvoiceCustomer.Trim();
// this.h_customer.Value = invoiceApplicationEntity.InvoiceCustomer == null ? "" : invoiceApplicationEntity.InvoiceCustomer.Trim();
// this.txt_amountcapital.Value = invoiceApplicationEntity.AmountCapital;
// this.h_capitial.Value = invoiceApplicationEntity.AmountCapital;
// this.txt_total.Value = invoiceApplicationEntity.Currency.Trim().ToUpper() + " " + invoiceApplicationEntity.ApplyAmount.ToString();
// this.txt_remark.Value = invoiceApplicationEntity.Remark;
// if (invoiceApplicationEntity.InvoiceNO != null)
// {
// this.txt_invoiceno.Value = invoiceApplicationEntity.InvoiceNO.Trim();
// }
// else
// {
// this.txt_invoiceno.Value = "";
// }
// //获取ch_fee_do表根据BILLNO获取所有费用信息详细信息
// FeeDoDA feeDoDA = new FeeDoDA();
// IList<FeeDoEntity> origFeeDoEntities = new List<FeeDoEntity>();
// IList<FeeDoEntity> applicationFeeDoEntities = new List<FeeDoEntity>();
// origFeeDoEntities = feeDoDA.GetFeeDoByBillNO(invoiceApplicationEntity.BillNO);
// string strFeeItem = invoiceApplicationEntity.FeeItem;
// if (!strFeeItem.Trim().Equals(""))
// {
// applicationFeeDoEntities = GetFeeDoXml(strFeeItem);
// }
// foreach (FeeDoEntity appFeeDoEntity in applicationFeeDoEntities)
// {
// for (int i = 0; i < origFeeDoEntities.Count; i++)
// {
// if (appFeeDoEntity.FeeID == origFeeDoEntities[i].FeeID)
// {
// appFeeDoEntity.GID = origFeeDoEntities[i].GID;
// appFeeDoEntity.BSNO = origFeeDoEntities[i].BSNO;
// appFeeDoEntity.CustomerName = origFeeDoEntities[i].CustomerName;
// appFeeDoEntity.Currency = origFeeDoEntities[i].Currency;
// }
// }
// }
// if (applicationFeeDoEntities.Count > 0)
// {
// StringBuilder sourceBuilder = new StringBuilder();
// sourceBuilder.Append("{");
// sourceBuilder.Append("caches:[");
// for (int i = 0; i < applicationFeeDoEntities.Count; i++)
// {
// if (i == 0)
// {
// sourceBuilder.Append("{id:\"" + applicationFeeDoEntities[i].FeeID + "\",");
// }
// else
// {
// sourceBuilder.Append(",{id:\"" + applicationFeeDoEntities[i].FeeID + "\",");
// }
// sourceBuilder.Append("\"type\":\"" + applicationFeeDoEntities[i].FeeType + "\",");
// sourceBuilder.Append("\"bsno\":\"" + applicationFeeDoEntities[i].BSNO + "\",");
// sourceBuilder.Append("\"cus\":\"" + applicationFeeDoEntities[i].CustomerName + "\",");
// sourceBuilder.Append("\"fname\":\"" + applicationFeeDoEntities[i].FeeName + "\",");
// sourceBuilder.Append("\"stl\":\"" + applicationFeeDoEntities[i].Amount + "\",");
// string strMakeOutCurrency = "";
// if (applicationFeeDoEntities[i].Orig == 2 || applicationFeeDoEntities[i].Orig == 3)
// {
// strMakeOutCurrency = h_settlecurrency.Value.Trim().ToUpper();
// }
// else
// {
// strMakeOutCurrency = applicationFeeDoEntities[i].Currency.ToUpper();
// }
// sourceBuilder.Append("\"cur\":\"" + strMakeOutCurrency + "\",");
// sourceBuilder.Append("\"cstl\":\"" + applicationFeeDoEntities[i].DoAmount + "\",");
// sourceBuilder.Append("\"orig\":\"" + applicationFeeDoEntities[i].Orig + "\",");
// sourceBuilder.Append("\"origcur\":\"" + applicationFeeDoEntities[i].OrigCurrency + "\",");
// sourceBuilder.Append("\"rate\":" + applicationFeeDoEntities[i].ExchangeRate + "}");
// }
// sourceBuilder.Append("]");
// sourceBuilder.Append("}");
// //缓存费用信息
// this.h_feecache.Value = sourceBuilder.ToString();
// this.btn_delete.Disabled = true;
// this.btn_import.Disabled = true;
// }
// InvoiceBookItemEntity invoiceBookItemEntity = new InvoiceBookItemEntity();
// InvoiceBookDA invoiceBookDA = new InvoiceBookDA();
// invoiceBookItemEntity = invoiceBookDA.GetCurrentBookItem(strCompanyID);
// if (invoiceBookItemEntity != null)
// {
// if (invoiceBookItemEntity.GID != null)
// {
// this.txt_invoiceno.Value = invoiceBookItemEntity.InvoiceNum;
// }
// }
// }
// }
// #endregion
// }
// else if (strHandle == "import")
// {
// this.txt_type.Value = "自由开票";
// this.ck_deleted.Disabled = true;
// this.ck_isfee.Disabled = true;
// this.ck_isprint.Disabled = true;
// }
// else if (strHandle == "directmake")
// {
// this.txt_type.Value = "自由开票";
// }
//}
//#endregion
//if (!this.h_action.Value.Trim().Equals(""))
//{
// int iAction = int.Parse(this.h_action.Value.Trim());
// //h_action值为1表示执行开票操作
// if (iAction == 1 && strHandle == "makeout")
// {
// MakeOutInvoice(strInvoiceAppGID);
// }
// else if (iAction == 1 && strHandle == "import")
// {
// //引入费用信息开票
// MakeOutImportInvoice();
// }
// else if (iAction == 1 && strHandle == "directmake")
// {
// DirectMakeOutInvoice();
// }
//}
#endregion
//加载下拉框 initComboTradingAgency();
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>initComboCustomer();</script>");
}
#region 初始化发票申请信息
/// <summary>
/// 初始化发票申请信息
/// </summary>
/// <param name="tempInvoiceAppGID">发票申请GID</param>
private void InitInvoiceApplicationInfo(string tempInvoiceAppGID)
{
InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
invoiceApplicationEntity = invoiceApplicationDA.GetInvoiceApplicationByGID(strInvoiceAppGID);
if (invoiceApplicationEntity.GID != null)
{
strOldBillNO = invoiceApplicationEntity.BillNO;
this.h_billno.Value = invoiceApplicationEntity.BillNO;
this.h_settlecurrency.Value = invoiceApplicationEntity.Currency;
if (!invoiceApplicationEntity.Currency.Trim().Equals(""))
{
this.h_currency.Value = (invoiceApplicationEntity.Currency.Trim().ToUpper().Equals("RMB") ? 1 : 2).ToString();
}
this.txt_type.Value = "申请发票";
//this.txt_paycustomer.Value = invoiceApplicationEntity.InvoiceCustomer;
this.txt_mblno.Value = invoiceApplicationEntity.MBLNO == null ? "" : invoiceApplicationEntity.MBLNO;
this.txt_etd.Value = (invoiceApplicationEntity.ETD == DateTime.MinValue || invoiceApplicationEntity.ETD.ToString().Trim().IndexOf("1900")>-1) ? "" : invoiceApplicationEntity.ETD.ToString("yyyy-MM-dd hh:mm:ss");
this.txt_pod.Value = invoiceApplicationEntity.POD == null ? "" : invoiceApplicationEntity.POD;
this.txt_pol.Value = invoiceApplicationEntity.POL == null ? "" : invoiceApplicationEntity.POL;
this.txt_custno.Value = invoiceApplicationEntity.BSNO == null ? "" : invoiceApplicationEntity.BSNO;
this.txt_mblno.Value = invoiceApplicationEntity.MBLNO == null ? "" : invoiceApplicationEntity.MBLNO;
this.txt_vesselvoyage.Value = invoiceApplicationEntity.VesselVoyage == null ? "" : invoiceApplicationEntity.VesselVoyage;
//this.h_payable.Value = invoiceApplicationEntity.InvoiceCustomer == null ? "" : invoiceApplicationEntity.InvoiceCustomer.Trim();
this.h_customer.Value = invoiceApplicationEntity.InvoiceCustomer == null ? "" : invoiceApplicationEntity.InvoiceCustomer.Trim();
this.h_customername.Value = invoiceApplicationEntity.CustomerName == null ? "" : invoiceApplicationEntity.CustomerName.Trim();
this.txt_amountcapital.Value = invoiceApplicationEntity.AmountCapital;
this.h_capitial.Value = invoiceApplicationEntity.AmountCapital;
this.txt_total.Value = invoiceApplicationEntity.Currency.Trim().ToUpper() + " " + invoiceApplicationEntity.ApplyAmount.ToString();
this.txt_remark.Value = invoiceApplicationEntity.Remark;
//if (invoiceApplicationEntity.InvoiceNO != null)
//{
// this.txt_invoiceno.Value = invoiceApplicationEntity.InvoiceNO.Trim();
//}
//else
//{
// this.txt_invoiceno.Value = "";
//}
}
}
#endregion
#region 引入费用开出发票
/// <summary>
/// 引入费用开出发票
/// </summary>
/// <param name="tempPostSessionName">缓存名称</param>
private void MakeOutImportFeeInvoice(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 strInvoiceGID = Guid.NewGuid().ToString();
string strCustomerName = "";
InvoiceDA invoiceDA = new InvoiceDA();
InvoiceEntity invoiceEntity = new InvoiceEntity();
if (ViewState["enter"] == 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);
//折算汇率
invoiceEntity.Rate = totalUsd != 0 ? usdToRmb : 1;
}
else if (strSettleCurrency == "2")
{
//美元结算
FinalTotal = (StatisticSettleAmount(totalRmb, rmbToUsd) + totalUsd);
//折算汇率
invoiceEntity.Rate = totalRmb != 0 ? rmbToUsd : 1;
}
//付费申请费用明细信息
IList<FeeDoEntity> feeDoEntities = 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 = 7;
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);
}
}
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.txt_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;
feeDoEntities.Add(feeDoEntity);
}
invoiceEntity.GID = strInvoiceGID;
invoiceEntity.InvoiceNO = this.h_invoiceno.Value.Trim();
invoiceEntity.BillNO = "";
invoiceEntity.CustomerName = strCustomerName;
invoiceEntity.InvoiceCustName = this.h_customer.Value.Trim();
invoiceEntity.Bank = this.h_bank.Value.Trim();
invoiceEntity.Account = this.h_account.Value.Trim();
invoiceEntity.BSNO = this.h_custno.Value.Trim();
invoiceEntity.VesselVoyage = "";
invoiceEntity.ETD = this.h_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.h_etd.Value.Trim());
invoiceEntity.POL = this.h_pol.Value.Trim();
invoiceEntity.POD = this.h_pod.Value.Trim();
invoiceEntity.MBLNO = this.h_mblno.Value.Trim();
invoiceEntity.FeeItem = CreateFeeDoXml(feeDoEntities).OuterXml;
invoiceEntity.AmountList = "";
string[] strApplyAmount = this.txt_total.Value.Trim().Split(new char[] { ' ' });
invoiceEntity.Amount = decimal.Parse(strApplyAmount[1]);//decimal.Parse(this.h_total.Value.Trim());
invoiceEntity.AmountCapital = this.h_capitial.Value.Trim();
invoiceEntity.Currency = this.h_settlecurrency.Value.Trim();
invoiceEntity.Remark = this.txt_remark.Value.Trim();
invoiceEntity.Applicant = strUserID;
invoiceEntity.ApplyTime = DateTime.Parse(this.txt_makeouttime.Value.Trim());
invoiceEntity.InvoiceType = 2;
invoiceEntity.IsDelete = false;
invoiceEntity.IsNeedFee = false;
invoiceEntity.IsNeedPrint = false;
invoiceEntity.Operator = strUserID;
CompanyEntity companyEntity = new CompanyDA().GetCompanyByID(strCompanyID);
invoiceEntity.LicenseCode = companyEntity.LICENSECODE != null ? companyEntity.LICENSECODE : "";
invoiceEntity.TaxCode = companyEntity.TAXCODE != null ? companyEntity.TAXCODE : "";
invoiceEntity.ExchangeRate = this.h_settlecurrency.Value.Trim().Equals("USD") ? (decimal.Parse(h_exusdtormb.Value.Trim().Equals("") ? "1" : h_exusdtormb.Value.Trim())) : (decimal.Parse(h_exrmbtousd.Value.Trim().Equals("") ? "1" : h_exrmbtousd.Value.Trim()));
invoiceEntity.PrintAmount = decimal.Parse(this.h_printamount.Value.Trim().Equals("") ? "0" : this.h_printamount.Value.Trim());
invoiceEntity.PrintCaptial = this.h_printcapital.Value.Trim();
invoiceEntity.PrintTitle = this.h_rename.Value.Trim();
invoiceEntity.CompanyID = strCompanyID;
int iResult = invoiceDA.InsertImportInvoice(invoiceEntity, feeDoEntities);
if (iResult == 1)
{
ViewState["enter"] = "1";//已经保存成功
ViewState["SaveState"] = "1";//已经保存成功
ViewState["InvoiceID"] = invoiceEntity.GID;//保存发票开出主表GID
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('发票开出成功');refresh();window.parent.opener.location.href = window.parent.opener.location.href;window.close();</script>");
}
else if (iResult == -3)
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('因发票号重复,开出失败!');refresh();</script>");
}
else if (iResult == -4)
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('此发票在发票册中已开出或删除或锁定,开出失败!');refresh();</script>");
}
else
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('发票开出失败');refresh();</script>");
}
}
}
#endregion
#region 开出发票申请
/// <summary>
/// 开出发票申请
/// </summary>
/// <param name="tempInvoiceAppGID">发票申请GID</param>
private void MakeOutInvoiceApplication(string tempInvoiceAppGID)
{
InvoiceDA invoiceDA = new InvoiceDA();
//先获取发票申请信息
InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
invoiceApplicationEntity = invoiceApplicationDA.GetInvoiceApplicationByGID(tempInvoiceAppGID);
if (invoiceApplicationEntity.GID != null)
{
InvoiceEntity invoiceEntity = new InvoiceEntity();
invoiceEntity.GID = Guid.NewGuid().ToString();
invoiceEntity.InvoiceNO = this.h_invoiceno.Value.Trim();
invoiceEntity.BillNO = "";//invoiceApplicationEntity.BillNO;
invoiceEntity.CustomerName = invoiceApplicationEntity.CustomerName;
invoiceEntity.InvoiceCustName = this.h_customer.Value.Trim();
invoiceEntity.Bank = this.h_bank.Value.Trim();
invoiceEntity.Account = this.h_account.Value.Trim();
invoiceEntity.BSNO = this.h_custno.Value.Trim();
invoiceEntity.VesselVoyage = "";
invoiceEntity.ETD = this.h_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.h_etd.Value.Trim());
invoiceEntity.POL = this.h_pol.Value.Trim();
invoiceEntity.POD = this.h_pod.Value.Trim();
invoiceEntity.MBLNO = this.h_mblno.Value.Trim();
invoiceEntity.FeeItem = invoiceApplicationEntity.FeeItem;//CreateFeeDoXml(feeDoEntities).OuterXml;
invoiceEntity.AmountList = "";
//invoiceEntity.Amount = decimal.Parse(this.h_total.Value.Trim());
string[] strApplyAmount = this.txt_total.Value.Trim().Split(new char[] { ' ' });
invoiceEntity.Amount = decimal.Parse(strApplyAmount[1]);//decimal.Parse(this.h_total.Value.Trim());
invoiceEntity.AmountCapital = this.h_capitial.Value.Trim();
invoiceEntity.Currency = this.h_settlecurrency.Value.Trim();
invoiceEntity.Remark = this.txt_remark.Value.Trim();
invoiceEntity.Applicant = invoiceApplicationEntity.Applicant;
invoiceEntity.ApplyTime = invoiceApplicationEntity.ApplyTime;
invoiceEntity.InvoiceType = 1;
invoiceEntity.IsDelete = false;
invoiceEntity.IsNeedFee = false;
invoiceEntity.IsNeedPrint = false;
invoiceEntity.Operator = strUserID;
CompanyEntity companyEntity = new CompanyDA().GetCompanyByID(strCompanyID);
invoiceEntity.LicenseCode = companyEntity.LICENSECODE != null ? companyEntity.LICENSECODE : "";
invoiceEntity.TaxCode = companyEntity.TAXCODE != null ? companyEntity.TAXCODE : "";
invoiceEntity.ExchangeRate = this.h_settlecurrency.Value.Trim().Equals("USD") ? (decimal.Parse(h_exusdtormb.Value.Trim().Equals("") ? "1" : h_exusdtormb.Value.Trim())) : (decimal.Parse(h_exrmbtousd.Value.Trim().Equals("") ? "1" : h_exrmbtousd.Value.Trim()));
invoiceEntity.PrintAmount = decimal.Parse(this.h_printamount.Value.Trim().Equals("") ? "0" : this.h_printamount.Value.Trim());
invoiceEntity.PrintCaptial = this.h_printcapital.Value.Trim();
invoiceEntity.PrintTitle = this.h_rename.Value.Trim();
invoiceEntity.CompanyID = strCompanyID;
int iResult = invoiceDA.InsertInvoiceByApplication(invoiceEntity, tempInvoiceAppGID, invoiceApplicationEntity.BillNO);
if (iResult == 1)
{
ViewState["enter"] = "1";//已经保存成功
ViewState["SaveState"] = "1";//已经保存成功
ViewState["InvoiceID"] = invoiceEntity.GID;//保存发票开出主表GID
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('发票开出成功');refresh();window.parent.opener.location.href = window.parent.opener.location.href;window.close();</script>");
}
else if (iResult == -3)
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('因发票号重复,开出失败!');refresh();</script>");
}
else if (iResult == -4)
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('此发票在发票册中已开出或删除或锁定,开出失败!');refresh();</script>");
}
else
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('发票开出失败');refresh();</script>");
}
}
}
#endregion
private void MakeOutDirectInvoice(string tempCacheName)
{
if (Session[tempCacheName] != null)
{
InvoiceDA invoiceDA = new InvoiceDA();
DataTable feeTalbe = (DataTable)Session[tempCacheName];
IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
for (int i = 0; i < feeTalbe.Rows.Count; i++)
{
FeeDoEntity feeDoEntity = new FeeDoEntity();
feeDoEntity.FeeID = feeTalbe.Rows[i]["GID"].ToString();
feeDoEntity.FeeType = 1;
feeDoEntity.Currency = feeTalbe.Rows[i]["CURRENCY"].ToString().Trim().ToUpper();
feeDoEntity.Amount = decimal.Parse(feeTalbe.Rows[i]["CTL"].ToString());
feeDoEntity.DoAmount = decimal.Parse(feeTalbe.Rows[i]["CTL"].ToString());
feeDoEntity.CustomerName = h_customer.Value.Trim();
feeDoEntity.FeeName = feeTalbe.Rows[i]["FEENAME"].ToString().Trim().ToUpper();
feeDoEntity.BSNO = "";
feeDoEntity.Orig = 2;
feeDoEntity.ExchangeRate = 1;
feeDoEntity.MBLNO = "";
feeDoEntity.HBLNO = "";
feeDoEntity.BillNO = "";
feeDoEntity.GID = Guid.NewGuid().ToString();
feeDoEntity.Category = 7;
feeDoEntity.BSType = 1;
feeDoEntity.BillStatus = 2;
feeDoEntity.Remark = "";
feeDoEntity.UnsettleAmount = 0;
feeDoEntity.ExchangeRate = 0;
feeDoEntity.OrigCurrency = "";
feeDoEntity.OriginalFeeCSTL = decimal.Parse(feeTalbe.Rows[i]["CTL"].ToString());
feeDoEntity.CompanyID = strCompanyID;
feeDoEntities.Add(feeDoEntity);
}
InvoiceEntity invoiceEntity = new InvoiceEntity();
invoiceEntity.GID = Guid.NewGuid().ToString();
invoiceEntity.InvoiceNO = this.h_invoiceno.Value.Trim();
invoiceEntity.BillNO = "";
invoiceEntity.CustomerName = this.h_customer.Value.Trim();
invoiceEntity.InvoiceCustName = this.h_customer.Value.Trim();
invoiceEntity.Bank = this.h_bank.Value.Trim();
invoiceEntity.Account = this.h_account.Value.Trim();
invoiceEntity.BSNO = this.h_custno.Value.Trim();
invoiceEntity.VesselVoyage = "";
invoiceEntity.ETD = this.h_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.h_etd.Value.Trim());
invoiceEntity.POL = this.h_pol.Value.Trim();
invoiceEntity.POD = this.h_pod.Value.Trim();
invoiceEntity.MBLNO = this.h_mblno.Value.Trim();
invoiceEntity.FeeItem = CreateFeeDoXml(feeDoEntities).OuterXml;
invoiceEntity.AmountList = "";
//invoiceEntity.Amount = decimal.Parse(this.h_total.Value.Trim());
string[] strApplyAmount = this.txt_total.Value.Trim().Split(new char[] { ' ' });
invoiceEntity.Amount = decimal.Parse(strApplyAmount[1]);//decimal.Parse(this.h_total.Value.Trim());
invoiceEntity.AmountCapital = this.h_capitial.Value.Trim();
invoiceEntity.Currency = this.h_settlecurrency.Value.Trim();
invoiceEntity.Remark = this.txt_remark.Value.Trim();
invoiceEntity.Applicant = strUserID;
invoiceEntity.ApplyTime = DateTime.Parse(this.txt_makeouttime.Value.Trim());
invoiceEntity.InvoiceType = 2;
invoiceEntity.IsDelete = false;
invoiceEntity.IsNeedFee = false;
invoiceEntity.IsNeedPrint = false;
invoiceEntity.Operator = strUserID;
invoiceEntity.LicenseCode = "";
invoiceEntity.TaxCode = "";
invoiceEntity.ExchangeRate = this.h_settlecurrency.Value.Trim().Equals("USD") ? (decimal.Parse(h_exusdtormb.Value.Trim().Equals("") ? "1" : h_exusdtormb.Value.Trim())) : (decimal.Parse(h_exrmbtousd.Value.Trim().Equals("") ? "1" : h_exrmbtousd.Value.Trim()));
invoiceEntity.PrintAmount = decimal.Parse(this.h_printamount.Value.Trim().Equals("") ? "0" : this.h_printamount.Value.Trim());
invoiceEntity.PrintCaptial = this.h_printcapital.Value.Trim();
invoiceEntity.PrintTitle = this.h_rename.Value.Trim();
invoiceEntity.CompanyID = strCompanyID;
int iResult = invoiceDA.InsertInvoiceDirect(invoiceEntity, feeDoEntities);
if (iResult == 1)
{
ViewState["enter"] = "1";//已经保存成功
ViewState["SaveState"] = "1";//已经保存成功
ViewState["InvoiceID"] = invoiceEntity.GID;//保存发票开出主表GID
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('发票开出成功');refresh();window.close();</script>");
}
else if (iResult == -3)
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('因发票号重复,开出失败!');refresh();</script>");
}
else if (iResult == -4)
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('此发票在发票册中已开出或删除或锁定,开出失败!');refresh();</script>");
}
else
{
ViewState["enter"] = "1";
ViewState.Remove("SaveState");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('发票开出失败');refresh();</script>");
}
}
}
#region 从发票册内自动获取发票号码
/// <summary>
/// 从发票册内自动获取发票号码
/// </summary>
private void InitBookItems()
{
InvoiceBookItemEntity invoiceBookItemEntity = new InvoiceBookItemEntity();
InvoiceBookDA invoiceBookDA = new InvoiceBookDA();
invoiceBookItemEntity = invoiceBookDA.GetCurrentBookItem(strCompanyID);
if (invoiceBookItemEntity != null)
{
if (invoiceBookItemEntity.GID != null)
{
//this.txt_invoiceno.Value = invoiceBookItemEntity.InvoiceNum;
this.h_invoiceno.Value = invoiceBookItemEntity.InvoiceNum;
}
}
}
#endregion
#region 从服务器获取当前时间 赋值到开票日期内
/// <summary>
/// 从服务器获取当前时间 赋值到开票日期内
/// </summary>
private void InitMakeOutTime()
{
InvoiceApplicationDA tempInvoiceApplicationDA = new InvoiceApplicationDA();
DateTime currentDateTime = tempInvoiceApplicationDA.GetServerTime();
if (currentDateTime != DateTime.MinValue)
{
this.txt_makeouttime.Value = currentDateTime.ToString("yyyy-MM-dd");
}
}
#endregion
///// <summary>
///// 更新发票信息
///// </summary>
//private void UpdateInvoiceInfo()
//{
// if (!this.h_feecache.Value.Trim().Equals(""))
// {
// string strList = this.h_feecache.Value.Trim();
// string strFilter = "";
// InvoiceDA invoiceDA = new InvoiceDA();
// InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
// IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
// string strBillNO = CreateBillNO();
// 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 = strArg[1].ToString().Replace("\"", "").Trim() == "" ? 3 : 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":
// feeDoEntity.Orig = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// //case "origcur":
// // feeDoEntity.OrigCurrency = strArg[1].ToString().Replace("\"", "").Trim().ToUpper();
// // 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 = 7;
// feeDoEntity.BSType = 1;
// feeDoEntity.BillStatus = 2;
// feeDoEntity.Remark = "";
// feeDoEntity.UnsettleAmount = 0;
// feeDoEntity.ExchangeRate = 0;
// feeDoEntity.OrigCurrency = "";
// feeDoEntities.Add(feeDoEntity);
// }
// }
// }
// InvoiceEntity invoiceEntity = new InvoiceEntity();
// //查看是否已经存在已经开票的相关申请
// invoiceEntity = invoiceDA.GetInvoiceByBillNO(strBillNO);
// //如果不存在相同的发票信息,则执行开票操作
// if (invoiceEntity.GID == null)
// {
// invoiceEntity.GID = Guid.NewGuid().ToString();
// invoiceEntity.InvoiceNO = this.txt_invoiceno.Value.Trim();
// invoiceEntity.BillNO = strBillNO;
// invoiceEntity.CustomerName = this.h_customer.Value.Trim();
// invoiceEntity.InvoiceCustName = this.h_customer.Value.Trim();
// invoiceEntity.Bank = this.h_bank.Value.Trim();
// invoiceEntity.Account = this.h_account.Value.Trim();
// invoiceEntity.BSNO = this.h_custno.Value.Trim();
// invoiceEntity.VesselVoyage = "";
// invoiceEntity.ETD = this.h_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.h_etd.Value.Trim());
// invoiceEntity.POL = this.h_pol.Value.Trim();
// invoiceEntity.POD = this.h_pod.Value.Trim();
// invoiceEntity.MBLNO = this.h_mblno.Value.Trim();
// invoiceEntity.FeeItem = CreateFeeDoXml(feeDoEntities).OuterXml;
// invoiceEntity.AmountList = "";
// //invoiceEntity.Amount = decimal.Parse(this.h_total.Value.Trim());
// string[] strApplyAmount = this.txt_total.Value.Trim().Split(new char[] { ' ' });
// invoiceEntity.Amount = decimal.Parse(strApplyAmount[1]);//decimal.Parse(this.h_total.Value.Trim());
// invoiceEntity.AmountCapital = this.h_capitial.Value.Trim();
// invoiceEntity.Currency = this.h_settlecurrency.Value.Trim();
// invoiceEntity.Remark = this.txt_remark.Value.Trim();
// invoiceEntity.Applicant = "";
// invoiceEntity.ApplyTime = DateTime.MinValue;
// invoiceEntity.InvoiceType = 1;
// invoiceEntity.IsDelete = false;
// invoiceEntity.IsNeedFee = false;
// invoiceEntity.IsNeedPrint = false;
// invoiceEntity.Operator = strUserID;
// invoiceEntity.LicenseCode = "";
// invoiceEntity.TaxCode = "";
// int iResult = invoiceDA.InsertInvoiceDirect(invoiceEntity, feeDoEntities);
// if (iResult == 1)
// {
// this.txt_invoiceno.Disabled = true;
// this.txt_vesselvoyage.Disabled = true;
// this.txt_mblno.Disabled = true;
// this.txt_etd.Disabled = true;
// this.txt_pod.Disabled = true;
// this.txt_pol.Disabled = true;
// this.sel_account.Disabled = true;
// this.sel_bank.Disabled = true;
// this.sel_customer.Disabled = true;
// this.btn_makeout.Disabled = true;
// this.h_invoiceid.Value = invoiceEntity.GID;
// //this.btn_createinvoice.Disabled = false;
// }
// }
// }
// }
//}
#region 手动填写开发票
/// <summary>
/// 手动填写开发票
/// </summary>
private void DirectMakeOutInvoice()
{
if (!this.h_feecache.Value.Trim().Equals(""))
{
string strList = this.h_feecache.Value.Trim();
string strFilter = "";
InvoiceDA invoiceDA = new InvoiceDA();
InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
string strBillNO = CreateBillNO();
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 = strArg[1].ToString().Replace("\"", "").Trim() == "" ? 3 : 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":
feeDoEntity.Orig = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
//case "origcur":
// feeDoEntity.OrigCurrency = strArg[1].ToString().Replace("\"", "").Trim().ToUpper();
// 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 = 7;
feeDoEntity.BSType = 1;
feeDoEntity.BillStatus = 2;
feeDoEntity.Remark = "";
feeDoEntity.UnsettleAmount = 0;
feeDoEntity.ExchangeRate = 0;
feeDoEntity.OrigCurrency = "";
feeDoEntities.Add(feeDoEntity);
}
}
}
InvoiceEntity invoiceEntity = new InvoiceEntity();
//查看是否已经存在已经开票的相关申请
invoiceEntity = invoiceDA.GetInvoiceByBillNO(strBillNO);
//如果不存在相同的发票信息,则执行开票操作
if (invoiceEntity.GID == null)
{
invoiceEntity.GID = Guid.NewGuid().ToString();
invoiceEntity.InvoiceNO = this.h_invoiceno.Value.Trim();
invoiceEntity.BillNO = strBillNO;
invoiceEntity.CustomerName = this.h_customer.Value.Trim();
invoiceEntity.InvoiceCustName = this.h_customer.Value.Trim();
invoiceEntity.Bank = this.h_bank.Value.Trim();
invoiceEntity.Account = this.h_account.Value.Trim();
invoiceEntity.BSNO = this.h_custno.Value.Trim();
invoiceEntity.VesselVoyage = "";
invoiceEntity.ETD = this.h_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.h_etd.Value.Trim());
invoiceEntity.POL = this.h_pol.Value.Trim();
invoiceEntity.POD = this.h_pod.Value.Trim();
invoiceEntity.MBLNO = this.h_mblno.Value.Trim();
invoiceEntity.FeeItem = CreateFeeDoXml(feeDoEntities).OuterXml;
invoiceEntity.AmountList = "";
//invoiceEntity.Amount = decimal.Parse(this.h_total.Value.Trim());
string[] strApplyAmount = this.txt_total.Value.Trim().Split(new char[] { ' ' });
invoiceEntity.Amount = decimal.Parse(strApplyAmount[1]);//decimal.Parse(this.h_total.Value.Trim());
invoiceEntity.AmountCapital = this.h_capitial.Value.Trim();
invoiceEntity.Currency = this.h_settlecurrency.Value.Trim();
invoiceEntity.Remark = this.txt_remark.Value.Trim();
invoiceEntity.Applicant = strUserID;
invoiceEntity.ApplyTime = DateTime.Parse(this.txt_makeouttime.Value.Trim());
invoiceEntity.InvoiceType = 1;
invoiceEntity.IsDelete = false;
invoiceEntity.IsNeedFee = false;
invoiceEntity.IsNeedPrint = false;
invoiceEntity.Operator = strUserID;
invoiceEntity.LicenseCode = "";
invoiceEntity.TaxCode = "";
invoiceEntity.ExchangeRate = this.h_settlecurrency.Value.Trim().Equals("USD") ? (decimal.Parse(h_exusdtormb.Value.Trim().Equals("") ? "1" : h_exusdtormb.Value.Trim())) : (decimal.Parse(h_exrmbtousd.Value.Trim().Equals("") ? "1" : h_exrmbtousd.Value.Trim()));
invoiceEntity.PrintAmount = decimal.Parse(this.h_printamount.Value.Trim().Equals("") ? "0" : this.h_printamount.Value.Trim());
invoiceEntity.PrintCaptial = this.h_printcapital.Value.Trim();
invoiceEntity.PrintTitle = this.h_rename.Value.Trim();
int iResult = invoiceDA.InsertInvoiceDirect(invoiceEntity, feeDoEntities);
if (iResult == 1)
{
//this.txt_invoiceno.Disabled = true;
this.sel_invoiceno.Disabled = true;
this.txt_vesselvoyage.Disabled = true;
this.txt_mblno.Disabled = true;
this.txt_etd.Disabled = true;
this.txt_pod.Disabled = true;
this.txt_pol.Disabled = true;
this.sel_account.Disabled = true;
this.sel_bank.Disabled = true;
this.sel_customer.Disabled = true;
this.btn_makeout.Disabled = true;
this.h_invoiceid.Value = invoiceEntity.GID;
//this.btn_createinvoice.Disabled = false;
}
}
}
}
}
#endregion
//#region 发票申请开出发票
///// <summary>
///// 发票申请开出发票
///// </summary>
///// <param name="tempInvoiceAppGID"></param>
//private void MakeOutInvoice(string tempInvoiceAppGID)
//{
// if (!this.h_feecache.Value.Trim().Equals(""))
// {
// string strList = this.h_feecache.Value.Trim();
// string strFilter = "";
// InvoiceDA invoiceDA = new InvoiceDA();
// InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
// InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
// invoiceApplicationEntity = invoiceApplicationDA.GetInvoiceApplicationByGID(tempInvoiceAppGID);
// IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
// IList<FeeEntity> feeEntities = new List<FeeEntity>();
// FeeDA feeDA = new FeeDA();
// 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 = strArg[1].ToString().Replace("\"", "").Trim() == "" ? 3 : 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":
// feeDoEntity.Orig = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
// break;
// case "origcur":
// feeDoEntity.OrigCurrency = strArg[1].ToString().Replace("\"", "").Trim().ToUpper();
// 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 = invoiceApplicationEntity.BillNO;
// feeDoEntity.GID = Guid.NewGuid().ToString();
// feeDoEntity.Category = 7;
// feeDoEntity.BSType = 1;
// feeDoEntity.BillStatus = 2;
// feeDoEntity.Remark = "";
// if (feeDoEntity.Orig == 1)
// {
// //FeeEntity feeEntity = new FeeEntity();
// //feeEntity = feeDA.GetFeeByID(feeDoEntity.FeeID);
// //feeEntities.Add(feeEntity);
// feeDoEntities.Add(feeDoEntity);
// }
// }
// }
// }
// }
// if (invoiceApplicationEntity.GID != null)
// {
// InvoiceEntity invoiceEntity = new InvoiceEntity();
// //查看是否已经存在已经开票的相关申请
// invoiceEntity = invoiceDA.GetInvoiceByBillNO(invoiceApplicationEntity.BillNO);
// //如果不存在相同的发票信息,则执行开票操作
// if (invoiceEntity.GID == null)
// {
// invoiceEntity.GID = Guid.NewGuid().ToString();
// invoiceEntity.InvoiceNO = this.txt_invoiceno.Value.Trim();
// invoiceEntity.BillNO = invoiceApplicationEntity.BillNO;
// invoiceEntity.CustomerName = invoiceApplicationEntity.CustomerName;
// invoiceEntity.InvoiceCustName = this.h_customer.Value.Trim();
// invoiceEntity.Bank = this.h_bank.Value.Trim();
// invoiceEntity.Account = this.h_account.Value.Trim();
// invoiceEntity.BSNO = this.h_custno.Value.Trim();
// invoiceEntity.VesselVoyage = "";
// invoiceEntity.ETD = this.h_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.h_etd.Value.Trim());
// invoiceEntity.POL = this.h_pol.Value.Trim();
// invoiceEntity.POD = this.h_pod.Value.Trim();
// invoiceEntity.MBLNO = this.h_mblno.Value.Trim();
// invoiceEntity.FeeItem = CreateFeeDoXml(feeDoEntities).OuterXml;
// invoiceEntity.AmountList = "";
// //invoiceEntity.Amount = decimal.Parse(this.h_total.Value.Trim());
// string[] strApplyAmount = this.txt_total.Value.Trim().Split(new char[] { ' ' });
// invoiceEntity.Amount = decimal.Parse(strApplyAmount[1]);//decimal.Parse(this.h_total.Value.Trim());
// invoiceEntity.AmountCapital = this.h_capitial.Value.Trim();
// invoiceEntity.Currency = this.h_settlecurrency.Value.Trim();
// invoiceEntity.Remark = this.txt_remark.Value.Trim();
// invoiceEntity.Applicant = invoiceApplicationEntity.Applicant;
// invoiceEntity.ApplyTime = invoiceApplicationEntity.ApplyTime;
// invoiceEntity.InvoiceType = 1;
// invoiceEntity.IsDelete = false;
// invoiceEntity.IsNeedFee = false;
// invoiceEntity.IsNeedPrint = false;
// invoiceEntity.Operator = strUserID;
// CompanyEntity companyEntity = new CompanyDA().GetCompanyByID(strCompanyID);
// invoiceEntity.LicenseCode = companyEntity.LICENSECODE != null ? companyEntity.LICENSECODE : "";
// invoiceEntity.TaxCode = companyEntity.TAXCODE != null ? companyEntity.TAXCODE : "";
// invoiceEntity.ExchangeRate = this.h_settlecurrency.Value.Trim().Equals("USD") ? (decimal.Parse(h_exusdtormb.Value.Trim().Equals("") ? "1" : h_exusdtormb.Value.Trim())) : (decimal.Parse(h_exrmbtousd.Value.Trim().Equals("") ? "1" : h_exrmbtousd.Value.Trim()));
// invoiceEntity.PrintAmount = decimal.Parse(this.h_printamount.Value.Trim().Equals("") ? "0" : this.h_printamount.Value.Trim());
// invoiceEntity.PrintCaptial = this.h_printcapital.Value.Trim();
// invoiceEntity.PrintTitle = this.h_rename.Value.Trim();
// int iResult = invoiceDA.InsertInvoice(invoiceEntity, feeDoEntities, invoiceApplicationEntity.BillNO);
// if (iResult == 1)
// {
// this.txt_invoiceno.Disabled = true;
// this.txt_vesselvoyage.Disabled = true;
// this.txt_mblno.Disabled = true;
// this.txt_etd.Disabled = true;
// this.txt_pod.Disabled = true;
// this.txt_pol.Disabled = true;
// this.sel_account.Disabled = true;
// this.sel_bank.Disabled = true;
// this.sel_customer.Disabled = true;
// this.btn_makeout.Disabled = true;
// this.h_invoiceid.Value = invoiceEntity.GID;
// this.btn_createinvoice.Disabled = false;
// IList<MessageEntity> messageEntities = new List<MessageEntity>();
// MessageDA messageDA = new MessageDA();
// MessageEntity messageEntity = new MessageEntity();
// messageEntity.GID = Guid.NewGuid().ToString();
// messageEntity.Name = "InvoiceAppMakeout";
// messageEntity.Description = "发票申请开出";
// messageEntity.IsRead = false;
// messageEntity.ReadCount = 0;
// messageEntity.MessageContent = strShowName + " 已经开出 [发票申请] 业务编号:" + invoiceApplicationEntity.BillNO + " 金额 " + this.txt_total.Value.Trim() + " ";
// messageEntity.TaskID = invoiceApplicationEntity.BillNO;
// messageEntity.Receiver = invoiceApplicationEntity.Applicant;
// messageEntity.TaskUrl = messageEntity.TaskUrl = "invoice/invoiceapplicationlist.aspx";
// messageEntity.Type = messageDA.GetMessageType(MessageType.INVOICEAPP);
// messageEntity.RecvType = 3;//审核完成类型
// messageEntities.Add(messageEntity);
// if (messageEntities.Count > 0)
// {
// messageDA.CreateMessage(MessageType.INVOICEAPP, messageEntities);
// }
// //Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('发票开出成功');setTimeOut(function(){btnDisable('btn_makeout');},70);</script>");
// this.h_billno.Value = invoiceEntity.BillNO;
// }
// }
// }
// }
//}
//#endregion
#region 开出引入费用发票
/// <summary>
/// 开出引入费用发票
/// </summary>
private void MakeOutImportInvoice()
{
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>();
IList<FeeEntity> feeEntities = new List<FeeEntity>();
FeeDA feeDA = new FeeDA();
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 = strArg[1].ToString().Replace("\"", "").Trim() == "" ? 3 : 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":
feeDoEntity.Orig = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "origcur":
feeDoEntity.OrigCurrency = strArg[1].ToString().Replace("\"", "").Trim().ToUpper();
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 = 7;
feeDoEntity.BSType = 1;
feeDoEntity.BillStatus = 2;
feeDoEntity.Remark = "";
if (feeDoEntity.Orig == 1)
{
//FeeEntity feeEntity = new FeeEntity();
//feeEntity = feeDA.GetFeeByID(feeDoEntity.FeeID);
//feeEntities.Add(feeEntity);
feeDoEntities.Add(feeDoEntity);
}
}
}
}
}
InvoiceDA invoiceDA = new InvoiceDA();
InvoiceEntity invoiceEntity = new InvoiceEntity();
//查看是否已经存在已经开票的相关信息
invoiceEntity = invoiceDA.GetInvoiceByBillNO(strBillNO);
if (invoiceEntity.GID == null)
{
invoiceEntity.GID = Guid.NewGuid().ToString();
invoiceEntity.InvoiceNO = this.h_invoiceno.Value.Trim();
invoiceEntity.BillNO = strBillNO;
invoiceEntity.CustomerName = feeDoEntities[0].CustomerName;
invoiceEntity.InvoiceCustName = this.h_customer.Value.Trim();
invoiceEntity.Bank = this.h_bank.Value.Trim();
invoiceEntity.Account = this.h_account.Value.Trim();
invoiceEntity.BSNO = this.h_custno.Value.Trim();
invoiceEntity.VesselVoyage = "";
invoiceEntity.ETD = this.h_etd.Value.Trim().Equals("") ? DateTime.MinValue : DateTime.Parse(this.h_etd.Value.Trim());
invoiceEntity.POL = this.h_pol.Value.Trim();
invoiceEntity.POD = this.h_pod.Value.Trim();
invoiceEntity.MBLNO = this.h_mblno.Value.Trim();
invoiceEntity.FeeItem = CreateFeeDoXml(feeDoEntities).OuterXml;
invoiceEntity.AmountList = "";
string[] strApplyAmount = this.txt_total.Value.Trim().Split(new char[] { ' ' });
invoiceEntity.Amount = decimal.Parse(strApplyAmount[1]);//decimal.Parse(this.h_total.Value.Trim());
invoiceEntity.AmountCapital = this.h_capitial.Value.Trim();
invoiceEntity.Currency = this.h_settlecurrency.Value.Trim();
invoiceEntity.Remark = this.txt_remark.Value.Trim();
invoiceEntity.Applicant = strUserID;
invoiceEntity.ApplyTime = DateTime.Parse(this.txt_makeouttime.Value.Trim());
invoiceEntity.InvoiceType = 2;
invoiceEntity.IsDelete = false;
invoiceEntity.IsNeedFee = false;
invoiceEntity.IsNeedPrint = false;
invoiceEntity.Operator = strUserID;
CompanyEntity companyEntity = new CompanyDA().GetCompanyByID(strCompanyID);
invoiceEntity.LicenseCode = companyEntity.LICENSECODE != null ? companyEntity.LICENSECODE : "";
invoiceEntity.TaxCode = companyEntity.TAXCODE != null ? companyEntity.TAXCODE : "";
invoiceEntity.ExchangeRate = this.h_settlecurrency.Value.Trim().Equals("USD") ? (decimal.Parse(h_exusdtormb.Value.Trim().Equals("") ? "1" : h_exusdtormb.Value.Trim())) : (decimal.Parse(h_exrmbtousd.Value.Trim().Equals("") ? "1" : h_exrmbtousd.Value.Trim()));
invoiceEntity.PrintAmount = decimal.Parse(this.h_printamount.Value.Trim().Equals("") ? "0" : this.h_printamount.Value.Trim());
invoiceEntity.PrintCaptial = this.h_printcapital.Value.Trim();
invoiceEntity.PrintTitle = this.h_rename.Value.Trim();
int iResult = 0;
iResult = invoiceDA.InsertImportInvoice(invoiceEntity, feeDoEntities);
if (iResult == 1)
{
this.h_saved.Value = "1";//保存状态位
this.btn_makeout.Disabled = true;
this.h_invoiceid.Value = invoiceEntity.GID;
this.btn_createinvoice.Disabled = false;
this.h_billno.Value = invoiceEntity.BillNO;
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('发票开出成功');setTimeOut(function(){btnDisable('btn_makeout');},70);</script>");
}
}
}
}
#endregion
#region 生成开票申请编号
/// <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 ch_fee_invoiceapplication WHERE BILLNO LIKE '" + strFeeType + strDateTime + "%' ORDER BY BILLNO DESC";
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;
}
#endregion
#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 读取FeeItem费用明细数据
/// <summary>
/// 读取FeeItem费用明细数据
/// </summary>
/// <param name="strXml">XML字符串</param>
/// <returns>返回实体类FeeDoEntity</returns>
private IList<FeeDoEntity> GetFeeDoXml(string strXml)
{
XmlDocument xmlFeeDoDoc = new XmlDocument();
IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
try
{
xmlFeeDoDoc.LoadXml(strXml);
for (int i = 0; i < xmlFeeDoDoc.ChildNodes[0].ChildNodes[0].ChildNodes.Count; i++)
{
FeeDoEntity feeDoEntity = new FeeDoEntity();
feeDoEntity.FeeID = xmlFeeDoDoc.ChildNodes[0].ChildNodes[0].ChildNodes[i].ChildNodes[0].InnerText.Trim();
feeDoEntity.FeeName = xmlFeeDoDoc.ChildNodes[0].ChildNodes[0].ChildNodes[i].ChildNodes[1].InnerText.Trim();
feeDoEntity.DoAmount = decimal.Parse(xmlFeeDoDoc.ChildNodes[0].ChildNodes[0].ChildNodes[i].ChildNodes[2].InnerText.Trim());
feeDoEntity.Category = int.Parse(xmlFeeDoDoc.ChildNodes[0].ChildNodes[0].ChildNodes[i].ChildNodes[3].InnerText.Trim());
feeDoEntity.FeeType = int.Parse(xmlFeeDoDoc.ChildNodes[0].ChildNodes[0].ChildNodes[i].ChildNodes[4].InnerText.Trim());
feeDoEntity.Orig = int.Parse(xmlFeeDoDoc.ChildNodes[0].ChildNodes[0].ChildNodes[i].ChildNodes[5].InnerText.Trim());
feeDoEntities.Add(feeDoEntity);
}
}
catch (Exception error)
{
throw (error);
}
return feeDoEntities;
}
#endregion
#region 创建FeeItem的XML信息
/// <summary>
/// 创建FeeItem的XML信息
/// </summary>
/// <param name="tempFeeDoEntities">FeeDoEntity实体类信息</param>
/// <returns>返回XML字符串</returns>
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;
}
#endregion
#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 = "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 + "'";
//2013-02-05 修改
string 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 + "'";
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();
}
#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
}
}