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/InvoiceApplicationGridSourc...

6134 lines
319 KiB
C#

This file contains ambiguous Unicode characters!

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

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
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.Text;
using System.Text.RegularExpressions;
using DSWeb.Models;
using DSWeb.EntityDA;
using DSWeb.ConfigManager;
using DSWeb.Authority;
namespace DSWeb.Invoice
{
public partial class InvoiceApplicationGridSource : System.Web.UI.Page
{
private string strHandle;
private string strSearch;//委托信息查询条件
private string strBSNO;//海运出口委托编号
private string strFeeSearch;//费用查询条件
private string strApplicationGID;//开票申请GID
private string strInvoiceGID;//发票GID
private string strUserID;//登录人GID
private string strBillNO;//发票申请编号
private string strCurrency;//币别名称
private string strCustomerName;//结算单位名称
private int iCurrentPage;//当前页数
private int iShowPage;//显示最大页数
private string strOrderCacheName;//缓存名称
private string strSelectedOrder;//已经选择的委托信息
private string strCheckType;//全选类型 值"check"选中的值 值"uncheck"去除选择的值
private string strFeeID;//费用GID
private string strPostSessionID;//提交发票申请Session
private string strRename;//是否是自定义名称
private decimal dExchangeRate;//折算汇率
private decimal dCSTL;//本次结算
private decimal dUSTL;//未结金额
private string strInvoiceAppID;//发票申请GID
private string strCompanyID;//公司GID
private string strShowName;//用户显示名
private string strDeptName;//部门名称
private string strDoTypeName;//调用页面标识
private string strCacheName;//缓存名称
private string strVerifyFeeID;//发票收费结算-费用GID
private int iCheckType;//操作类型 1-选中单个费用 2-取消选中单个费用 3-选中全部费用 4-取消选中所有费用
private int iExchangeType;//折算方式 1-RMB折算 2-USD折算 3-不折算按默认币别统计
private decimal dDoAmount;//结算金额
private decimal dUnDoAmount;//未结算金额
private string strBankName;//银行名称
private string strTotalCacheName;//结算合计缓存名称
private string strBsnoCacheName;//委托缓存名称
private string stroplb = "";//业务类别
private string strbstype="";//业务类别
private string strBorrowPay;//是否查询垫付信息
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
#region 请求处理
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString().Trim().ToLower();
}
if (Request.QueryString["oplb"] != null)
{
stroplb = Request.QueryString["oplb"].ToString();
}
if (Request.QueryString["bstype"] != null)
{
strbstype = Request.QueryString["bstype"].ToString();
}
if(Request.QueryString["billno"] != null)
{
strBillNO = Request.QueryString["billno"].ToString().Trim().ToLower();
}
if (Request.QueryString["search"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strSearch = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["search"].ToString())));
}
if (Request.QueryString["fsearch"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strFeeSearch = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["fsearch"].ToString())));
}
if (Request.QueryString["customer"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strCustomerName = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["customer"].ToString())));
}
if (Request.QueryString["bsno"] != null)
{
strBSNO = Request.QueryString["bsno"].ToString();
}
if (Request.QueryString["appid"] != null)
{
strApplicationGID = Request.QueryString["appid"].ToString().Trim();
}
if (Request.QueryString["invoiceid"] != null)
{
strInvoiceGID = Request.QueryString["invoiceid"].ToString();
}
if(Request.QueryString["currency"] != null)
{
strCurrency = Request.QueryString["currency"].ToString().Trim().ToUpper();
}
if (Request.QueryString["cur_page"] != null)
{
iCurrentPage = int.Parse(Request.QueryString["cur_page"].ToString().Trim());
}
else
{
iCurrentPage = 0;
}
if (Request.QueryString["show_page"] != null)
{
iShowPage = int.Parse(Request.QueryString["show_page"].ToString().Trim());
}
else
{
iShowPage = 0;
}
if (Request.QueryString["ordercachename"] != null)
{
strOrderCacheName = Request.QueryString["ordercachename"].ToString();
}
if (Request.QueryString["selectedorder"] != null)
{
strSelectedOrder = Request.QueryString["selectedorder"].ToString();
}
if (Request.QueryString["op"] != null)
{
strCheckType = Request.QueryString["op"].ToString();
}
if (Request.QueryString["feeid"] != null)
{
strFeeID = Request.QueryString["feeid"].ToString().Trim();
}
if (Request.QueryString["postsession"] != null)
{
strPostSessionID = Request.QueryString["postsession"].ToString();
}
if (Request.QueryString["rename"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strRename = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["rename"].ToString())));
}
if (Request.QueryString["exchange"] != null)
{
dExchangeRate = decimal.Parse(Request.QueryString["exchange"].ToString());
}
else
{
dExchangeRate = 0;
}
if(Request.QueryString["cstl"] != null)
{
dCSTL = decimal.Parse(Request.QueryString["cstl"].ToString());
}
if(Request.QueryString["ustl"] != null)
{
dUSTL = decimal.Parse(Request.QueryString["ustl"].ToString());
}
if (Request.QueryString["invoiceappid"] != null)
{
strInvoiceAppID = Request.QueryString["invoiceappid"].ToString();
}
if (Request.QueryString["do"] != null)
{
strDoTypeName = Request.QueryString["do"].ToString().ToLower();
}
if (Request.QueryString["cachename"] != null)
{
strCacheName = Request.QueryString["cachename"].ToString();
}
if (Request.QueryString["verifyfee"] != null)
{
strVerifyFeeID = Request.QueryString["verifyfee"].ToString();
}
if (Request.QueryString["checktype"] != null)
{
iCheckType = int.Parse(Request.QueryString["checktype"].ToString());
}
else
{
iCheckType = 0;
}
if (Request.QueryString["rate"] != null)
{
dExchangeRate = decimal.Parse(Request.QueryString["rate"].ToString());
}
if (Request.QueryString["settletype"] != null)
{
iExchangeType = int.Parse(Request.QueryString["settletype"].ToString());
}
else
{
iExchangeType = 0;
}
if (Request.QueryString["doamount"] != null)
{
dDoAmount = decimal.Parse(Request.QueryString["doamount"].ToString());
}
else
{
dDoAmount = 0;
}
if (Request.QueryString["unamount"] != null)
{
dUnDoAmount = decimal.Parse(Request.QueryString["unamount"].ToString());
}
else
{
dUnDoAmount = 0;
}
if(Request.QueryString["bankname"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strBankName = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["bankname"].ToString())));
}
if (Request.QueryString["totalcachename"] != null)
{
strTotalCacheName = Request.QueryString["totalcachename"].ToString();
}
if (Request.QueryString["bsnocachename"] != null)
{
strBsnoCacheName = Request.QueryString["bsnocachename"].ToString();
}
if (Request.QueryString["BorrowFee"] != null)//垫付
{
strBorrowPay = Request.QueryString["BorrowFee"].ToString();
}
if (strHandle != null)
{
//获取开票申请列表信息
if (strHandle.Equals("invoiceapplist"))
{
Response.Write(GetInvoiceApplicationAll());
}
else if (strHandle == "invoiceapplistpage")//获取发票申请数据总页数
{
Response.Write(GetInvoiceApplicationPageCount().ToString());
}
else if (strHandle.Equals("applist"))
{
Response.Write(GetInvoiceApplication());
}
else if (strHandle == "ordersearch")
{
Response.Write(GetSeaeOrderBySearch(strSearch));
}
else if (strHandle == "orderfee" && strBSNO != null)
{
Response.Write(GetSelectedOrderFee(strBSNO));
}
else if (strHandle == "opseae" && strBSNO != null)//获取船名航次相关信息
{
Response.Write(GetOpSeaeInfo(strBSNO));
}
else if (strHandle == "makeoutlist")
{
Response.Write(GetMakeOutList());
}
else if (strHandle == "makeoutlistpage")
{
Response.Write(GetMakeOutListPage());
}
else if (strHandle == "makeoutlistexcel")
{
Response.Write(GetMakeOutListExcel());
}
else if (strHandle == "postapply" && strApplicationGID != null)
{
//提交开票申请操作
Response.Write(PostMakeOutInvoiceApply(strApplicationGID));
}
else if (strHandle == "postapplybillno" && strBillNO != null)
{
//通过开票申请编号提交开票申请操作
Response.Write(PostMakeOutInvoiceApplyByBillNO(strBillNO));
}
else if (strHandle == "makeoutapp")
{
//获取开票申请信息,只包含已提交申请的信息
Response.Write(GetMakeOutInvoiceApplication());
}
else if (strHandle == "deleteapply")
{
//删除未提交的开票申请
Response.Write(DeleteUnPostApplication(strApplicationGID));
}
else if (strHandle == "deleteinvoice" && strInvoiceGID != null)
{
//删除已开票(包含自由和申请)发票
Response.Write(DeleteInvoice(strInvoiceGID));
}
else if (strHandle == "voidinvoice" && strInvoiceGID != null)
{
//废除发票
Response.Write(VoidInvoice(strInvoiceGID));
}
else if (strHandle == "print" && strInvoiceGID != null)
{
Response.Write(PrintInvoice(strInvoiceGID));
}
else if (strHandle == "invoiceapp" && strApplicationGID != null)
{
Response.Write(GetInvoiceApplicationByAppGID(strApplicationGID));
}
else if (strHandle == "bankinfo" && strCurrency != null)
{
Response.Write(GetBankInfo(strUserID, strCurrency));
}
else if (strHandle == "cuspayable" && strCustomerName != null)
{
Response.Write(GetCustomerPayable(strCustomerName));
}
else if (strHandle == "cacheorder" && strOrderCacheName != null)
{
//当全选委托时缓存数据
//Response.Write(CacheOrderFee(strSelectedOrder, strOrderCacheName));
Response.Write(CheckAllOrder(strSearch, strBsnoCacheName, strOrderCacheName, strTotalCacheName, strCheckType));
}
else if (strHandle == "checkorder" && strBSNO != null && strOrderCacheName != null && strCheckType != null && strBsnoCacheName != null && strTotalCacheName != null)
{
//单选委托信息
Response.Write(ExcuteCheckOrder(strBSNO, strCheckType, strOrderCacheName, strBsnoCacheName, strTotalCacheName));
}
else if (strHandle == "checkfee" && strFeeID != null && strOrderCacheName != null && strCheckType != null && strBsnoCacheName != null && strTotalCacheName != null && strBSNO != null)
{
Response.Write(ExcuteCheckFee(strFeeID, strCheckType, strOrderCacheName, strBsnoCacheName, strTotalCacheName, strBSNO));
}
else if (strHandle == "checkallfee" && strBSNO != null && strOrderCacheName != null && strCheckType != null && strBsnoCacheName != null && strTotalCacheName != null)
{
//费用全选操作
Response.Write(ExcuteCheckAllFee(strBSNO, strCheckType, strOrderCacheName, strBsnoCacheName, strTotalCacheName));
}
else if (strHandle == "validatepost" && strOrderCacheName != null)
{
//查看是否有不同的结算单位
Response.Write(ValidatePostInfo(strOrderCacheName));
}
else if (strHandle == "postinvoiceapp" && strPostSessionID != null && strOrderCacheName != null && strBsnoCacheName != null && strTotalCacheName != null)
{
//提交开票申请SESSION信息
Response.Write(PostInvoiceApplicationSession(strPostSessionID, strBsnoCacheName, strOrderCacheName, strTotalCacheName));
}
else if (strHandle == "changefee" && strOrderCacheName != null && strFeeID != null && strBsnoCacheName != null && strTotalCacheName != null && strBSNO != null)
{
//更改本次结算费用金额
Response.Write(ChangeFeeCstl(strOrderCacheName, strFeeID, dCSTL, dUSTL, strBsnoCacheName, strTotalCacheName, strBSNO));
}
else if (strHandle == "invoiceeditfee" && strInvoiceGID != null && strBSNO != null)
{
Response.Write(GetInvoiceMakeOutEditFeeByGID(strInvoiceGID, strBSNO));
}
else if (strHandle == "invoiceappeditfee" && strInvoiceAppID != null && strBSNO != null)
{
Response.Write(GetInvoiceApplicationEditFeeByGID(strInvoiceAppID, strBSNO));
}
else if (strHandle == "validatemakeout")
{
Response.Write(ValidateUserMakeOutAuthority().ToString());
}
else if (strHandle == "validateinvoiceapp")
{
Response.Write(ValidateUserInvoiceApplicationAuthority().ToString());
}
else if (strHandle == "unverifyinvoice" )
{
//获取已开发票但未收费的发票信息
Response.Write(GetUnverificationInvoice());
}
else if (strHandle == "unverifyinvoicepage")
{
//获取已开发票但未收费的发票信息
Response.Write(GetUnverificationListPage());
}
else if (strHandle == "unverificationfee" && strInvoiceGID != null)
{
//获取已开票但未收费的费用明细信息
Response.Write(GetUnverificationFeeList(strInvoiceGID));
}
else if (strHandle == "unverificationfeepage" && strInvoiceGID != null)
{
Response.Write(GetUnverificationFeeListPage(strInvoiceGID));
}
else if (strHandle == "checkverifyfee" && strInvoiceGID != null && strCacheName != null && iCheckType > 0)
{
Response.Write(CacheVerificationFee(strInvoiceGID,strVerifyFeeID,iCheckType,strCacheName));
}
else if (strHandle == "editverifyfee" && strInvoiceGID != null && strVerifyFeeID != null && strCacheName != null)
{
Response.Write(EditVerificationFee(strInvoiceGID,strVerifyFeeID,strCacheName));
}
else if (strHandle == "verifyfeerate" && strCacheName != null)
{
Response.Write(ReStatisticVerificationFee(strCacheName));
}
else if (strHandle == "voidinvoiceapp" && strInvoiceAppID != null)
{
Response.Write(CancelInvoiceApplication(strInvoiceAppID));
}
else if (strHandle == "getaccount" && strCurrency != null & strBankName != null)
{
Response.Write(GetBankInfoByBankName(strUserID, strCurrency, strBankName));
}
else if (strHandle == "refreshorder" && strOrderCacheName != null && strBsnoCacheName != null && strTotalCacheName != null && strSearch != null)
{
Response.Write(RefreshOrder(strSearch, strBsnoCacheName, strOrderCacheName, strTotalCacheName, strCheckType));
}
}
#endregion
}
#region 获取当前用户的公司的支付信息通过币别和银行名称区分类型
/// <summary>
/// 获取当前用户的公司的支付信息通过币别和银行名称区分类型
/// </summary>
/// <param name="strUserID">用户GID</param>
/// <param name="strCurrency">币别名称</param>
/// <param name="tempBankName">银行名称</param>
/// <returns>所有支付信息</returns>
private string GetBankInfoByBankName(string strUserID, string strCurrency,string tempBankName)
{
CRMClientDA crmClientDA = new CRMClientDA();
string strSql = String.Format(" SELECT GID,BANKNAME,ACCOUNT,CURRENCY FROM sys_bank WHERE LINKID IN "
+ " (SELECT C.GID FROM [user] as A INNER JOIN user_company as B on A.GID = B.USERID INNER JOIN [company] as C "
+ " ON B.COMPANYID = C.GID WHERE A.GID = '{0}' and A.ISDELETED=0) AND CURRENCY = '{1}' AND BANKNAME = '{2}' ", strUserID, strCurrency, tempBankName);
DataTable sourceTable = crmClientDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("banks:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("\"bank\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"account\":\"" + sourceTable.Rows[i][2].ToString() + "\",");
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("\"currency\":\"" + sourceTable.Rows[i][3].ToString() + "\"}");
}
else
{
sourceBuilder.Append("\"currency\":\"" + sourceTable.Rows[i][3].ToString() + "\"},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 驳回发票申请
/// <summary>
/// 驳回发票申请
/// </summary>
/// <param name="tempInvoiceID">发票申请GID</param>
/// <returns>值1表示驳回成功 值不等于1表示驳回失败</returns>
private int CancelInvoiceApplication(string tempInvoiceID)
{
int iResult = 0;
IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
invoiceApplicationEntity = invoiceApplicationDA.GetInvoiceApplicationByGID(tempInvoiceID);
if (invoiceApplicationEntity != null)
{
if (invoiceApplicationEntity.GID != null)
{
if (!invoiceApplicationEntity.IsDelete)
{
iResult = invoiceApplicationDA.voidInvoiceApplication(tempInvoiceID, strUserID, invoiceApplicationEntity.BillNO);
}
}
else
{
iResult = -3;//发票申请不存在
}
}
else
{
iResult = -3;//发票申请不存在
}
return iResult;
}
#endregion
#region 根据币别重新计算结算费用
/// <summary>
/// 根据币别重新计算结算费用
/// </summary>
/// <param name="tempCacheName">缓存名称</param>
/// <returns>返回重新计算的费用</returns>
private string ReStatisticVerificationFee(string tempCacheName)
{
string strResult = "";
DataTable sourceTable;
if (Session[tempCacheName] != null)
{
sourceTable = (DataTable)Session[tempCacheName];
}
else
{
sourceTable = new DataTable();
}
strResult = GetProfitValue(sourceTable, dExchangeRate, iExchangeType);
return strResult;
}
#endregion
#region 发票收费结算-部分结算操作
/// <summary>
/// 发票收费结算-部分结算操作
/// </summary>
/// <param name="tempInvoiceGID">发票GID</param>
/// <param name="tempVerifyFeeID">费用GID</param>
/// <param name="tempCacheName">缓存名称</param>
/// <returns>返回计算后的总金额</returns>
private string EditVerificationFee(string tempInvoiceGID, string tempVerifyFeeID, string tempCacheName)
{
string strResult = "";
string strSql = "";
InvoiceDA invoiceDA = new InvoiceDA();
DataTable sourceTable = new DataTable();
DataTable checkTable;
if (Session[tempCacheName] != null)
{
sourceTable = (DataTable)Session[tempCacheName];
}
//strSql = " SELECT A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,A.AMOUNT - A.SETTLEMENT as SETTLEMENT,"
// + " A.AMOUNT - A.SETTLEMENT as UNSETTLE,A.INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT,A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO "
// + " FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN op_seae as E ON A.BSNO = E.BSNO "
// + " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceGID + "') AND A.SETTLEMENT <> A.AMOUNT AND A.GID = '" + tempVerifyFeeID + "' AND B.CATEGORY = 7";
//2013-02-05 修改
strSql = " SELECT A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,A.AMOUNT - A.SETTLEMENT as SETTLEMENT,"
+ " A.AMOUNT - A.SETTLEMENT as UNSETTLE,A.INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT,A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO,A.REMARK "
+ " FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN VW_Settlement as E ON A.BSNO = E.BSNO "
+ " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceGID + "') AND A.SETTLEMENT <> A.AMOUNT AND A.GID = '" + tempVerifyFeeID + "' AND B.CATEGORY = 7";
checkTable = invoiceDA.GetExcuteSql(strSql).Tables[0];
if (sourceTable.Rows.Count > 0)
{
for (int j = 0; j < checkTable.Rows.Count; j++)
{
int iCount = 0;
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (checkTable.Rows[j]["GID"].ToString().Equals(sourceTable.Rows[i]["GID"].ToString()))
{
iCount++;//如果有相同的记录,则只更新结算和未结算费用
sourceTable.Rows[i]["SETTLEMENT"] = dDoAmount.ToString();//结算金额
sourceTable.Rows[i]["UNSETTLE"] = dUnDoAmount.ToString();//未结算金额
break;
}
}
if (iCount == 0)
{
DataRow newDataRow = sourceTable.NewRow();
newDataRow["GID"] = checkTable.Rows[j]["GID"].ToString();
newDataRow["CUSTNO"] = checkTable.Rows[j]["CUSTNO"].ToString();
newDataRow["MBLNO"] = checkTable.Rows[j]["MBLNO"].ToString();
newDataRow["HBLNO"] = checkTable.Rows[j]["HBLNO"].ToString();
newDataRow["CUSTOMERNAME"] = checkTable.Rows[j]["CUSTOMERNAME"].ToString();
newDataRow["FEENAME"] = checkTable.Rows[j]["FEENAME"].ToString();
newDataRow["FEETYPE"] = checkTable.Rows[j]["FEETYPE"].ToString();
newDataRow["SETTLEMENT"] = dDoAmount.ToString();//checkTable.Rows[j]["SETTLEMENT"].ToString();
newDataRow["UNSETTLE"] = dUnDoAmount.ToString();//checkTable.Rows[j]["UNSETTLE"].ToString();
newDataRow["INVOICE"] = checkTable.Rows[j]["INVOICE"].ToString();
newDataRow["UNIT"] = checkTable.Rows[j]["UNIT"].ToString();
newDataRow["UNITPRICE"] = checkTable.Rows[j]["UNITPRICE"].ToString();
newDataRow["QUANTITY"] = checkTable.Rows[j]["QUANTITY"].ToString();
newDataRow["AMOUNT"] = checkTable.Rows[j]["AMOUNT"].ToString();
newDataRow["CURRENCY"] = checkTable.Rows[j]["CURRENCY"].ToString();
newDataRow["EXCHANGERATE"] = checkTable.Rows[j]["EXCHANGERATE"].ToString();
newDataRow["ENTERDATE"] = checkTable.Rows[j]["ENTERDATE"].ToString();
newDataRow["BSNO"] = checkTable.Rows[j]["BSNO"].ToString();
sourceTable.Rows.Add(newDataRow);
}
}
Session[tempCacheName] = sourceTable;
}
else
{
checkTable.Rows[0]["SETTLEMENT"] = dDoAmount.ToString();//结算金额
checkTable.Rows[0]["UNSETTLE"] = dUnDoAmount.ToString();//未结算金额
Session[tempCacheName] = checkTable;
sourceTable = (DataTable)Session[tempCacheName];
}
strResult = GetProfitValue(sourceTable, dExchangeRate, iExchangeType);
return strResult;
}
#endregion
#region 缓存选中的收费结算费用信息
/// <summary>
/// 缓存选中的收费结算费用信息
/// </summary>
/// <param name="tempInvoiceGID">发票GID</param>
/// <param name="tempVerifyFeeID">费用GID</param>
/// <param name="tempType">操作类型 1-选中单个费用 2-取消选中单个费用 3-选中全部费用 4-取消选中所有费用</param>
/// <param name="tempCacheName"></param>
/// <returns></returns>
private string CacheVerificationFee(string tempInvoiceGID,string tempVerifyFeeID,int tempType,string tempCacheName)
{
string strResult = "";
string strSql = "";
InvoiceDA invoiceDA = new InvoiceDA();
DataTable sourceTable = new DataTable();
DataTable checkTable;
if (Session[tempCacheName] != null)
{
sourceTable = (DataTable)Session[tempCacheName];
}
switch (tempType)
{
case 1://选中单个费用
//strSql = " SELECT A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as SETTLEMENT,"
// + " CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as UNSETTLE,B.DOAMOUNT as INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT,A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO "
// + " FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN op_seae as E ON A.BSNO = E.BSNO "
// + " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceGID + "') AND A.SETTLEMENT <> A.AMOUNT AND A.GID = '" + tempVerifyFeeID + "' AND B.CATEGORY = 7";
//strSql = " SELECT W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
// + " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO "
// + " FROM ch_fee as W INNER JOIN op_seae as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT "
// + " FROM (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B "
// + " ON A.BILLNO = B.BILLNO WHERE A.GID = '" + tempInvoiceGID + "') AS C "
// + " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETE,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D ON C.FEEID = D.FEEID "
// + " WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID WHERE W.GID = '" + tempVerifyFeeID + "'";
//2013-02-05 修改
strSql = " SELECT W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
+ " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO,W.REMARK "
+ " FROM ch_fee as W INNER JOIN VW_Settlement as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT "
+ " FROM (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B "
+ " ON A.BILLNO = B.BILLNO WHERE A.GID = '" + tempInvoiceGID + "') AS C "
+ " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
+ " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETED,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D ON C.FEEID = D.FEEID "
+ " WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID WHERE W.GID = '" + tempVerifyFeeID + "'";
checkTable = invoiceDA.GetExcuteSql(strSql).Tables[0];
if (sourceTable != null)
{
if (sourceTable.Rows.Count > 0)
{
DataRow newDataRow = sourceTable.NewRow();
newDataRow["GID"] = checkTable.Rows[0]["GID"].ToString();
newDataRow["CUSTNO"] = checkTable.Rows[0]["CUSTNO"].ToString();
newDataRow["MBLNO"] = checkTable.Rows[0]["MBLNO"].ToString();
newDataRow["HBLNO"] = checkTable.Rows[0]["HBLNO"].ToString();
newDataRow["CUSTOMERNAME"] = checkTable.Rows[0]["CUSTOMERNAME"].ToString();
newDataRow["FEENAME"] = checkTable.Rows[0]["FEENAME"].ToString();
newDataRow["FEETYPE"] = checkTable.Rows[0]["FEETYPE"].ToString();
newDataRow["SETTLEMENT"] = checkTable.Rows[0]["SETTLEMENT"].ToString();
newDataRow["UNSETTLE"] = checkTable.Rows[0]["UNSETTLE"].ToString();
newDataRow["INVOICE"] = checkTable.Rows[0]["INVOICE"].ToString();
newDataRow["UNIT"] = checkTable.Rows[0]["UNIT"].ToString();
newDataRow["UNITPRICE"] = checkTable.Rows[0]["UNITPRICE"].ToString();
newDataRow["QUANTITY"] = checkTable.Rows[0]["QUANTITY"].ToString();
newDataRow["AMOUNT"] = checkTable.Rows[0]["AMOUNT"].ToString();
newDataRow["CURRENCY"] = checkTable.Rows[0]["CURRENCY"].ToString();
newDataRow["EXCHANGERATE"] = checkTable.Rows[0]["EXCHANGERATE"].ToString();
newDataRow["ENTERDATE"] = checkTable.Rows[0]["ENTERDATE"].ToString();
newDataRow["BSNO"] = checkTable.Rows[0]["BSNO"].ToString();
sourceTable.Rows.Add(newDataRow);
Session[tempCacheName] = sourceTable;
}
else
{
Session[tempCacheName] = checkTable;
sourceTable = (DataTable)Session[tempCacheName];
}
}
else
{
Session[tempCacheName] = checkTable;
sourceTable = (DataTable)Session[tempCacheName];
}
break;
case 2://取消选中单个费用
int rowsCount = sourceTable.Rows.Count;
for (int i = 0; i < rowsCount; i++)
{
if (sourceTable.Rows[i]["GID"].ToString().Trim().Equals(tempVerifyFeeID))
{
sourceTable.Rows.RemoveAt(i);
break;
}
}
Session[tempCacheName] = sourceTable;
break;
case 3://选中全部费用
//strSql = " SELECT A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as SETTLEMENT,"
// + " CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as UNSETTLE,B.DOAMOUNT as INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT,A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO "
// + " FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN op_seae as E ON A.BSNO = E.BSNO "
// + " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceGID + "') AND A.SETTLEMENT <> A.AMOUNT AND B.CATEGORY = 7 ";
//2013-02-05 修改
strSql = " SELECT A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as SETTLEMENT,"
+ " CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as UNSETTLE,B.DOAMOUNT as INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT,A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO,A.REMARK "
+ " FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN VW_Settlement as E ON A.BSNO = E.BSNO "
+ " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceGID + "') AND A.SETTLEMENT <> A.AMOUNT ";//AND B.CATEGORY = 7 ";
checkTable = invoiceDA.GetExcuteSql(strSql).Tables[0];
if (sourceTable.Rows.Count > 0)
{
for (int j = 0; j < checkTable.Rows.Count; j++)
{
int iCount = 0;
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (checkTable.Rows[j]["GID"].ToString().Equals(sourceTable.Rows[i]["GID"].ToString()))
{
iCount++;//如果有相同的记录,则不覆盖,保留原数据
break;
}
}
if (iCount == 0)
{
DataRow newDataRow = sourceTable.NewRow();
newDataRow["GID"] = checkTable.Rows[j]["GID"].ToString();
newDataRow["CUSTNO"] = checkTable.Rows[j]["CUSTNO"].ToString();
newDataRow["MBLNO"] = checkTable.Rows[j]["MBLNO"].ToString();
newDataRow["HBLNO"] = checkTable.Rows[j]["HBLNO"].ToString();
newDataRow["CUSTOMERNAME"] = checkTable.Rows[j]["CUSTOMERNAME"].ToString();
newDataRow["FEENAME"] = checkTable.Rows[j]["FEENAME"].ToString();
newDataRow["FEETYPE"] = checkTable.Rows[j]["FEETYPE"].ToString();
newDataRow["SETTLEMENT"] = checkTable.Rows[j]["SETTLEMENT"].ToString();
newDataRow["UNSETTLE"] = checkTable.Rows[j]["UNSETTLE"].ToString();
newDataRow["INVOICE"] = checkTable.Rows[j]["INVOICE"].ToString();
newDataRow["UNIT"] = checkTable.Rows[j]["UNIT"].ToString();
newDataRow["UNITPRICE"] = checkTable.Rows[j]["UNITPRICE"].ToString();
newDataRow["QUANTITY"] = checkTable.Rows[j]["QUANTITY"].ToString();
newDataRow["AMOUNT"] = checkTable.Rows[j]["AMOUNT"].ToString();
newDataRow["CURRENCY"] = checkTable.Rows[j]["CURRENCY"].ToString();
newDataRow["EXCHANGERATE"] = checkTable.Rows[j]["EXCHANGERATE"].ToString();
newDataRow["ENTERDATE"] = checkTable.Rows[j]["ENTERDATE"].ToString();
newDataRow["BSNO"] = checkTable.Rows[j]["BSNO"].ToString();
sourceTable.Rows.Add(newDataRow);
}
}
Session[tempCacheName] = sourceTable;
}
else
{
Session[tempCacheName] = checkTable;
sourceTable = (DataTable)Session[tempCacheName];
}
break;
case 4://取消选中所有费用
Session.Remove(tempCacheName);
sourceTable = new DataTable();
break;
}
strResult = GetProfitValue(sourceTable,dExchangeRate,iExchangeType);
return strResult;
}
#endregion
private string GetProfitValue(DataTable tempDataTable,decimal tempExchangeRate,int tempSettleType)
{
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.Append("{");
jsonBuilder.Append("\"verify\":");
jsonBuilder.Append("[");
jsonBuilder.Append("{");
double totalRmb = 0;
double totalUsd = 0;
for (int i = 0; i < tempDataTable.Rows.Count; i++)
{
if (tempSettleType == 1)//按RMB结算
{
if (tempDataTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals("USD"))
{
if (tempDataTable.Rows[i]["FEETYPE"].ToString().Trim().ToUpper().Equals("收"))
{
double amountUsd = double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
double tempTotal = Round(amountUsd * double.Parse(tempExchangeRate.ToString()), 2);
totalRmb += tempTotal;
}
else
{
double amountUsd = double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
double tempTotal = Round(amountUsd * double.Parse(tempExchangeRate.ToString()), 2);
tempTotal = 0 - tempTotal;
totalRmb += tempTotal;
}
}
else if (tempDataTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals("RMB"))
{
if (tempDataTable.Rows[i]["FEETYPE"].ToString().Trim().ToUpper().Equals("收"))
{
double amountRmb = double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
totalRmb += amountRmb;
}
else
{
double amountRmb = double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
amountRmb = 0 - amountRmb;
totalRmb += amountRmb;
}
}
}
else if (tempSettleType == 2)//按USD结算
{
if (tempDataTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals("USD"))
{
if (tempDataTable.Rows[i]["FEETYPE"].ToString().Trim().ToUpper().Equals("收"))
{
double amountUsd = double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
totalUsd += amountUsd;
}
else
{
double amountUsd = double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
amountUsd = 0 - amountUsd;
totalUsd += amountUsd;
}
}
else if (tempDataTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals("RMB"))
{
if (tempDataTable.Rows[i]["FEETYPE"].ToString().Trim().ToUpper().Equals("收"))
{
double amountRmb = double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
double tempTotal = Round(amountRmb / double.Parse(tempExchangeRate.ToString()), 2);
totalUsd += tempTotal;
}
else
{
double amountRmb = double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
double tempTotal = Round(amountRmb / double.Parse(tempExchangeRate.ToString()), 2);
tempTotal = 0 - tempTotal;
totalUsd += tempTotal;
}
}
}
else if (tempSettleType == 3)//按照默认币别计算
{
if (tempDataTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals("USD"))
{
if (tempDataTable.Rows[i]["FEETYPE"].ToString().Trim().ToUpper().Equals("收"))
{
totalUsd += double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
}
else
{
double tempTotal = double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
tempTotal = 0 - tempTotal;
totalUsd += tempTotal;
}
}
else if (tempDataTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals("RMB"))
{
if (tempDataTable.Rows[i]["FEETYPE"].ToString().Trim().ToUpper().Equals("收"))
{
totalRmb += double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
}
else
{
double tempTotal = double.Parse(tempDataTable.Rows[i]["SETTLEMENT"].ToString());
tempTotal = 0 - tempTotal;
totalRmb += tempTotal;
}
}
}
}
jsonBuilder.Append("\"rmb\":" + totalRmb + ",");
jsonBuilder.Append("\"usd\":" + totalUsd + ",");
jsonBuilder.Append("\"state\":1");
jsonBuilder.Append("}");
jsonBuilder.Append("]");
jsonBuilder.Append("}");
return jsonBuilder.ToString();
}
#region 四舍五入
/// <summary>
/// 四舍五入
/// </summary>
/// <param name="v">处理数据</param>
/// <param name="x">保留有效小数位数</param>
/// <returns>返回四舍五入后的数值</returns>
private double Round(double v, int x)
{
bool isNegative = false;
//如果是负数
if (v < 0)
{
isNegative = true;
v = -v;
}
int IValue = 1;
for (int i = 1; i <= x; i++)
{
IValue = IValue * 10;
}
double Int = Math.Round(v * IValue + 0.5, 0);
v = Int / IValue;
if (isNegative)
{
v = -v;
}
return v;
}
#endregion
#region 获取已开票但未收费的费用明细信息总页数
/// <summary>
/// 获取未结算发票信息
/// </summary>
/// <returns></returns>
private int GetUnverificationFeeListPage(string tempInvoiceID)
{
InvoiceDA invoiceDA = new InvoiceDA();
string strCondition = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.ENTERDATE,20) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.ENTERDATE,20) <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND A.FEENAME LIKE '%{0}%'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
}
//string strAuthorityCondition = "";
//UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
//if (userAuthorityManage.OperateType != AuthorityType.NULL)
//{
// strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEMAKEOUT, strShowName, strCompanyID, strDeptName, strUserID);
//}
string strSql = String.Format(" select count(*) from (SELECT W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
+ " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO "
+ " FROM ch_fee as W INNER JOIN VW_Settlement as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
+ " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID = '{0}') AS C "
+ " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
+ " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETED,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
+ " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID {1}) as L ", tempInvoiceID, strCondition);
int iTotal = int.Parse(invoiceDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
#region 获取已开票但未收费的费用明细信息
/// <summary>
/// 获取已开票但未收费的费用明细信息
/// </summary>
/// <returns></returns>
private string GetUnverificationFeeList(string tempInvoiceID)
{
InvoiceDA invoiceDA = new InvoiceDA();
DataTable sourceTable;
string strCondition = "";
string strIncludeCondition = "";
string strTopInclude = "";
string strTopNotInclude = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.ENTERDATE,20) >= '{0}' ", strArg[1].Replace("\"", ""));
strIncludeCondition += String.Format(" AND convert(char(10),C.ENTERDATE,20) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.ENTERDATE,20) <= '{0}' ", strArg[1].Replace("\"", ""));
strIncludeCondition += String.Format(" AND convert(char(10),C.ENTERDATE,20) <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
strIncludeCondition += String.Format(" AND C.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND A.FEENAME LIKE '%{0}%'", strArg[1].Replace("\"", ""));
strIncludeCondition += String.Format(" AND C.FEENAME LIKE '%{0}%'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
}
//string strAuthorityCondition = "";
//UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
//if (userAuthorityManage.OperateType != AuthorityType.NULL)
//{
// strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEMAKEOUT, strShowName, strCompanyID, strDeptName, strUserID);
//}
string strSql = "";
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
//strSql = String.Format("SELECT {0} A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as SETTLEMENT,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as UNSETTLE,B.DOAMOUNT as INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT, "
// + " A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN op_seae as E ON A.BSNO = E.BSNO "
// + " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceID + "') AND A.SETTLEMENT <> A.AMOUNT "
// + strCondition + " ORDER BY A.ENTERDATE DESC ", "top " + iShowPage.ToString());
//strSql = String.Format(" SELECT {0} W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
// + " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO "
// + " FROM ch_fee as W INNER JOIN op_seae as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
// + " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID = '" + tempInvoiceID + "') AS C "
// + " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETE,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
// + " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID " + strCondition + " ORDER BY W.ENTERDATE DESC ", "top " + iShowPage.ToString());
//strSql = String.Format(" SELECT {0} W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
// + " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO "
// + " FROM ch_fee as W INNER JOIN op_seae as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
// + " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID = {0}) AS C "
// + " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETE,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
// + " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID {1} ", " top {2} "
// //+ " ORDER BY W.ENTERDATE DESC "
// + " union all "
// + " SELECT {0} W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
// + " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO "
// + " FROM ch_fee as W INNER JOIN op_seai as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
// + " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID = {0}) AS C "
// + " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETE,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
// + " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID {1} ORDER BY W.ENTERDATE DESC ", " top {2} "
// , tempInvoiceID, strCondition, iShowPage.ToString());
//2013-02-05 修改
//if (iShowPage.ToString().Trim() != "")
//{
// strTopInclude = "top " + iShowPage.ToString();
//}
strTopInclude = "";
strSql = String.Format(" SELECT {0} W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
+ " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO,W.REMARK "
+ " FROM ch_fee as W INNER JOIN VW_Settlement as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
+ " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID = '{1}') AS C "
+ " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
+ " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETED,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
+ " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID {2} ORDER BY W.ENTERDATE DESC ", strTopInclude, tempInvoiceID, strCondition);
}
else
{
strTopNotInclude = "top " + (iShowPage * (iCurrentPage - 1)).ToString();//RowCount*PageNum
strTopInclude = "top " + iShowPage.ToString();
//strSql = String.Format(" SELECT {0} A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as SETTLEMENT,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as UNSETTLE,B.DOAMOUNT as INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT, "
// + " A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN op_seae as E ON A.BSNO = E.BSNO "
// + " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceID + "') AND A.SETTLEMENT <> A.AMOUNT "
// + " AND A.GID NOT IN "
// + " (SELECT {1} C.GID FROM ch_fee as C INNER JOIN ch_fee_do as D ON C.GID = D.FEEID "
// + " WHERE BILLNO IN (SELECT BILLNO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceID + "') AND C.SETTLEMENT <> C.AMOUNT " + strIncludeCondition + " ORDER BY ENTERDATE DESC)"
// + strCondition + " ORDER BY A.ENTERDATE DESC ", strTopInclude, strTopNotInclude);
//strSql = String.Format(" SELECT {0} W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
// + " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO "
// + " FROM ch_fee as W INNER JOIN op_seae as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
// + " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID = '" + tempInvoiceID + "') AS C "
// + " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETE,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
// + " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID "
// + " WHERE W.GID NOT IN( "
// + " SELECT {1} GID FROM ch_fee as W INNER JOIN op_seae as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
// + " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID = '" + tempInvoiceID + "') AS C "
// + " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETE,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
// + " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID ORDER BY ENTERDATE DESC) "
// + strCondition + " ORDER BY W.ENTERDATE DESC ", strTopInclude, strTopNotInclude);
//strSql = String.Format(" SELECT {0} W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
// + " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO "
// + " FROM ch_fee as W INNER JOIN op_seae as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
// + " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID ={0} ) AS C "
// + " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETE,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
// + " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID "
// + " WHERE W.GID NOT IN( "
// + " SELECT {0} GID FROM ch_fee as W INNER JOIN op_seae as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
// + " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID ={0} ) AS C "
// + " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETE,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
// + " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID ORDER BY ENTERDATE DESC) {1} "
// //+ " ORDER BY W.ENTERDATE DESC "
// + " union all "
// + " SELECT {0} W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
// + " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO "
// + " FROM ch_fee as W INNER JOIN op_seai as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
// + " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID ={0} ) AS C "
// + " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETE,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
// + " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID "
// + " WHERE W.GID NOT IN( "
// + " SELECT {0} GID FROM ch_fee as W INNER JOIN op_seai as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
// + " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID ={0} ) AS C "
// + " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETE,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
// + " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID ORDER BY ENTERDATE DESC) {1} "
// + " ORDER BY W.ENTERDATE DESC "
// , tempInvoiceID, strCondition, strTopInclude, strTopNotInclude);
//2013-02-05 修改
strSql = String.Format(" SELECT {2} W.GID,E.CUSTNO,E.MBLNO,E.HBLNO,W.CUSTOMERNAME,W.FEENAME,CASE WHEN W.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE, "
+ " F.TOTALAMOUNT as SETTLEMENT,F.TOTALAMOUNT as UNSETTLE,F.DOAMOUNT as INVOICE,W.UNIT,W.UNITPRICE,W.QUANTITY,W.AMOUNT,W.CURRENCY,W.EXCHANGERATE,W.ENTERDATE,W.BSNO,W.REMARK "
+ " FROM ch_fee as W INNER JOIN VW_Settlement as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
+ " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID ='{0}' ) AS C "
+ " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
+ " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETED,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
+ " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID "
+ " WHERE W.GID NOT IN( "
+ " SELECT {3} GID FROM ch_fee as W INNER JOIN VW_Settlement as E ON W.BSNO = E.BSNO INNER JOIN (SELECT C.FEEID,(C.DOAMOUNT - ISNULL(D.TOTALAMOUNT,0)) as TOTALAMOUNT,C.DOAMOUNT FROM "
+ " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO WHERE A.GID ='{0}' ) AS C "
+ " LEFT JOIN (SELECT B.FEEID,SUM(ISNULL(B.DOAMOUNT,0)) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
+ " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETED,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
+ " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - ISNULL(TOTALAMOUNT,0)) <> 0)) AS F ON W.GID = F.FEEID ORDER BY ENTERDATE DESC) {1} "
+ " ORDER BY W.ENTERDATE DESC ", tempInvoiceID, strCondition, strTopInclude, strTopNotInclude);
}
}
else
{
//strSql = String.Format("SELECT A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as SETTLEMENT,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as UNSETTLE,B.DOAMOUNT as INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT, "
// + " A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN op_seae as E ON A.BSNO = E.BSNO "
// + " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceID + "') AND A.SETTLEMENT <> A.AMOUNT "
// + strCondition + " ORDER BY A.ENTERDATE DESC ");
//strSql = String.Format("SELECT A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as SETTLEMENT,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as UNSETTLE,B.DOAMOUNT as INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT, "
// + " A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN op_seae as E ON A.BSNO = E.BSNO "
// + " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID ={0} ) AND A.SETTLEMENT <> A.AMOUNT {1} "
// //+ " ORDER BY A.ENTERDATE DESC "
// + " union all "
// + "SELECT A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as SETTLEMENT,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as UNSETTLE,B.DOAMOUNT as INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT, "
// + " A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN op_seai as E ON A.BSNO = E.BSNO "
// + " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID ={0} ) AND A.SETTLEMENT <> A.AMOUNT {1} "
// + " ORDER BY A.ENTERDATE DESC "
// , tempInvoiceID, strCondition);
//2013-02-05 修改
strSql = String.Format("SELECT A.GID,E.CUSTNO,E.MBLNO,E.HBLNO,A.CUSTOMERNAME,A.FEENAME,CASE WHEN A.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as SETTLEMENT,CASE WHEN B.AMOUNT <> B.DOAMOUNT THEN B.DOAMOUNT ELSE A.AMOUNT - A.SETTLEMENT END as UNSETTLE,B.DOAMOUNT as INVOICE,A.UNIT,A.UNITPRICE,A.QUANTITY,A.AMOUNT, "
+ " A.CURRENCY,A.EXCHANGERATE,A.ENTERDATE,A.BSNO,A.REMARK FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID INNER JOIN VW_Settlement as E ON A.BSNO = E.BSNO "
+ " WHERE B.BILLNO IN ( SELECT BILLNO FROM ch_fee_invoice WHERE GID ='{0}' ) AND A.SETTLEMENT <> A.AMOUNT {1} "
+ " ORDER BY A.ENTERDATE DESC ", tempInvoiceID, strCondition);
}
sourceTable = getBillStatusNameTable(invoiceDA.GetExcuteSql(strSql).Tables[0]);
DataTable cacheTable;
if (Session[strCacheName] != null)
{
cacheTable = (DataTable)Session[strCacheName];
}
else
{
cacheTable = new DataTable();
}
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
if (cacheTable.Rows.Count > 0)
{
int iCount = 0;
for (int j = 0; j < cacheTable.Rows.Count; j++)
{
if (sourceTable.Rows[i]["GID"].ToString().Equals(cacheTable.Rows[j]["GID"].ToString()))
{
sourceBuilder.Append("\"1\",");
sourceTable.Rows[i]["SETTLEMENT"] = cacheTable.Rows[j]["SETTLEMENT"].ToString();
sourceTable.Rows[i]["UNSETTLE"] = cacheTable.Rows[j]["UNSETTLE"].ToString();
iCount++;
break;
}
}
if (iCount == 0)
{
sourceBuilder.Append("\"0\",");
}
}
else
{
sourceBuilder.Append("\"0\",");
}
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 获取未结算发票总页数
/// <summary>
/// 获取未结算发票信息
/// </summary>
/// <returns></returns>
private int GetUnverificationListPage()
{
InvoiceDA invoiceDA = new InvoiceDA();
string strCondition = "";
//string strAuthorityCondition = "";
//UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
//if (userAuthorityManage.OperateType != AuthorityType.NULL)
//{
// strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEMAKEOUT, strShowName, strCompanyID, strDeptName, strUserID);
// strSql += strAuthorityCondition;
//}
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND (A.BILLNO LIKE '%{0}%' or A.INVOICENO LIKE '%{0}%' or A.MBLNO LIKE '%{0}%')", strArg[1].Replace("\"", ""));// or B.MBLNO LIKE '%{0}%'
break;
default:
break;
}
}
}
//strSql += strCondition;
}
}
//string strSql = " SELECT COUNT(*) FROM ch_fee_invoice as A "
// + " WHERE A.BILLNO IN (SELECT B.BILLNO FROM ch_fee_do as B INNER JOIN ch_fee as C ON B.FEEID = C.GID WHERE (ISNULL(C.SETTLEMENT,0) < C.AMOUNT AND ISNULL(C.SETTLEMENT,0) < ISNULL(C.INVOICE,0))"
// + " OR (ISNULL(C.SETTLEMENT,0) = 0 AND ISNULL(C.INVOICE,0) > 0))";
//string strSql = " SELECT COUNT(A.GID) FROM ch_fee_invoice as A "
// + " INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO LEFT JOIN [user] as C ON A.APPLICANT = C.GID LEFT JOIN [user] as D ON A.OPERATOR = D.GID"
// + " LEFT JOIN (SELECT SUM(ISNULL(DOAMOUNT,0)) AS TOTALAMOUNT,INVOICESETTLENO "
// + " FROM ch_fee_settlement as E INNER JOIN ch_fee_do as F ON E.BILLNO = F.BILLNO GROUP BY INVOICESETTLENO) AS L "
// + " ON A.BILLNO = L.INVOICESETTLENO "
// + " WHERE B.FEEID IN (SELECT GID FROM ch_fee WHERE (ISNULL(B.DOAMOUNT,0) - ISNULL(L.TOTALAMOUNT,0) <> 0) "
// + " AND ((ISNULL(SETTLEMENT,0) < AMOUNT AND ISNULL(SETTLEMENT,0) < ISNULL(INVOICE,0)) OR (ISNULL(SETTLEMENT,0) = 0 AND ISNULL(INVOICE,0) > 0))) ";
//string strSql = " SELECT COUNT(*) FROM ch_fee_invoice as A "
// + " LEFT JOIN [user] AS E ON A.APPLICANT = E.GID LEFT JOIN [user] as F ON A.OPERATOR = F.GID WHERE A.BILLNO NOT IN( "
// + " SELECT BILLNO FROM (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO) AS C "
// + " INNER JOIN (SELECT B.FEEID,SUM(B.DOAMOUNT) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
// + " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETED,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
// + " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - TOTALAMOUNT) = 0)) ";
string strSql = " SELECT COUNT(*) FROM ch_fee_invoice as A "
+ " LEFT JOIN [user] AS E ON A.APPLICANT = E.GID LEFT JOIN [user] as F ON A.OPERATOR = F.GID WHERE A.BILLNO NOT IN( "
+ " SELECT BILLNO FROM (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO) AS C "
+ " INNER JOIN (SELECT B.FEEID,SUM(B.DOAMOUNT) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
+ " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETED,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
+ " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - TOTALAMOUNT) = 0)) "
+ " and A.BILLNO IN(select billno from ch_fee_do where feeid in (select gid from ch_fee)) "
+ strCondition;
int iTotal = int.Parse(invoiceDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
private string GetUnverificationInvoice()
{
InvoiceDA invoiceDA = new InvoiceDA();
DataTable sourceTable;
string strCondition = "";
string strTopInclude = "";
string strTopNotInclude = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND (A.BILLNO LIKE '%{0}%' or A.INVOICENO LIKE '%{0}%' or A.MBLNO LIKE '%{0}%')", strArg[1].Replace("\"", ""));// or B.MBLNO LIKE '%{0}%'
break;
default:
break;
}
}
}
}
}
//string strAuthorityCondition = "";
//UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
//if (userAuthorityManage.OperateType != AuthorityType.NULL)
//{
// strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEMAKEOUT, strShowName, strCompanyID, strDeptName, strUserID);
//}
string strSql = "";
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
//strSql = String.Format(" SELECT {0} A.GID,A.INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN 1 ELSE 0 END,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END,"
// + " A.INVOICENO,A.CUSTOMERNAME,A.INVOICECUSTNAME,(ISNULL(B.DOAMOUNT,0) - ISNULL(L.TOTALAMOUNT,0)) AS AMOUNT,A.CURRENCY,C.SHOWNAME,A.APPLYTIME,D.SHOWNAME,A.OPERATETIME FROM ch_fee_invoice as A "
// + " INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO LEFT JOIN [user] as C ON A.APPLICANT = C.GID LEFT JOIN [user] as D ON A.OPERATOR = D.GID"
// + " LEFT JOIN (SELECT SUM(ISNULL(DOAMOUNT,0)) AS TOTALAMOUNT,INVOICESETTLENO "
// + " FROM ch_fee_settlement as E INNER JOIN ch_fee_do as F ON E.BILLNO = F.BILLNO GROUP BY INVOICESETTLENO) AS L "
// + " ON A.BILLNO = L.INVOICESETTLENO "
// + " WHERE B.FEEID IN (SELECT GID FROM ch_fee WHERE (ISNULL(B.DOAMOUNT,0) - ISNULL(L.TOTALAMOUNT,0) <> 0) "
// + " AND ((ISNULL(SETTLEMENT,0) < AMOUNT AND ISNULL(SETTLEMENT,0) < ISNULL(INVOICE,0)) OR (ISNULL(SETTLEMENT,0) = 0 AND ISNULL(INVOICE,0) > 0))) "
// + strCondition + " ORDER BY A.BILLNO DESC ", "top " + iShowPage.ToString());
strSql = String.Format(" SELECT {0} A.GID,A.INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN 1 ELSE 0 END,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END,"
+ " A.INVOICENO,A.MBLNO,A.CUSTOMERNAME,A.INVOICECUSTNAME,A.AMOUNT,A.CURRENCY,E.SHOWNAME,A.APPLYTIME,F.SHOWNAME,A.OPERATETIME FROM ch_fee_invoice as A "
+ " LEFT JOIN [user] AS E ON A.APPLICANT = E.GID LEFT JOIN [user] as F ON A.OPERATOR = F.GID WHERE A.BILLNO NOT IN( "
+ " SELECT BILLNO FROM (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO) AS C "
+ " INNER JOIN (SELECT B.FEEID,SUM(B.DOAMOUNT) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
+ " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETED,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
+ " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - TOTALAMOUNT) = 0)) "
+ " and A.BILLNO IN(select billno from ch_fee_do where feeid in (select gid from ch_fee)) "
+ strCondition + " ORDER BY A.BILLNO DESC ", "top " + iShowPage.ToString());
}
else
{
strTopNotInclude = "top " + (iShowPage * (iCurrentPage - 1)).ToString();//RowCount*PageNum
strTopInclude = "top " + iShowPage.ToString();
strSql = String.Format(" SELECT {0} A.GID,A.INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN 1 ELSE 0 END,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END,"
+ " A.INVOICENO,A.MBLNO,A.CUSTOMERNAME,A.INVOICECUSTNAME,A.AMOUNT,A.CURRENCY,E.SHOWNAME,A.APPLYTIME,F.SHOWNAME,A.OPERATETIME FROM ch_fee_invoice as A "
+ " LEFT JOIN [user] AS E ON A.APPLICANT = E.GID LEFT JOIN [user] as F ON A.OPERATOR = F.GID WHERE A.BILLNO NOT IN( "
+ " SELECT BILLNO FROM (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO) AS C "
+ " INNER JOIN (SELECT B.FEEID,SUM(B.DOAMOUNT) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
+ " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETED,0) <> 1 GROUP BY INVOICESETTLENO,FEEID ) AS D "
+ " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - TOTALAMOUNT) = 0)) "
+ " and A.BILLNO IN(select billno from ch_fee_do where feeid in (select gid from ch_fee)) "
+ " AND A.GID NOT IN (SELECT {1} GID FROM ch_fee_invoice WHERE BILLNO NOT IN( SELECT BILLNO FROM "
+ " (SELECT B.FEEID,B.AMOUNT,B.DOAMOUNT,B.BILLNO,INVOICESETTLENO FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO) AS C "
+ " INNER JOIN (SELECT B.FEEID,SUM(B.DOAMOUNT) AS TOTALAMOUNT FROM ch_fee_settlement as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
+ " WHERE INVOICESETTLENO IS NOT NULL AND ISNULL(B.ISDELETED,0) <> 1 GROUP BY INVOICESETTLENO,FEEID) AS D "
+ " ON C.FEEID = D.FEEID WHERE ((ISNULL(C.DOAMOUNT,0) - TOTALAMOUNT) = 0))"
+ " and A.BILLNO IN(select billno from ch_fee_do where feeid in (select gid from ch_fee))"
+ " ORDER BY BILLNO DESC ) "
+ " ORDER BY A.BILLNO DESC ", strTopInclude, strTopNotInclude);
}
}
else
{
strSql = " SELECT A.GID,A.INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN 1 ELSE 0 END,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END, A.INVOICENO,A.MBLNO,A.CUSTOMERNAME,A.INVOICECUSTNAME,A.AMOUNT,A.CURRENCY,E.SHOWNAME,A.APPLYTIME,F.SHOWNAME,A.OPERATETIME FROM ch_fee_invoice as A LEFT JOIN [user] as B ON A.APPLICANT = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1<0 ";
}
sourceTable = getBillStatusNameTable(invoiceDA.GetExcuteSql(strSql).Tables[0]);
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#region 验证用户是否有提交发票申请的权限
/// <summary>
/// 验证用户是否有开发票的权限
/// </summary>
/// <returns>值1表示有权限发票 值不等于1表示没有权限开发票</returns>
private int ValidateUserInvoiceApplicationAuthority()
{
int iResult = 0;
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppList");
if (userAuthorityManage.OperateType != AuthorityType.NULL && userAuthorityManage.OperateType != AuthorityType.NONE)
{
iResult = 1;
}
else
{
iResult = -1;
}
return iResult;
}
#endregion
#region 验证用户是否有开发票的权限
/// <summary>
/// 验证用户是否有开发票的权限
/// </summary>
/// <returns>值1表示有权限发票 值不等于1表示没有权限开发票</returns>
private int ValidateUserMakeOutAuthority()
{
int iResult = 0;
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
if (userAuthorityManage.OperateType != AuthorityType.NULL && userAuthorityManage.OperateType != AuthorityType.NONE)
{
iResult = 1;
}
else
{
iResult = -1;
}
return iResult;
}
#endregion
#region 获取已开出发票页总数
/// <summary>
/// 获取已开出发票页总数
/// </summary>
/// <returns>返回总页数</returns>
private int GetMakeOutListPage()
{
InvoiceDA invoiceDA = new InvoiceDA();
string strCondition = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND (A.BILLNO LIKE '%{0}%' OR A.INVOICENO LIKE '%{0}%' OR A.MBLNO LIKE '%{0}%') ", strArg[1].Replace("\"", ""));
break;
case "amount1"://
strCondition += String.Format(" AND A.AMOUNT >= '{0}'", strArg[1].Replace("\"", ""));
break;
case "amount2"://
strCondition += String.Format(" AND A.AMOUNT <= '{0}'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
}
string strAuthorityCondition = "";
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEMAKEOUT, strShowName, strCompanyID, strDeptName,strUserID);
}
//
string strSql = "select count(*) FROM ch_fee_invoice as A LEFT JOIN [user] as B ON A.APPLICANT = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1>0 " + strAuthorityCondition + strCondition;
int iTotal = int.Parse(invoiceDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
#region 获取已开票费用明细信息
/// <summary>
/// 获取已开票费用明细信息
/// </summary>
/// <param name="tempInvoiceGID">发票GID</param>
/// <returns>JSON数据集</returns>
private string GetInvoiceMakeOutEditFeeByGID(string tempInvoiceGID,string tempBSNO)
{
InvoiceDA invoiceDA = new InvoiceDA();
string strConditionBSNO = tempBSNO.Trim() == "" ? "" : " AND C.BSNO = '" + tempBSNO + "'";
string strSql = "";
if (tempBSNO.Trim().ToLower().Equals("handmakeout"))
{
strSql = " SELECT B.GID,'收',B.FEENAME,A.CUSTOMERNAME,'',B.DOAMOUNT,1,B.DOAMOUNT,A.CURRENCY,1,B.DOAMOUNT,0,C.REMARK "
+ " FROM ch_fee_invoice as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO INNER JOIN ch_fee as C ON A.FEEID = C.GID WHERE A.GID = '" + tempInvoiceGID + "' ";
}
else
{
strSql = " SELECT C.GID,CASE WHEN C.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,C.FEENAME,C.CUSTOMERNAME,C.UNIT, "
+ " C.UNITPRICE,C.QUANTITY,C.AMOUNT,C.CURRENCY,C.EXCHANGERATE,ISNULL(C.INVOICE,0) as INVOICE,C.AMOUNT - ISNULL(C.INVOICE,0) as UNINVOICE,C.REMARK "
+ " FROM ch_fee_do as A INNER JOIN ch_fee_invoice as B ON A.BILLNO = B.BILLNO INNER JOIN ch_fee as C ON A.FEEID = C.GID WHERE B.GID = '" + tempInvoiceGID + "' "
+ strConditionBSNO + " ";
}
DataTable invoiceTable = new DataTable();
invoiceTable = invoiceDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < invoiceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + invoiceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < invoiceTable.Columns.Count; j++)
{
if (j == invoiceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + invoiceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + invoiceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == invoiceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 获取申请开票费用明细信息
/// <summary>
/// 获取申请开票费用明细信息
/// </summary>
/// <param name="tempInvoiceAppGID">发票申请GID</param>
/// <param name="tempBSNO">委托编号BSNO</param>
/// <returns>JSON数据集</returns>
private string GetInvoiceApplicationEditFeeByGID(string tempInvoiceAppGID, string tempBSNO)
{
InvoiceDA invoiceDA = new InvoiceDA();
string strConditionBSNO = tempBSNO.Trim() == "" ? "" : " AND C.BSNO = '" + tempBSNO + "'";
string strSql = " SELECT C.GID,CASE WHEN C.FEETYPE = 1 THEN '收' ELSE '付' END as FEETYPE,C.FEENAME,C.CUSTOMERNAME,C.UNIT, "
+ " C.UNITPRICE,C.QUANTITY,C.AMOUNT,C.CURRENCY,C.EXCHANGERATE,ISNULL(C.ORDERINVOICE,0) as ORDERINVOICE,C.AMOUNT - ISNULL(C.ORDERINVOICE,0) as UNORDERINVOICE,C.REMARK "
+ " FROM ch_fee_do as A INNER JOIN ch_fee_invoiceapplication as B ON A.BILLNO = B.BILLNO INNER JOIN ch_fee as C ON A.FEEID = C.GID WHERE B.GID = '" + tempInvoiceAppGID + "' "
+ strConditionBSNO + " AND A.CATEGORY = 6 ";
DataTable invoiceTable = new DataTable();
invoiceTable = invoiceDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < invoiceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + invoiceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < invoiceTable.Columns.Count; j++)
{
if (j == invoiceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + invoiceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + invoiceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == invoiceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 更改本次结算费用金额
/// <summary>
/// 更改本次结算费用金额
/// </summary>
/// <param name="tempCacheName">费用缓存名称</param>
/// <param name="tempFeeID">费用GID</param>
/// <param name="tempCSTL">本次结算金额</param>
/// <param name="tempUSTL">未结算金额</param>
/// <param name="tempBsnoCacheName">委托缓存名称</param>
/// <param name="tempTotalCacheName">合计缓存名称</param>
/// <param name="tempBSNO">委托编号</param>
/// <returns>返回金额合计总数</returns>
private string ChangeFeeCstl(string tempCacheName, string tempFeeID, decimal tempCSTL, decimal tempUSTL, string tempBsnoCacheName, string tempTotalCacheName, string tempBSNO)
{
string strResult = "";
DataTable feeTable = (DataTable)Session[tempCacheName] ?? CreateFeeTable();
DataTable bsnoTable = (DataTable)Session[tempBsnoCacheName] ?? CreateBsnoTable();
DataTable totalTable = (DataTable)Session[tempTotalCacheName] ?? CreateTotalTable();
int iAuthorityStatus = 0;
if (strDoTypeName == "app")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppSearch");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEAPPSEARCH, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, strBSNO, "", strUserID);
}
if (iAuthorityStatus != 1)
{
if (Session[tempCacheName] != null)
{
feeTable = (DataTable)Session[tempCacheName];
}
strResult = GetSumFeeJson(feeTable, -1,0,false);
return strResult;
}
}
else if (strDoTypeName == "import")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceImport");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEIMPORT, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, strBSNO, "", strUserID);
}
if (iAuthorityStatus != 1)
{
if (Session[tempCacheName] != null)
{
feeTable = (DataTable)Session[tempCacheName];
}
strResult = GetSumFeeJson(feeTable, -1,0,false);
return strResult;
}
}
#region ####
//if (Session[tempOrderCacheName] != null)
//{
// feeTable = (DataTable)Session[tempOrderCacheName];
// int iCount = 0;
// if (feeTable.Rows.Count > 0)
// {
// for (int i = 0; i < feeTable.Rows.Count; i++)
// {
// if (feeTable.Rows[i]["GID"].ToString().Equals(tempFeeID))
// {
// feeTable.Rows[i]["CTL"] = tempCSTL.ToString();
// feeTable.Rows[i]["UCTL"] = tempUSTL.ToString();
// iCount++;
// break;
// }
// }
// }
// if (iCount > 0)
// {
// Session[tempOrderCacheName] = feeTable;
// }
// else
// {
// string strSql = String.Format("SELECT GID,BSNO,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT, "
// + " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
// + " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END as CTL, "
// + " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
// + " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END as UCTL FROM ch_fee WHERE GID = '{0}'", tempFeeID);
// DataTable sourceTable = new DataTable();
// FeeDA feeDA = new FeeDA();
// sourceTable = feeDA.GetFeeListByCondition(strSql).Tables[0];
// if (sourceTable.Rows.Count > 0)
// {
// sourceTable.Rows[0]["CTL"] = tempCSTL.ToString();
// sourceTable.Rows[0]["UCTL"] = tempUSTL.ToString();
// }
// DataRow newRow = feeTable.NewRow();
// newRow["GID"] = sourceTable.Rows[0]["GID"].ToString();
// newRow["BSNO"] = sourceTable.Rows[0]["BSNO"].ToString();
// newRow["FEETYPE"] = sourceTable.Rows[0]["FEETYPE"].ToString();
// newRow["CUSTOMERNAME"] = sourceTable.Rows[0]["CUSTOMERNAME"].ToString();
// newRow["FEENAME"] = sourceTable.Rows[0]["FEENAME"].ToString();
// newRow["CURRENCY"] = sourceTable.Rows[0]["CURRENCY"].ToString();
// newRow["AMOUNT"] = sourceTable.Rows[0]["AMOUNT"].ToString();
// newRow["CTL"] = sourceTable.Rows[0]["CTL"].ToString();
// newRow["UCTL"] = sourceTable.Rows[0]["UCTL"].ToString();
// feeTable.Rows.Add(newRow);
// Session[tempOrderCacheName] = feeTable;
// }
// strResult = GetSumFeeJson(feeTable,1);
//}
//else
//{
// string strSql = String.Format("SELECT GID,BSNO,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT, "
// + " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
// + " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END as CTL, "
// + " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
// + " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END as UCTL FROM ch_fee WHERE GID = '{0}'", tempFeeID);
// DataTable sourceTable = new DataTable();
// FeeDA feeDA = new FeeDA();
// sourceTable = feeDA.GetFeeListByCondition(strSql).Tables[0];
// if (sourceTable.Rows.Count > 0)
// {
// sourceTable.Rows[0]["CTL"] = tempCSTL.ToString();
// sourceTable.Rows[0]["UCTL"] = tempUSTL.ToString();
// }
// Session[tempOrderCacheName] = sourceTable;
// strResult = GetSumFeeJson(sourceTable,1);
//}
//return strResult;
#endregion
int iCount = 0;
if (feeTable.Rows.Count > 0)
{
for (int i = 0; i < feeTable.Rows.Count; i++)
{
if (feeTable.Rows[i]["GID"].ToString().Equals(tempFeeID))
{
feeTable.Rows[i]["CTL"] = tempCSTL.ToString();
feeTable.Rows[i]["UCTL"] = tempUSTL.ToString();
iCount++;
break;
}
}
}
if (iCount > 0)
{
Session[tempCacheName] = feeTable;
}
else
{
DataTable sourceTable = GetSimpleFeeByGID(tempFeeID);
if (sourceTable.Rows.Count > 0)
{
sourceTable.Rows[0]["CTL"] = tempCSTL.ToString();
sourceTable.Rows[0]["UCTL"] = tempUSTL.ToString();
}
DataRow newRow = feeTable.NewRow();
newRow["GID"] = sourceTable.Rows[0]["GID"].ToString();
newRow["BSNO"] = sourceTable.Rows[0]["BSNO"].ToString();
newRow["FEETYPE"] = sourceTable.Rows[0]["FEETYPE"].ToString();
newRow["CUSTOMERNAME"] = sourceTable.Rows[0]["CUSTOMERNAME"].ToString();
newRow["FEENAME"] = sourceTable.Rows[0]["FEENAME"].ToString();
newRow["CURRENCY"] = sourceTable.Rows[0]["CURRENCY"].ToString();
newRow["AMOUNT"] = sourceTable.Rows[0]["AMOUNT"].ToString();
newRow["CTL"] = sourceTable.Rows[0]["CTL"].ToString();
newRow["UCTL"] = sourceTable.Rows[0]["UCTL"].ToString();
feeTable.Rows.Add(newRow);
Session[tempCacheName] = feeTable;
strResult = GetSumFeeJson(feeTable, 1, 1, false);
}
int iBsnoCount = 0;
for (int j = 0; j < bsnoTable.Rows.Count; j++)
{
if (bsnoTable.Rows[j]["BSNO"].ToString().Trim().Equals(tempBSNO))
{
iBsnoCount++;
break;
}
}
if (iBsnoCount == 0)
{
//BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO
DataTable sourceTable = GetOrderTable(strSearch, tempBSNO);
DataRow newRow = bsnoTable.NewRow();
newRow["BSNO"] = sourceTable.Rows[0]["BSNO"].ToString();
newRow["CUSTOMERNAME"] = sourceTable.Rows[0]["CUSTOMERNAME"].ToString();
newRow["CUSTNO"] = sourceTable.Rows[0]["CUSTNO"].ToString();
newRow["MBLNO"] = sourceTable.Rows[0]["MBLNO"].ToString();
newRow["HBLNO"] = sourceTable.Rows[0]["HBLNO"].ToString();
bsnoTable.Rows.Add(newRow);
Session[tempBsnoCacheName] = bsnoTable;
}
return strResult;
}
#endregion
#region 获取开票申请信息的总页数
/// <summary>
/// 获取开票申请信息的总页数
/// </summary>
/// <returns>返回总页数</returns>
private int GetInvoiceApplicationPageCount()
{
InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
string strSql = "SELECT COUNT(*) FROM ch_fee_invoiceapplication as A LEFT JOIN [user] as B ON A.Applicant = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1 > 0 AND ISNULL(A.ISDELETE,0) <> 1 ";
string strCondition = "";
string strAuthorityCondition = "";
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppList");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEAPPLIST, strShowName, strCompanyID, strDeptName, strUserID);
strSql += strAuthorityCondition;
}
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
//strCondition += String.Format(" AND BILLNO LIKE '%{0}%'", strArg[1].Replace("\"", ""));
strCondition += String.Format(" AND (A.BILLNO LIKE '%{0}%' or A.BILLNO in (select BILLNO from ch_fee_do where feeid in (select gid from ch_fee where INVOICENUM LIKE '%{0}%') and BILLNO LIKE '%IA%') or A.BILLNO in (select BILLNO from ch_fee_do where feeid in (select gid from ch_fee where bsno in (select bsno from VW_Settlement where MBLNO LIKE '%{0}%')) and BILLNO LIKE '%IA%')) ", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
strSql += strCondition;
}
}
int iTotal = invoiceApplicationDA.GetInvoiceApplicationPageCount(strSql);
return iTotal;
}
#endregion
#region 获取结算单位的支付信息
/// <summary>
/// 获取结算单位的支付信息
/// </summary>
/// <param name="tempCustomerName">结算单位简称</param>
/// <returns></returns>
private string GetCustomerPayable(string tempCustomerName)
{
CRMClientDA crmClientDA = new CRMClientDA();
string strSql = String.Format("SELECT GID,CASE WHEN BILLRISES1 = '' OR BILLRISES1 IS NULL THEN DESCRIPTION ELSE BILLRISES1 END as BILLRISES1 ,BILLRISES2 "
+ " FROM info_client WHERE SHORTNAME = '{0}'", tempCustomerName);
DataTable sourceTable = crmClientDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("clients:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("\"pay1\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"pay2\":\"" + sourceTable.Rows[i][2].ToString() + "\"}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 获取当前用户的公司的支付信息
/// <summary>
/// 获取当前用户的公司的支付信息通过币别区分类型
/// </summary>
/// <param name="strUserID">用户GID</param>
/// <param name="strCurrency">币别名称</param>
/// <returns>所有支付信息</returns>
private string GetBankInfo(string strUserID,string strCurrency)
{
CRMClientDA crmClientDA = new CRMClientDA();
string strSql = String.Format(" SELECT GID,BANKNAME,ACCOUNT,CURRENCY FROM sys_bank WHERE LINKID IN "
+ " (SELECT C.GID FROM [user] as A INNER JOIN user_company as B on A.GID = B.USERID INNER JOIN [company] as C "
+ " ON B.COMPANYID = C.GID WHERE A.GID = '{0}' and A.ISDELETED=0) AND CURRENCY = '{1}'", strUserID, strCurrency);
DataTable sourceTable = crmClientDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("banks:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("\"bank\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"account\":\"" + sourceTable.Rows[i][2].ToString() + "\",");
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("\"currency\":\"" + sourceTable.Rows[i][3].ToString() + "\"}");
}
else
{
sourceBuilder.Append("\"currency\":\"" + sourceTable.Rows[i][3].ToString() + "\"},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 根据开票申请GID获取开票申请信息
/// <summary>
/// 根据开票申请GID获取开票申请信息
/// </summary>
/// <param name="tempInvoiceApplicationGID">开票申请GID</param>
/// <returns>开票申请信息</returns>
private string GetInvoiceApplicationByAppGID(string tempInvoiceApplicationGID)
{
InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
DataTable sourceTable;
string strSql = "SELECT GID,CUSTOMERNAME,INVOICENO,INVOICECUSTNAME,BSNO,VESSELVOYAGE,ETD,POL,POD,MBLNO FROM ch_fee_invoiceapplication WHERE GID = '" + tempInvoiceApplicationGID + "'";
sourceTable = invoiceApplicationDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("apps:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
//if (i == 0)
//{
// sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
//}
//else
//{
// sourceBuilder.Append(",{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
//}
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("\"custname\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"inno\":\"" + sourceTable.Rows[i][2].ToString() + "\",");
sourceBuilder.Append("\"incust\":\"" + sourceTable.Rows[i][3].ToString() + "\",");
sourceBuilder.Append("\"custno\":\"" + sourceTable.Rows[i][4].ToString() + "\",");
sourceBuilder.Append("\"vessel\":\"" + sourceTable.Rows[i][5].ToString() + "\",");
string strETD = "";
if (!sourceTable.Rows[i][6].ToString().Trim().Equals(""))
{
strETD = DateTime.Parse(sourceTable.Rows[i][6].ToString()).ToString("yyyy-MM-dd");
}
sourceBuilder.Append("\"etd\":\"" + strETD + "\",");
sourceBuilder.Append("\"pol\":\"" + sourceTable.Rows[i][7].ToString() + "\",");
sourceBuilder.Append("\"pod\":\"" + sourceTable.Rows[i][8].ToString() + "\",");
sourceBuilder.Append("\"mblno\":\"" + sourceTable.Rows[i][9].ToString() + "\"}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 打印发票
/// <summary>
/// 打印发票
/// </summary>
/// <param name="tempInvoiceGID"></param>
/// <returns></returns>
private int PrintInvoice(string tempInvoiceGID)
{
int iResult = 0;
int iAuthorityStatus = 0;
InvoiceDA invoiceDA = new InvoiceDA();
InvoiceEntity invoiceEntity = new InvoiceEntity();
invoiceEntity = invoiceDA.GetInvoiceByGID(tempInvoiceGID);
if (invoiceEntity.GID != null)
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEMAKEOUT, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, "", invoiceEntity.BillNO, strUserID);
}
if (iAuthorityStatus > 0)
{
if (!invoiceEntity.IsDelete)
{
iResult = invoiceDA.PrintInvoiceByGID(tempInvoiceGID);
if (iResult < 1)
{
iResult = -1;//打印异常
}
}
else
{
iResult = -2;//发票已经废除不能打印
}
}
else
{
iResult = -3;//没有权限打印发票
}
}
return iResult;
}
#endregion
#region 作废发票
/// <summary>
/// 作废发票
/// </summary>
/// <param name="tempInvoiceGID"></param>
/// <returns></returns>
private int VoidInvoice(string tempInvoiceGID)
{
int iResult = 0;
int iAuthorityStatus = 0;
InvoiceDA invoiceDA = new InvoiceDA();
InvoiceEntity invoiceEntity = new InvoiceEntity();
invoiceEntity = invoiceDA.GetInvoiceByGID(tempInvoiceGID);
if (invoiceEntity.GID != null)
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEMAKEOUT, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, "", invoiceEntity.BillNO, strUserID);
}
if (iAuthorityStatus > 0)
{
if (!invoiceEntity.IsDelete)
{
iResult = invoiceDA.VoidInvoiceByGID(tempInvoiceGID, strUserID);
if (iResult < 1)
{
iResult = -1;//废除异常
}
}
else
{
iResult = -2;//发票已经打印过
}
}
else
{
iResult = -3;//没有权限作废发票
}
}
return iResult;
}
#endregion
#region 删除已开出(包含自由和申请)发票
/// <summary>
/// 删除已开出(包含自由和申请)发票
/// </summary>
/// <param name="tempInvoiceGID">发票GID</param>
/// <returns>值1表示删除成功 值-1表示发票已经打印不能删除,只能废除 值-2表示删除异常</returns>
private int DeleteInvoice(string tempInvoiceGID)
{
int iResult = 0;
InvoiceDA invoiceDA = new InvoiceDA();
InvoiceEntity invoiceEntity = new InvoiceEntity();
invoiceEntity = invoiceDA.GetInvoiceByGID(tempInvoiceGID);
int iAuthorityStatus = 0;
if (invoiceEntity.GID != null)
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEMAKEOUT, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, "", invoiceEntity.BillNO, strUserID);
}
if (iAuthorityStatus > 0)
{
//如果发票已经打印,则不能删除
if (!invoiceEntity.IsNeedPrint)
{
IList<FeeDoEntity> feeDoEntities = new List<FeeDoEntity>();
FeeDoDA feeDoDA = new FeeDoDA();
feeDoEntities = feeDoDA.GetFeeDoByBillNO(invoiceEntity.BillNO);
if (feeDoEntities.Count == 0)
{
//feeDoEntities = feeDoDA.GetFeeDoByBillNO2(invoiceEntity.BillNO);
//自由发票删除
iResult = invoiceDA.DeleteInvoiceByGID2(tempInvoiceGID, invoiceEntity.BillNO, strUserID);//feeDoEntities
}
else
{
//申请发票删除
iResult = invoiceDA.DeleteInvoiceByGID(tempInvoiceGID, invoiceEntity.BillNO, strUserID);//feeDoEntities
}
if (iResult < 0)
{
iResult = -2;//删除异常
}
}
else
{
iResult = -1;//发票已经打印,不能删除,只能废除
}
}
else
{
iResult = -3;//没有权限删除发票信息
}
}
return iResult;
}
#endregion
#region 删除未开票的申请
/// <summary>
/// 删除未开票的申请
/// </summary>
/// <param name="tempInvoiceGID">开票申请GID</param>
/// <returns>值1表示删除开票申请成功 值-1表示要删除的发票申请不存在 值-2开票申请已提交,不能删除,值-3删除失败,有异常</returns>
private string DeleteUnPostApplication(string tempInvoiceGID)
{
int iResult = 0;
int iAuthorityStatus = 0;
//根据开票申请
InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
invoiceApplicationEntity = invoiceApplicationDA.GetInvoiceApplicationByGID(tempInvoiceGID);
if (invoiceApplicationEntity.GID != null)
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppList");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEAPPLIST, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, "", invoiceApplicationEntity.BillNO, strUserID);
}
if (iAuthorityStatus > 0)
{
if (invoiceApplicationEntity.BillStatus == 1)
{
int tempResult = invoiceApplicationDA.DeleteInvoiceApplication(invoiceApplicationEntity.GID);
if (tempResult > 0)
{
iResult = 1;//提交成功
}
else
{
iResult = -3;//删除失败
}
}
else if (invoiceApplicationEntity.BillStatus == 2)
{
iResult = -2;//开票申请已提交,不能删除
}
}
else
{
iResult = -4;//没有权限删除发票申请
}
}
else
{
iResult = -1;//要删除的发票申请不存在
}
return iResult.ToString();
}
#endregion
#region 获取开票申请信息,只包含已提交申请的信息
/// <summary>
/// 获取开票申请信息,只包含已提交申请的信息
/// </summary>
/// <returns>返回已提交开票申请的信息列表</returns>
private string GetMakeOutInvoiceApplication()
{
InvoiceDA invoiceDA = new InvoiceDA();
DataTable sourceTable;
//
string strAuthorityCondition = "";
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppList");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEAPPLIST, strShowName, strCompanyID, strDeptName, strUserID);
}
//
string strSql = " SELECT GID,BILLNO,BILLSTATUS,INVOICENO,CUSTOMERNAME,INVOICECUSTNAME,APPLYAMOUNT,CURRENCY,(select top 1 SHOWNAME from [user] where GID=APPLICANT) as APPLICANT,APPLYTIME,(select top 1 SHOWNAME from [user] where GID=OPERATOR) as OPERATOR,OPERATETIME FROM ch_fee_invoiceapplication as A WHERE ISAPPLY = 1 AND BILLSTATUS = 2 AND ISNULL(ISDELETE,0) <> 1 " + strAuthorityCondition + " ORDER BY BILLNO DESC ";
sourceTable = getBillStatusNameTable(invoiceDA.GetExcuteSql(strSql).Tables[0]);
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 提交开票申请,将保存的未提交申请的开票申请提交到服务端
/// <summary>
/// 提交开票申请,将保存的未提交申请的开票申请提交到服务端
/// </summary>
/// <param name="tempInvoiceGID">开票申请GID</param>
/// <returns>值1表示提交申请成功 值-1表示要提交的发票申请不存在 值-2开票申请已经提交 值-3更新失败</returns>
private string PostMakeOutInvoiceApply(string tempInvoiceGID)
{
int iResult = 0;
int iAuthorityStatus = 0;
//根据开票申请
InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
invoiceApplicationEntity = invoiceApplicationDA.GetInvoiceApplicationByGID(tempInvoiceGID);
if (invoiceApplicationEntity.GID != null)
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppList");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEAPPLIST, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, "", invoiceApplicationEntity.BillNO, strUserID);
}
if (iAuthorityStatus > 0)
{
if (invoiceApplicationEntity.BillStatus == 1)
{
int tempResult = invoiceApplicationDA.UpdateInvoiceApplicationStatus(invoiceApplicationEntity.GID, 2, true, invoiceApplicationEntity.BillNO);
if (tempResult > 0)
{
iResult = 1;//提交成功
}
else
{
iResult = -3;//更新失败
}
}
else if (invoiceApplicationEntity.BillStatus == 2)
{
iResult = -2;//开票申请已提交
}
}
else
{
iResult = -4;//没有权限提交发票申请
}
}
else
{
iResult = -1;//要提交的发票申请不存在
}
return iResult.ToString();
}
#endregion
#region 通过开票申请编号BILLNO提交开票申请,将保存的未提交申请的开票申请提交到服务端
/// <summary>
/// 通过开票申请编号BILLNO提交开票申请,将保存的未提交申请的开票申请提交到服务端
/// </summary>
/// <param name="tempInvoiceGID">开票申请GID</param>
/// <returns>值1表示提交申请成功 值-1表示要提交的发票申请不存在 值-2开票申请已经提交 值-3更新失败</returns>
private string PostMakeOutInvoiceApplyByBillNO(string tempBillNO)
{
int iResult = 0;
//根据开票申请
InvoiceApplicationDA invoiceApplicationDA = new InvoiceApplicationDA();
InvoiceApplicationEntity invoiceApplicationEntity = new InvoiceApplicationEntity();
invoiceApplicationEntity = invoiceApplicationDA.GetInvoiceApplicationByBillNO(tempBillNO);
if (invoiceApplicationEntity.GID != null)
{
if (invoiceApplicationEntity.BillStatus == 1)
{
int tempResult = invoiceApplicationDA.UpdateInvoiceApplicationStatus(invoiceApplicationEntity.GID, 2, true, invoiceApplicationEntity.BillNO);
if (tempResult > 0)
{
iResult = 1;//提交成功
}
else
{
iResult = -3;//更新失败
}
}
else if (invoiceApplicationEntity.BillStatus == 2)
{
iResult = -2;//开票申请已提交
}
}
else
{
iResult = -1;//要提交的发票申请不存在
}
return iResult.ToString();
}
#endregion
/// <summary>
/// 发票开出列表导出
/// </summary>
/// <returns></returns>
private string GetMakeOutListExcel()
{
InvoiceDA invoiceDA = new InvoiceDA();
string strCondition = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND (A.BILLNO LIKE '%{0}%' OR A.INVOICENO LIKE '%{0}%') ", strArg[1].Replace("\"", ""));
break;
case "amount1"://
strCondition += String.Format(" AND A.AMOUNT >= '{0}'", strArg[1].Replace("\"", ""));
break;
case "amount2"://
strCondition += String.Format(" AND A.AMOUNT <= '{0}'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
}
//
string strAuthorityCondition = "";
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEMAKEOUT, strShowName, strCompanyID, strDeptName,strUserID);
}
//
string strSql = " SELECT CASE WHEN A.INVOICETYPE = 1 THEN '申请发票' ELSE '自由发票' END as INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN '是' ELSE '' END,CASE WHEN A.ISDELETE = 1 THEN '是' ELSE '' END,A.BILLNO,A.INVOICENO,A.CUSTOMERNAME,A.INVOICECUSTNAME,A.AMOUNT,A.CURRENCY,B.SHOWNAME,A.APPLYTIME,C.SHOWNAME,A.OPERATETIME "
+ " FROM ch_fee_invoice as A LEFT JOIN [user] as B ON A.APPLICANT = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1>0 " + strAuthorityCondition + strCondition + " ORDER BY BILLNO DESC ";
return strSql.Trim();
}
private string GetMakeOutList()
{
InvoiceDA invoiceDA = new InvoiceDA();
DataTable sourceTable;
string strCondition = "";
string strTopInclude = "";
string strTopNotInclude = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND (A.BILLNO LIKE '%{0}%' OR A.INVOICENO LIKE '%{0}%' OR A.MBLNO LIKE '%{0}%') ", strArg[1].Replace("\"", ""));
break;
case "amount1"://
strCondition += String.Format(" AND A.AMOUNT >= '{0}'", strArg[1].Replace("\"", ""));
break;
case "amount2"://
strCondition += String.Format(" AND A.AMOUNT <= '{0}'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
}
string strAuthorityCondition = "";
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEMAKEOUT, strShowName, strCompanyID, strDeptName,strUserID);
}
string strSql = "";
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
strSql = String.Format(" SELECT {0} A.GID,A.INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN 1 ELSE 0 END,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END,A.BILLNO,A.INVOICENO,A.CUSTOMERNAME,A.INVOICECUSTNAME,A.AMOUNT,A.CURRENCY,B.SHOWNAME,A.APPLYTIME,C.SHOWNAME,A.OPERATETIME "
+ " FROM ch_fee_invoice as A LEFT JOIN [user] as B ON A.APPLICANT = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1>0 " + strAuthorityCondition + strCondition + " ORDER BY BILLNO DESC ", "top " + iShowPage.ToString());
}
else
{
strTopNotInclude = "top " + (iShowPage * (iCurrentPage - 1)).ToString();//RowCount*PageNum
strTopInclude = "top " + iShowPage.ToString();
strSql = String.Format(" SELECT {0} A.GID,A.INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN 1 ELSE 0 END,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END,A.BILLNO,A.INVOICENO,A.CUSTOMERNAME,A.INVOICECUSTNAME,A.AMOUNT,A.CURRENCY,B.SHOWNAME,A.APPLYTIME,C.SHOWNAME,A.OPERATETIME "
+ " FROM ch_fee_invoice as A LEFT JOIN [user] as B ON A.APPLICANT = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE A.GID NOT IN "
+ " (SELECT {1} GID FROM ch_fee_invoice as A WHERE 1>0 " + strAuthorityCondition + strCondition + " ORDER BY BILLNO DESC ) " + strAuthorityCondition + strCondition
+ " ORDER BY BILLNO DESC ", strTopInclude, strTopNotInclude);
}
}
else
{
strSql = " SELECT A.GID,A.INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN 1 ELSE 0 END,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END,A.BILLNO,A.INVOICENO,A.CUSTOMERNAME,A.INVOICECUSTNAME,A.AMOUNT,A.CURRENCY,B.SHOWNAME,A.APPLYTIME,C.SHOWNAME,A.OPERATETIME "
+ " FROM ch_fee_invoice as A LEFT JOIN [user] as B ON A.APPLICANT = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1>0 " + strAuthorityCondition + strCondition + " ORDER BY BILLNO DESC ";
}
sourceTable = getBillStatusNameTable(invoiceDA.GetExcuteSql(strSql).Tables[0]);
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
private string GetInvoiceApplication()
{
InvoiceDA invoiceDA = new InvoiceDA();
DataTable sourceTable;
string strSql = " SELECT GID,BILLNO,BILLSTATUS,INVOICENO,CUSTOMERNAME,INVOICECUSTNAME,APPLYAMOUNT,CURRENCY,APPLICANT,APPLYTIME,OPERATOR,OPERATETIME FROM ch_fee_invoiceapplication WHERE ISAPPLY = 1 ";
sourceTable = getBillStatusNameTable(invoiceDA.GetExcuteSql(strSql).Tables[0]);
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
private string GetOpSeaeInfo(string tempBSNO)
{
InvoiceDA invoiceDA = new InvoiceDA();
DataTable sourceTable;
//string strSql = "SELECT BSNO,VESSEL+' '+VOYNO as VESSELVOYAGE,MBLNO,CASE WHEN ETD IS NULL THEN '' ELSE ETD END,PORTLOAD,PORTDISCHARGE,CUSTNO FROM op_seae WHERE BSNO = '" + tempBSNO + "'";
//string strSql = String.Format("SELECT BSNO,VESSEL+' '+VOYNO as VESSELVOYAGE,MBLNO,CASE WHEN ETD IS NULL THEN '' ELSE ETD END,PORTLOAD,PORTDISCHARGE,CUSTNO FROM op_seae WHERE BSNO = {0} "
// + " union all "
// + "SELECT BSNO,VESSEL+' '+VOYNO as VESSELVOYAGE,MBLNO,CASE WHEN ETD IS NULL THEN '' ELSE ETD END,PORTLOAD,PORTDISCHARGE,CUSTNO FROM op_seai WHERE BSNO = {0} "
// , tempBSNO);
//2013-02-05 修改
string strSql = String.Format("SELECT BSNO,VESSEL+' '+VOYNO as VESSELVOYAGE,MBLNO,CASE WHEN ETD IS NULL THEN '' ELSE ETD END,PORTLOAD,PORTDISCHARGE,CUSTNO FROM VW_Settlement WHERE BSNO = {0} "
, tempBSNO);
sourceTable = invoiceDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("opinfo:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (i == 0)
{
sourceBuilder.Append("{bsno:\"" + sourceTable.Rows[i][0].ToString() + "\",");
}
else
{
sourceBuilder.Append(",{bsno:\"" + sourceTable.Rows[i][0].ToString() + "\",");
}
sourceBuilder.Append("\"vessel\":\"" + sourceTable.Rows[i][1].ToString() + "\",");
sourceBuilder.Append("\"mblno\":\"" + sourceTable.Rows[i][2].ToString() + "\",");
string strETD = "";
if (!sourceTable.Rows[i][3].ToString().Trim().Equals(""))
{
strETD = DateTime.Parse(sourceTable.Rows[i][3].ToString()).ToString("yyyy-MM-dd");
}
sourceBuilder.Append("\"etd\":\"" + strETD + "\",");
sourceBuilder.Append("\"pol\":\"" + sourceTable.Rows[i][4].ToString() + "\",");
sourceBuilder.Append("\"pod\":\"" + sourceTable.Rows[i][5].ToString() + "\",");
sourceBuilder.Append("\"custno\":\"" + sourceTable.Rows[i][6].ToString() + "\"}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
private string GetSeaeOrderBySearch(string tempSearch)
{
int itempoplb = 0; //业务类别
if (strOrderCacheName != null)
{
if (Session[strOrderCacheName] != null)
{
//如果点击查询费用按钮,则自动将搜索之前缓存的数据进行清除,清除Session
Session.Remove(strOrderCacheName);
}
}
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
string strSeaeCondition = "";
string strFeeCondition = "";
string strAuthorityCondition = "";
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "cus"://Customer
//strSeaeCondition += String.Format("AND CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
strFeeCondition += String.Format("AND CUSTOMERNAME = '{0}' ", strArg[1].Replace("\"", ""));
break;
case "bno"://BillNO
strSeaeCondition += String.Format(" AND (CUSTNO LIKE '%{0}%' OR MBLNO LIKE '%{0}%' OR HBLNO LIKE '%{0}%' OR CUSTOMNO LIKE '%{0}%' OR CUSTOMNO2 LIKE '%{0}%')", strArg[1].Replace("\"", ""));
break;
case "bt"://ETD BeginDate
strSeaeCondition += String.Format(" AND ETD >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "et"://ETD EndDate
strSeaeCondition += String.Format(" AND ETD <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "ves"://Vessel
strSeaeCondition += String.Format(" AND VESSEL LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "voy"://Voyno
strSeaeCondition += String.Format(" AND VOYNO LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "fnm"://FeeName
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
int iFeeName = -1;
try
{
iFeeName = int.Parse(strArg[1].Replace("\"", "").Trim());
}
catch { }
if (iFeeName == -1)
{
strFeeCondition += String.Format(" AND FEENAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
}
}
break;
case "fty"://FeeType
int iFeeType = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iFeeType > 0)
{
strFeeCondition += String.Format(" AND FEETYPE = {0}", iFeeType);
}
break;
case "cur"://Currency
int iCurrency = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iCurrency == 1)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "RMB");
}
else if (iCurrency == 2)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "USD");
}
break;
case "bty"://业务类别
itempoplb = int.Parse(strArg[1].Replace("\"", ""));
break;
//case "deno"://DebitNO
// //strSqlCondition += String.Format(" VOYNO LIKE '%{0}%' ", strArg[1]);
// break;
//case "ise"://IsSettled
// break;
//case "fty"://FeeType
// strSqlCondition += String.Format(" FEETYPE = {0} ", strArg[1]);
// break;
//case "cur"://Currency
// strSqlCondition += String.Format(" FEETYPE = {0} ", strArg[1]);
// break;
case "amount1"://
strFeeCondition += String.Format(" AND AMOUNT >= '{0}'", strArg[1].Replace("\"", ""));
break;
case "amount2"://
strFeeCondition += String.Format(" AND AMOUNT <= '{0}'", strArg[1].Replace("\"", ""));
break;
case "accDate":
strSeaeCondition += string.Format(" AND ACCDATE='{0}'",strArg[1].Replace("\"",""));
break;
default:
break;
}
}
}
if (strDoTypeName != null)
{
if (strDoTypeName == "app")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppSearch");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEAPPSEARCH, strShowName, strCompanyID, strDeptName, strUserID, itempoplb.ToString());//strbstype
}
}
else if (strDoTypeName == "import")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceImport");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEIMPORT, strShowName, strCompanyID, strDeptName, strUserID, itempoplb.ToString());//strbstype
}
}
}
else
{
strAuthorityCondition = " AND 1< 0 ";
}
FeeSettlementDA feeSettlementDA = new FeeSettlementDA();
DataTable sourceTable;
//string strSql = "SELECT BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + "SELECT BSNO FROM ch_fee WHERE FEESTATUS = 0 AND GID NOT IN (SELECT FEEID FROM ch_fee_do)) "
// + strSeaeCondition;
//string strSql = "SELECT BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + "SELECT BSNO FROM ch_fee WHERE GID IN"
// + "(SELECT A.GID FROM ch_fee as A LEFT JOIN ch_fee_do as B ON A.GID = B.FEEID WHERE FEEID IS NULL OR FEESTATUS = 8 OR (A.FEESTATUS = 0 AND A.ORDERAMOUNT <> B.DOAMOUNT)) AND (FEESTATUS = 8 OR FEESTATUS = 0))"
// + strSeaeCondition;
//string strSql = " SELECT BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) " + strFeeCondition + strAuthorityCondition + ") " + strSeaeCondition + " ORDER BY CUSTOMERNAME DESC ";
//switch (itempoplb)
//{
// case 0:
// strSql = String.Format(" SELECT BSNO,'海运出口' OPLB, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} "
// //+ "ORDER BY CUSTOMERNAME DESC "
// + " union all "
// + " SELECT BSNO,'海运进口' OPLB, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seai WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} ORDER BY OPLB,CUSTOMERNAME DESC "
// , strFeeCondition, strAuthorityCondition, strSeaeCondition);
// break;
// case 1:
// strSql = String.Format(" SELECT BSNO,'海运出口' OPLB, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} ORDER BY OPLB,CUSTOMERNAME DESC "
// , strFeeCondition, strAuthorityCondition, strSeaeCondition);
// break;
// case 2:
// strSql = String.Format(" SELECT BSNO,'海运进口' OPLB, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seai WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} ORDER BY OPLB,CUSTOMERNAME DESC "
// , strFeeCondition, strAuthorityCondition, strSeaeCondition);
// break;
// //case 3:
// //case 4:
// default:
// break;
//}
string strSql = "";
//2013-02-05 修改 begin
string sOPLBCondition = "";
switch (itempoplb)
{
case 0://所有业务类型
sOPLBCondition = "";
break;
case 1://海运出口op_Seae
sOPLBCondition = " and OPLBNAME='海运出口' ";
break;
case 2://海运进口op_Seai
sOPLBCondition = " and OPLBNAME='海运进口' ";
break;
case 3://空运出口
sOPLBCondition = " and OPLBNAME='空运出口' ";
break;
case 4://空运进口
sOPLBCondition = " and OPLBNAME='空运进口' ";
break;
case 5://陆运托运
sOPLBCondition = " and OPLBNAME='陆运托运' ";
break;
case 6://仓储费
sOPLBCondition = " and OPLBNAME='仓储费' ";
break;
case 7://仓储入库
sOPLBCondition = " and OPLBNAME='仓储入库' ";
break;
case 8://仓储出库
sOPLBCondition = " and OPLBNAME='仓储出库' ";
break;
case 9://陆运派车
sOPLBCondition = " and OPLBNAME='陆运派车' ";
break;
default:
break;
}
//strSql = String.Format(" SELECT BSNO,OPLBNAME,CUSTOMERNAME,CUSTNO,MBLNO,HBLNO,CUSTOMNO,CUSTOMNO2 FROM VW_Settlement WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} {3} ORDER BY OPLB,CUSTOMERNAME DESC "
// , strFeeCondition, strAuthorityCondition, strSeaeCondition, sOPLBCondition);
if (strBorrowPay == "borrowPay")//垫付条件
{
strSql = String.Format(" SELECT BSNO,OPLBNAME,CUSTOMERNAME,CUSTNO,MBLNO,HBLNO,CUSTOMNO,CUSTOMNO2 FROM VW_Settlement WHERE 1 > 0 AND BSNO IN ( "
+ " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} "
//+ " and gid not in(select feeid from ch_fee_do where (ISDELETED<>1 or ISDELETED is null))"
+ ") {2} {3} ORDER BY OPLB,CUSTOMERNAME DESC "
, strFeeCondition, strAuthorityCondition, strSeaeCondition, sOPLBCondition);
}
else
{
strSql = String.Format(" SELECT BSNO,OPLBNAME,CUSTOMERNAME,CUSTNO,MBLNO,HBLNO,CUSTOMNO,CUSTOMNO2 FROM VW_Settlement WHERE 1 > 0 AND BSNO IN ( "
+ " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) and feename not in (select [name] from [code_fee] where feetype='垫付') {0} {1} "
//+ " and gid not in(select feeid from ch_fee_do where (ISDELETED<>1 or ISDELETED is null))"
+ ") {2} {3} ORDER BY OPLB,CUSTOMERNAME DESC "
, strFeeCondition, strAuthorityCondition, strSeaeCondition, sOPLBCondition);
}
sourceTable = feeSettlementDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
private string GetSelectedOrderFee(string tempBSNO)
{
FeeSettlementDA feeSettlementDA = new FeeSettlementDA();
DataTable sourceTable;
string strCondition = "";
if (strFeeSearch != null)
{
if (!strFeeSearch.Trim().Equals(""))
{
string tempSearch = strFeeSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "cus"://Customer
strCondition += String.Format(" AND CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "fnm"://FeeName
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
int iFeeName = -1;
try
{
iFeeName = int.Parse(strArg[1].Replace("\"", "").Trim());
}
catch { }
if (iFeeName == -1)
{
strCondition += String.Format(" AND FEENAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
}
}
break;
case "fty"://FeeType
int iFeeType = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iFeeType > 0)
{
strCondition += String.Format(" AND FEETYPE = {0}", iFeeType);
}
break;
case "cur"://Currency
int iCurrency = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iCurrency == 1)
{
strCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "RMB");
}
else if (iCurrency == 2)
{
strCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "USD");
}
break;
case "amount1"://
strCondition += String.Format(" AND AMOUNT >= '{0}'", strArg[1].Replace("\"", ""));
break;
case "amount2"://
strCondition += String.Format(" AND AMOUNT <= '{0}'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
}
//string strSql = String.Format("SELECT GID,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT,AMOUNT-SETTLEMENT,AMOUNT-SETTLEMENT FROM ch_fee WHERE BSNO = '{0}' AND (FEESTATUS = 0 OR FEESTATUS = 8) AND GID NOT IN (SELECT FEEID FROM ch_fee_do WHERE BSNO IN ('{0}'))", tempBSNO);
//string strSql = String.Format(" SELECT GID,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT,AMOUNT-SETTLEMENT,AMOUNT-SETTLEMENT FROM ch_fee "
// + " WHERE BSNO IN ('{0}') AND FEESTATUS = 0 AND GID NOT IN (SELECT FEEID FROM ch_fee_do) " + strCondition, tempBSNO);
//string strSql = String.Format(" SELECT C.GID,C.FEETYPE,C.CUSTOMERNAME,C.FEENAME,C.CURRENCY,CASE WHEN C.FEESTATUS = 8 THEN C.AMOUNT - D.DOAMOUNT "
// + " ELSE CASE WHEN C.FEESTATUS =0 AND C.ORDERAMOUNT <> C.AMOUNT THEN C.AMOUNT - C.ORDERAMOUNT END END , "
// + " CASE WHEN C.FEESTATUS = 8 THEN C.AMOUNT - D.DOAMOUNT "
// + " ELSE CASE WHEN C.FEESTATUS =0 AND C.ORDERAMOUNT <> C.AMOUNT THEN C.AMOUNT - C.ORDERAMOUNT END END ,0 "
// + " FROM ch_fee as C LEFT JOIN ch_fee_do as D ON C.GID = D.FEEID WHERE C.GID IN ( SELECT A.GID FROM ch_fee as A LEFT JOIN ch_fee_do as B ON A.GID = B.FEEID "
// + " WHERE A.BSNO IN ('{0}') AND (FEEID IS NULL OR FEESTATUS = 8 OR (A.FEESTATUS = 0 AND A.ORDERAMOUNT <> A.AMOUNT AND A.AMOUNT > 0)) "
// + " ) AND (FEESTATUS = 8 OR FEESTATUS = 0) " + strCondition, tempBSNO);
string strSql;
if (strBorrowPay == "borrowPay")
{
strSql = String.Format(" SELECT GID,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END, REMARK "
+ " FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND BSNO IN ('{0}') AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) " + strCondition
//+ " and gid not in(select feeid from ch_fee_do where (ISDELETED<>1 or ISDELETED is null)) "
+ " ORDER BY CUSTOMERNAME DESC", tempBSNO);
}
else
{
strSql = String.Format(" SELECT GID,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END, REMARK "
+ " FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND BSNO IN ('{0}') AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) and feename not in (select [name] from [code_fee] where feetype='垫付') " + strCondition
//+ " and gid not in(select feeid from ch_fee_do where (ISDELETED<>1 or ISDELETED is null)) "
+ " ORDER BY CUSTOMERNAME DESC", tempBSNO);
}
sourceTable = getStatusNameTable(feeSettlementDA.GetExcuteSql(strSql).Tables[0]);
DataTable feeTable = null;
if (strOrderCacheName != null)
{
if (Session[strOrderCacheName] != null)
{
feeTable = (DataTable)Session[strOrderCacheName];
}
}
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
if (feeTable != null)
{
int iCount = 0;
for (int j = 0; j < feeTable.Rows.Count; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(sourceTable.Rows[i][0].ToString()))
{
sourceBuilder.Append("\"1\",");
iCount++;
break;
}
}
if (iCount == 0)
{
sourceBuilder.Append("\"0\",");
}
iCount = 0;
}
else
{
sourceBuilder.Append("\"0\",");
}
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
private string GetInvoiceApplicationAll()
{
InvoiceDA invoiceDA = new InvoiceDA();
DataTable sourceTable;
string strCondition = "";
string strTopInclude = "";
string strTopNotInclude = "";
if (strSearch != null)
{
#region strSearch != null
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,20) <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "cus":
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no":
strCondition += String.Format(" AND A.BILLNO LIKE '%{0}%'", strArg[1].Replace("\"", ""));
break;
case "invoicenum":
strCondition += String.Format(" AND A.BILLNO in (select BILLNO from ch_fee_do where feeid in (select gid from ch_fee where INVOICENUM LIKE '%{0}%') and BILLNO LIKE '%IA%')", strArg[1].Replace("\"", ""));
break;
case "mblno":
strCondition += String.Format(" AND A.BILLNO in (select BILLNO from ch_fee_do where feeid in (select gid from ch_fee where bsno in (select bsno from VW_Settlement where MBLNO LIKE '%{0}%')) and BILLNO LIKE '%IA%') ", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
#endregion
}
string strSql = "";
string strAuthorityCondition = "";
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppList");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEAPPLIST, strShowName, strCompanyID, strDeptName, strUserID);
}
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
strSql = String.Format(" SELECT {0} A.GID,A.BILLNO,A.BILLSTATUS"
+ ",INVOICENO=(select top 1 INVOICENUM from ch_fee where gid in(select feeid from ch_fee_do where billno=A.BILLNO))"
+ ",A.CUSTOMERNAME,A.INVOICECUSTNAME,A.APPLYAMOUNT,A.CURRENCY,B.SHOWNAME ,A.APPLYTIME,C.SHOWNAME,A.OPERATETIME "
+ " FROM ch_fee_invoiceapplication as A LEFT JOIN [user] as B ON A.Applicant = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1>0 AND ISNULL(ISDELETE,0) <> 1 {1} {2} ORDER BY BILLNO DESC ","top " + iShowPage.ToString(),strAuthorityCondition, strCondition);
}
else
{
strTopNotInclude = "top " + (iShowPage * (iCurrentPage - 1)).ToString();//RowCount*PageNum
strTopInclude = "top " + iShowPage.ToString();
strSql = String.Format(" SELECT {0} A.GID,A.BILLNO,A.BILLSTATUS"
+ ",INVOICENO=(select top 1 INVOICENUM from ch_fee where gid in(select feeid from ch_fee_do where billno=A.BILLNO))"
+ ",A.CUSTOMERNAME,A.INVOICECUSTNAME,A.APPLYAMOUNT,A.CURRENCY,B.SHOWNAME ,A.APPLYTIME,C.SHOWNAME,A.OPERATETIME "
+ " FROM ch_fee_invoiceapplication as A LEFT JOIN [user] as B ON A.Applicant = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE A.GID NOT IN "
+ " (SELECT {1} A.GID FROM ch_fee_invoiceapplication A LEFT JOIN [user] as B ON A.Applicant = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1>0 AND ISNULL(ISDELETE,0) <> 1 " + strAuthorityCondition + strCondition + " ORDER BY BILLNO DESC ) AND ISNULL(ISDELETE,0) <> 1 " + strAuthorityCondition + strCondition
+ " ORDER BY BILLNO DESC ", strTopInclude, strTopNotInclude);
}
}
else
{
strSql = "SELECT A.GID,A.BILLNO,A.BILLSTATUS"
+ ",INVOICENO=(select top 1 INVOICENUM from ch_fee where gid in(select feeid from ch_fee_do where billno=A.BILLNO))"
+ ",A.CUSTOMERNAME,A.INVOICECUSTNAME,A.APPLYAMOUNT,A.CURRENCY,B.SHOWNAME ,A.APPLYTIME,C.SHOWNAME,A.OPERATETIME "
+ " FROM ch_fee_invoiceapplication as A LEFT JOIN [user] as B ON A.Applicant = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1<0 ";
}
sourceTable = getBillStatusNameTable(invoiceDA.GetExcuteSql(strSql).Tables[0]);
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#region
/// <summary>
/// 将数据集表中费用状态FeeStatus和应收应付类型FeeType的数字状态位转换成文字
/// </summary>
/// <param name="tempTable">原数据源DataTable</param>
/// <returns>返回新数据源DataTable</returns>
private DataTable getBillStatusNameTable(DataTable tempTable)
{
DataTable sourceTable = tempTable;
DataTable cloneTable = new DataTable();
int iSwitch = 0;
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (iSwitch == 0)
{
for (int j = 0; j < sourceTable.Columns.Count; j++)
{
if (sourceTable.Columns[j].ColumnName.Equals("BILLSTATUS"))
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = sourceTable.Columns[j].ColumnName;
newColumn.DataType = System.Type.GetType("System.String");
cloneTable.Columns.Add(newColumn);
}
else if (sourceTable.Columns[j].ColumnName.Equals("INVOICETYPE"))
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = sourceTable.Columns[j].ColumnName;
newColumn.DataType = System.Type.GetType("System.String");
cloneTable.Columns.Add(newColumn);
}
else
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = sourceTable.Columns[j].ColumnName;
newColumn.DataType = sourceTable.Columns[j].DataType;
cloneTable.Columns.Add(newColumn);
}
}
iSwitch = 1;
}
DataRow cloneRow = cloneTable.NewRow();
for (int k = 0; k < sourceTable.Columns.Count; k++)
{
if (sourceTable.Columns[k].ColumnName.Equals("BILLSTATUS"))
{
int iFeeStatus = int.Parse(sourceTable.Rows[i][k].ToString());
string strFeeStatus = "";
switch (iFeeStatus)
{
case 1:
strFeeStatus = "未提交";
break;
case 2:
strFeeStatus = "已提交";
break;
case 3:
strFeeStatus = "已开出";
break;
case 4:
strFeeStatus = "已驳回";
break;
default:
break;
}
cloneRow[sourceTable.Columns[k].ColumnName] = strFeeStatus;
}
else if (sourceTable.Columns[k].ColumnName.Equals("INVOICETYPE"))
{
int iFeeStatus = int.Parse(sourceTable.Rows[i][k].ToString());
string strFeeStatus = "";
switch (iFeeStatus)
{
case 1:
strFeeStatus = "申请发票";
break;
case 2:
strFeeStatus = "自由发票";
break;
default:
break;
}
cloneRow[sourceTable.Columns[k].ColumnName] = strFeeStatus;
}
else
{
cloneRow[sourceTable.Columns[k].ColumnName] = sourceTable.Rows[i][k];
}
}
cloneTable.Rows.Add(cloneRow);
}
//cloneTable.Columns.Remove("FEESTATUS");
//cloneTable.Columns.Add(new DataColumn("FEESTATUS", System.Type.GetType("System.String")));
return cloneTable;
}
#endregion
/// <summary>
/// 将数据集表中费用状态FeeStatus和应收应付类型FeeType的数字状态位转换成文字
/// </summary>
/// <param name="tempTable">原数据源DataTable</param>
/// <returns>返回新数据源DataTable</returns>
private DataTable getStatusNameTable(DataTable tempTable)
{
DataTable sourceTable = tempTable;
DataTable cloneTable = new DataTable();
int iSwitch = 0;
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (iSwitch == 0)
{
for (int j = 0; j < sourceTable.Columns.Count; j++)
{
if (sourceTable.Columns[j].ColumnName.Equals("FEETYPE"))
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = sourceTable.Columns[j].ColumnName;
newColumn.DataType = System.Type.GetType("System.String");
cloneTable.Columns.Add(newColumn);
}
else
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = sourceTable.Columns[j].ColumnName;
newColumn.DataType = sourceTable.Columns[j].DataType;
cloneTable.Columns.Add(newColumn);
}
}
iSwitch = 1;
}
DataRow cloneRow = cloneTable.NewRow();
for (int k = 0; k < sourceTable.Columns.Count; k++)
{
if (sourceTable.Columns[k].ColumnName.Equals("FEETYPE"))
{
int iFeeStatus = int.Parse(sourceTable.Rows[i][k].ToString());
string strFeeStatus = "";
switch (iFeeStatus)
{
case 1:
strFeeStatus = "收";
break;
case 2:
strFeeStatus = "付";
break;
default:
break;
}
cloneRow[sourceTable.Columns[k].ColumnName] = strFeeStatus;
}
else
{
cloneRow[sourceTable.Columns[k].ColumnName] = sourceTable.Rows[i][k];
}
}
cloneTable.Rows.Add(cloneRow);
}
//cloneTable.Columns.Remove("FEESTATUS");
//cloneTable.Columns.Add(new DataColumn("FEESTATUS", System.Type.GetType("System.String")));
return cloneTable;
}
#region 当委托全选或者是去除全选时,缓存费用信息
/// <summary>
/// 当委托全选或者是去除全选时,缓存费用信息
/// </summary>
/// <param name="tempSelectedOrder">选中的委托信息组</param>
/// <param name="tempOrderCacheName">缓存名称</param>
/// <returns>返回动态计算的应收应付金额合计</returns>
private string CacheOrderFee(string tempSelectedOrder, string tempOrderCacheName)
{
string strResult = "";
int iAuthorityStatus = 0;
int iForbidCount = 0;//没有权限添加的委托信息统计
UserAuthorityManage userAuthorityManage = null;
if (strDoTypeName == "app")
{
userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppSearch");
}
else if (strDoTypeName == "import")
{
userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceImport");
}
ArrayList groupArray = new ArrayList();
string strBsnoGroup = "";
string strList = tempSelectedOrder;
string strFilter = "";
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 "bsno":
groupArray.Add(strArg[1].ToString().Replace("\"", "").Trim());
if (strDoTypeName == "app")
{
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEAPPSEARCH, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, strArg[1].ToString().Replace("\"", "").Trim(), "", strUserID);
}
}
else if (strDoTypeName == "import")
{
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEIMPORT, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, strArg[1].ToString().Replace("\"", "").Trim(), "", strUserID);
}
}
if (iAuthorityStatus == 1)
{
strBsnoGroup += "'" + strArg[1].ToString().Replace("\"", "").Trim() + "',";
}
else
{
iForbidCount++;
}
break;
default:
break;
}
}
}
}
}
}
if (strCheckType != null)
{
if (strCheckType.Trim().ToLower().Equals("check"))
{
if (strBsnoGroup.Trim().EndsWith(","))
{
strBsnoGroup = strBsnoGroup.Substring(0, strBsnoGroup.Length - 1);
}
if (strBsnoGroup.Trim().Equals(""))
{
strBsnoGroup = "''";
}
string strSql = GetSearchSql(strSearch,strBsnoGroup);//String.Format("SELECT * FROM ch_fee WHERE BSNO IN ({0})", strBsnoGroup);
DataTable feeTable = new DataTable();
FeeDA feeDA = new FeeDA();
feeTable = feeDA.GetExcuteSql(strSql).Tables[0];
if (feeTable.Rows.Count > 0)
{
Session[tempOrderCacheName] = feeTable;
}
if (iForbidCount > 0)
{
strResult = GetSumFeeJson(feeTable, -iForbidCount,0,false);
}
else
{
strResult = GetSumFeeJson(feeTable, 1,1,true);
}
}
else
{
if (Session[tempOrderCacheName] != null)
{
DataTable feeTable = (DataTable)Session[tempOrderCacheName];
if (groupArray.Count > 0)
{
for (int j = 0; j < groupArray.Count; j++)
{
for (int i = 0; i < feeTable.Rows.Count; i++)
{
if (feeTable.Rows[i]["BSNO"].ToString().Trim().Equals(groupArray[j].ToString()))
{
feeTable.Rows.Remove(feeTable.Rows[i]);
i = -1;
continue;
}
}
}
if (feeTable.Rows.Count == 0)
{
Session.Remove(tempOrderCacheName);
if (iForbidCount > 0)
{
strResult = GetSumFeeJson(feeTable, -iForbidCount,0,false);
}
else
{
strResult = GetSumFeeJson(feeTable, 1,2,true);
}
}
else
{
Session[tempOrderCacheName] = feeTable;
if (iForbidCount > 0)
{
strResult = GetSumFeeJson(feeTable, -iForbidCount,0,false);
}
else
{
strResult = GetSumFeeJson(feeTable, 1,2,true);
}
}
}
}
}
}
return strResult;
}
#endregion
#region 动态计算人民币、美元应收应付合计金额
/// <summary>
/// 动态计算人民币、美元应收应付合计金额
/// </summary>
/// <param name="tempFeeTable">数据表</param>
/// <param name="tempState">返回状态信息</param>
/// <param name="tempCheckType">是否是选中状态1-选中状态 2-取消选中状态</param>
/// <param name="tempCheckAll">是否是全选操作</param>
/// <returns></returns>
private string GetSumFeeJson(DataTable tempFeeTable, int tempState, int tempCheckType, bool tempCheckAll)
{
StringBuilder totalBuilder = new StringBuilder();
decimal RecvRmbTotal = 0;
decimal PayRmbTotal = 0;
decimal RecvUsdTotal = 0;
decimal PayUsdTotal = 0;
decimal RmbTotal = 0;
decimal UsdTotal = 0;
if (tempFeeTable != null)
{
if (tempFeeTable.Rows.Count > 0)
{
if (tempCheckType == 1)//选中状态
{
for (int i = 0; i < tempFeeTable.Rows.Count; i++)
{
string tempCurrency = tempFeeTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper();
decimal tempFee = decimal.Parse(tempFeeTable.Rows[i]["CTL"].ToString());
int tempFeeType = int.Parse(tempFeeTable.Rows[i]["FEETYPE"].ToString());
if (tempFeeType == 1 && tempCurrency == "RMB" && tempFee != 0)//tempFee > 0
{
RecvRmbTotal += tempFee;
}
else if (tempFeeType == 1 && tempCurrency == "USD" && tempFee != 0)//tempFee > 0
{
RecvUsdTotal += tempFee;
}
else if (tempFeeType == 2 && tempCurrency == "RMB" && tempFee != 0)//tempFee > 0
{
PayRmbTotal += tempFee;
}
else if (tempFeeType == 2 && tempCurrency == "USD" && tempFee != 0)//tempFee > 0
{
PayUsdTotal += tempFee;
}
}
if (strDoTypeName == "paysettle" || strDoTypeName == "paysettleapp")
{
RmbTotal = PayRmbTotal - RecvRmbTotal;
UsdTotal = PayUsdTotal - RecvUsdTotal;
}
else
{
RmbTotal = RecvRmbTotal - PayRmbTotal;
UsdTotal = RecvUsdTotal - PayUsdTotal;
}
totalBuilder.Append("{");
totalBuilder.Append("\"totals\":");
totalBuilder.Append("[");
totalBuilder.Append("{");
totalBuilder.Append("\"recvrmb\":" + RecvRmbTotal.ToString() + ",");
totalBuilder.Append("\"recvusd\":" + RecvUsdTotal.ToString() + ",");
totalBuilder.Append("\"payrmb\":" + PayRmbTotal.ToString() + ",");
totalBuilder.Append("\"payusd\":" + PayUsdTotal.ToString() + ",");
totalBuilder.Append("\"totalrmb\":" + RmbTotal.ToString() + ",");
totalBuilder.Append("\"totalusd\":" + UsdTotal.ToString() + ",");
totalBuilder.Append("\"state\":" + tempState.ToString());
totalBuilder.Append("}");
totalBuilder.Append("]");
totalBuilder.Append("}");
DataTable totalTable = null;
if (Session[strTotalCacheName] != null)
{
totalTable = (DataTable)Session[strTotalCacheName];
}
else
{
totalTable = CreateTotalTable();
DataRow newRow = totalTable.NewRow();
totalTable.Rows.Add(newRow);
}
totalTable.Rows[0]["RECVRMB"] = RecvRmbTotal.ToString();
totalTable.Rows[0]["RECVUSD"] = RecvUsdTotal.ToString();
totalTable.Rows[0]["PAYRMB"] = PayRmbTotal.ToString();
totalTable.Rows[0]["PAYUSD"] = PayUsdTotal.ToString();
totalTable.Rows[0]["TOTALRMB"] = RmbTotal.ToString();
totalTable.Rows[0]["TOTALUSD"] = UsdTotal.ToString();
Session[strTotalCacheName] = totalTable;
}
else
{
//如果当前是状态为全部取消选中状态,则将合计数据置零并清除Session信息
if (tempCheckAll)
{
if (Session[strTotalCacheName] != null)
{
Session.Remove(strTotalCacheName);
}
totalBuilder.Append("{");
totalBuilder.Append("\"totals\":");
totalBuilder.Append("[");
totalBuilder.Append("{");
totalBuilder.Append("\"recvrmb\":0,");
totalBuilder.Append("\"recvusd\":0,");
totalBuilder.Append("\"payrmb\":0,");
totalBuilder.Append("\"payusd\":0,");
totalBuilder.Append("\"totalrmb\":0,");
totalBuilder.Append("\"totalusd\":0,");
totalBuilder.Append("\"state\":" + tempState.ToString());
totalBuilder.Append("}");
totalBuilder.Append("]");
totalBuilder.Append("}");
}
else
{
for (int i = 0; i < tempFeeTable.Rows.Count; i++)
{
string tempCurrency = tempFeeTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper();
decimal tempFee = decimal.Parse(tempFeeTable.Rows[i]["CTL"].ToString());
int tempFeeType = int.Parse(tempFeeTable.Rows[i]["FEETYPE"].ToString());
if (tempFeeType == 1 && tempCurrency == "RMB" && tempFee != 0)//tempFee > 0
{
RecvRmbTotal += tempFee;
}
else if (tempFeeType == 1 && tempCurrency == "USD" && tempFee != 0)//tempFee > 0
{
RecvUsdTotal += tempFee;
}
else if (tempFeeType == 2 && tempCurrency == "RMB" && tempFee != 0)//tempFee > 0
{
PayRmbTotal += tempFee;
}
else if (tempFeeType == 2 && tempCurrency == "USD" && tempFee != 0)//tempFee > 0
{
PayUsdTotal += tempFee;
}
}
if (strDoTypeName == "paysettle" || strDoTypeName == "paysettleapp")
{
RmbTotal = PayRmbTotal - RecvRmbTotal;
UsdTotal = PayUsdTotal - RecvUsdTotal;
}
else
{
RmbTotal = RecvRmbTotal - PayRmbTotal;
UsdTotal = RecvUsdTotal - PayUsdTotal;
}
totalBuilder.Append("{");
totalBuilder.Append("\"totals\":");
totalBuilder.Append("[");
totalBuilder.Append("{");
totalBuilder.Append("\"recvrmb\":" + RecvRmbTotal.ToString() + ",");
totalBuilder.Append("\"recvusd\":" + RecvUsdTotal.ToString() + ",");
totalBuilder.Append("\"payrmb\":" + PayRmbTotal.ToString() + ",");
totalBuilder.Append("\"payusd\":" + PayUsdTotal.ToString() + ",");
totalBuilder.Append("\"totalrmb\":" + RmbTotal.ToString() + ",");
totalBuilder.Append("\"totalusd\":" + UsdTotal.ToString() + ",");
totalBuilder.Append("\"state\":" + tempState.ToString());
totalBuilder.Append("}");
totalBuilder.Append("]");
totalBuilder.Append("}");
DataTable totalTable = null;
if (Session[strTotalCacheName] != null)
{
totalTable = (DataTable)Session[strTotalCacheName];
}
else
{
totalTable = CreateTotalTable();
DataRow newRow = totalTable.NewRow();
totalTable.Rows.Add(newRow);
}
totalTable.Rows[0]["RECVRMB"] = RecvRmbTotal.ToString();
totalTable.Rows[0]["RECVUSD"] = RecvUsdTotal.ToString();
totalTable.Rows[0]["PAYRMB"] = PayRmbTotal.ToString();
totalTable.Rows[0]["PAYUSD"] = PayUsdTotal.ToString();
totalTable.Rows[0]["TOTALRMB"] = RmbTotal.ToString();
totalTable.Rows[0]["TOTALUSD"] = UsdTotal.ToString();
Session[strTotalCacheName] = totalTable;
}
}
}
else
{
totalBuilder.Append("{");
totalBuilder.Append("\"totals\":");
totalBuilder.Append("[");
totalBuilder.Append("{");
totalBuilder.Append("\"recvrmb\":" + RecvRmbTotal.ToString() + ",");
totalBuilder.Append("\"recvusd\":" + RecvUsdTotal.ToString() + ",");
totalBuilder.Append("\"payrmb\":" + PayRmbTotal.ToString() + ",");
totalBuilder.Append("\"payusd\":" + PayUsdTotal.ToString() + ",");
totalBuilder.Append("\"totalrmb\":" + RmbTotal.ToString() + ",");
totalBuilder.Append("\"totalusd\":" + UsdTotal.ToString() + ",");
totalBuilder.Append("\"state\":" + tempState.ToString());
totalBuilder.Append("}");
totalBuilder.Append("]");
totalBuilder.Append("}");
}
}
else
{
totalBuilder.Append("{");
totalBuilder.Append("\"totals\":");
totalBuilder.Append("[");
totalBuilder.Append("{");
totalBuilder.Append("\"recvrmb\":" + RecvRmbTotal.ToString() + ",");
totalBuilder.Append("\"recvusd\":" + RecvUsdTotal.ToString() + ",");
totalBuilder.Append("\"payrmb\":" + PayRmbTotal.ToString() + ",");
totalBuilder.Append("\"payusd\":" + PayUsdTotal.ToString() + ",");
totalBuilder.Append("\"totalrmb\":" + RmbTotal.ToString() + ",");
totalBuilder.Append("\"totalusd\":" + UsdTotal.ToString() + ",");
totalBuilder.Append("\"state\":" + tempState.ToString());
totalBuilder.Append("}");
totalBuilder.Append("]");
totalBuilder.Append("}");
}
return totalBuilder.ToString();
}
#endregion
#region 获取数据集的SQL语句
/// <summary>
/// 获取数据集的SQL语句
/// </summary>
/// <param name="tempSearch">查询条件</param>
/// <param name="tempValidateOrder">要包含的委托信息组</param>
/// <returns>返回获取数据集的SQL语句</returns>
private string GetSearchSql(string tempSearch,string tempValidateOrder)
{
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
string strSeaeCondition = "";
string strFeeCondition = "";
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "cus"://Customer
//strSeaeCondition += String.Format("AND CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
strFeeCondition += String.Format("AND CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "bno"://BillNO
strSeaeCondition += String.Format(" AND (CUSTNO LIKE '%{0}%' OR MBLNO LIKE '%{0}%' OR HBLNO LIKE '%{0}%')", strArg[1].Replace("\"", ""));
break;
case "bt"://ETD BeginDate
strSeaeCondition += String.Format(" AND ETD >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "et"://ETD EndDate
strSeaeCondition += String.Format(" AND ETD <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "ves"://Vessel
strSeaeCondition += String.Format(" AND VESSEL LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "voy"://Voyno
strSeaeCondition += String.Format(" AND VOYNO LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "fnm"://FeeName
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
int iFeeName = -1;
try
{
iFeeName = int.Parse(strArg[1].Replace("\"", "").Trim());
}
catch { }
if (iFeeName == -1)
{
strFeeCondition += String.Format(" AND FEENAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
}
}
break;
case "fty"://FeeType
int iFeeType = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iFeeType > 0)
{
strFeeCondition += String.Format(" AND FEETYPE = {0}", iFeeType);
}
break;
case "cur"://Currency
int iCurrency = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iCurrency == 1)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "RMB");
}
else if (iCurrency == 2)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "USD");
}
break;
//case "deno"://DebitNO
// //strSqlCondition += String.Format(" VOYNO LIKE '%{0}%' ", strArg[1]);
// break;
//case "ise"://IsSettled
// break;
//case "fty"://FeeType
// strSqlCondition += String.Format(" FEETYPE = {0} ", strArg[1]);
// break;
//case "cur"://Currency
// strSqlCondition += String.Format(" FEETYPE = {0} ", strArg[1]);
// break;
default:
break;
}
}
}
string strSql = String.Format(" SELECT GID,BSNO,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END as CTL, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END as UCTL, REMARK "
+ " FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND BSNO IN ({0}) AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) "
//+ " and gid not in(select feeid from ch_fee_do where (ISDELETED<>1 or ISDELETED is null))"
+ strFeeCondition, tempValidateOrder);
return strSql;
}
#endregion
#region 选中委托信息,默认缓存委托信息内的所有费用信息
/// <summary>
/// 选中委托信息,默认缓存委托信息内的所有费用信息
/// </summary>
/// <param name="tempBSNO">委托编号</param>
/// <param name="tempCheckType">选中类型 值check表示选中 值uncheck表示取消选中</param>
/// <param name="tempCacheName">缓存名称</param>
/// <param name="tempBsnoCacheName">委托缓存名称</param>
/// <param name="tempTotalCacheName">合计缓存名称</param>
/// <returns>返回重新计算后的利润信息JSON</returns>
private string ExcuteCheckOrder(string tempBSNO, string tempCheckType, string tempCacheName, string tempBsnoCacheName, string tempTotalCacheName)
{
string strResult = "";
DataTable feeTable = null;
int iAuthorityStatus = 0;
if (strDoTypeName == "app")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppSearch");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEAPPSEARCH, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, tempBSNO, "", strUserID, "VW_Settlement");//stroplb
}
if (iAuthorityStatus != 1)
{
if (Session[tempCacheName] != null)
{
feeTable = (DataTable)Session[tempCacheName];
}
strResult = GetSumFeeJson(feeTable, -1,0,false);
return strResult;
}
}
//如果已经存在选中费用明细,则从Session中获取费用信息进行添加
if (Session[tempCacheName] != null)
{
feeTable = (DataTable)Session[tempCacheName];
if (tempCheckType.Trim().ToLower().Equals("check"))
{
string strSql = GetSearchSql(strSearch, "'" + tempBSNO + "'");
DataTable checkFeeTable = new DataTable();
DataTable bsnoTable = null;
FeeDA feeDA = new FeeDA();
//checkFeeTable = feeDA.GetFeeListByCondition(strSql).Tables[0];
checkFeeTable = GetFeeByOrderBsnoTable(strSearch, tempBSNO);
if (checkFeeTable.Rows.Count > 0)
{
for (int i = 0; i < checkFeeTable.Rows.Count; i++)
{
int iCount = 0;
for (int j = 0; j < feeTable.Rows.Count; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(checkFeeTable.Rows[i]["GID"].ToString().Trim()))
{
iCount++;
break;
}
}
if (iCount == 0)
{
//缓存新的费用信息
DataRow newRow = feeTable.NewRow();
newRow["GID"] = checkFeeTable.Rows[i]["GID"].ToString();
newRow["BSNO"] = checkFeeTable.Rows[i]["BSNO"].ToString();
newRow["FEETYPE"] = checkFeeTable.Rows[i]["FEETYPE"].ToString();
newRow["CUSTOMERNAME"] = checkFeeTable.Rows[i]["CUSTOMERNAME"].ToString();
newRow["FEENAME"] = checkFeeTable.Rows[i]["FEENAME"].ToString();
newRow["CURRENCY"] = checkFeeTable.Rows[i]["CURRENCY"].ToString();
newRow["AMOUNT"] = checkFeeTable.Rows[i]["AMOUNT"].ToString();
newRow["CTL"] = checkFeeTable.Rows[i]["CTL"].ToString();
newRow["UCTL"] = checkFeeTable.Rows[i]["UCTL"].ToString();
feeTable.Rows.Add(newRow);
}
}
Session[tempCacheName] = feeTable;
}
if (Session[tempBsnoCacheName] != null)
{
bsnoTable = (DataTable)Session[tempBsnoCacheName];
for (int i = 0; i < bsnoTable.Rows.Count; i++)
{
if (bsnoTable.Rows[i]["BSNO"].ToString().Equals(tempBSNO))
{
bsnoTable.Rows.RemoveAt(i);
break;
}
}
//
DataTable tempBsnoTable = GetOrderTable(strSearch, tempBSNO);
if (tempBsnoTable.Rows.Count > 0)
{
for (int i = 0; i < tempBsnoTable.Rows.Count; i++)
{
//缓存新的费用信息
DataRow newRow = bsnoTable.NewRow();
newRow["BSNO"] = tempBsnoTable.Rows[i]["BSNO"].ToString();
newRow["CUSTOMERNAME"] = tempBsnoTable.Rows[i]["CUSTOMERNAME"].ToString();
newRow["CUSTNO"] = tempBsnoTable.Rows[i]["CUSTNO"].ToString();
newRow["MBLNO"] = tempBsnoTable.Rows[i]["MBLNO"].ToString();
newRow["HBLNO"] = tempBsnoTable.Rows[i]["HBLNO"].ToString();
newRow["CUSTOMNO"] = tempBsnoTable.Rows[i]["CUSTOMNO"].ToString();
newRow["CUSTOMNO2"] = tempBsnoTable.Rows[i]["CUSTOMNO2"].ToString();
//
bsnoTable.Rows.Add(newRow);
}
}
}
else
{
bsnoTable = GetOrderTable(strSearch, tempBSNO);
}
Session[strBsnoCacheName] = bsnoTable;
//
strResult = GetSumFeeJson(feeTable, 1, 1, false);
}
else if (tempCheckType.Trim().ToLower().Equals("uncheck"))
{
//string strSql = GetSearchSql(strSearch, "'" + tempBSNO + "'");
DataTable checkFeeTable = null;
//FeeDA feeDA = new FeeDA();
//checkFeeTable = feeDA.GetFeeListByCondition(strSql).Tables[0];
checkFeeTable = GetFeeByOrderBsnoTable(strSearch, tempBSNO);
if (checkFeeTable.Rows.Count > 0)
{
for (int i = 0; i < checkFeeTable.Rows.Count; i++)
{
for (int j = 0; j < feeTable.Rows.Count; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(checkFeeTable.Rows[i]["GID"].ToString().Trim()))
{
feeTable.Rows.Remove(feeTable.Rows[j]);
break;
}
}
}
Session[tempCacheName] = feeTable;
}
DataTable bsnoTable = null;
if (Session[tempBsnoCacheName] != null)
{
bsnoTable = (DataTable)Session[tempBsnoCacheName];
for (int i = 0; i < bsnoTable.Rows.Count; i++)
{
if (bsnoTable.Rows[i]["BSNO"].ToString().Equals(tempBSNO))
{
bsnoTable.Rows.RemoveAt(i);
break;
}
}
Session[tempBsnoCacheName] = bsnoTable;
}
strResult = GetSumFeeJson(feeTable, 1, 2, false);
}
//strResult = GetSumFeeJson(feeTable, 1);
}
else
{
if (tempCheckType.Trim().ToLower().Equals("check"))
{
DataTable bsnoTable = null;
//如果当前选中的委托下的费用未进行过缓存,则将所有费用明细缓存
if (Session[strBsnoCacheName] != null)
{
bsnoTable = (DataTable)Session[strBsnoCacheName];
}
else
{
bsnoTable = GetOrderTable(strSearch, tempBSNO);
Session[strBsnoCacheName] = bsnoTable;
}
feeTable = GetFeeByOrderBsnoTable(strSearch, tempBSNO);
Session[tempCacheName] = feeTable;
strResult = GetSumFeeJson(feeTable, 1, 1, false);
}
else
{
//如果在没有缓存费用明细情况下,取消选中状态,将委托缓存信息内相关委托移除,最后再缓存
DataTable bsnoTable = null;
if (Session[strBsnoCacheName] != null)
{
bsnoTable = (DataTable)Session[strBsnoCacheName];
}
if (bsnoTable != null)
{
for (int i = 0; i < bsnoTable.Rows.Count; i++)
{
if (bsnoTable.Rows[i]["BSNO"].ToString().Equals(tempBSNO))
{
bsnoTable.Rows.RemoveAt(i);
break;
}
}
Session[strBsnoCacheName] = bsnoTable;
}
strResult = GetSumFeeJson(feeTable, 1, 2, false);
}
}
return strResult;
}
#endregion
#region 单选费用操作
/// <summary>
/// 单选费用操作
/// </summary>
/// <param name="tempFeeID">费用GID</param>
/// <param name="tempCheckType">选中类型 值check选中状态 值uncheck取消选中状态</param>
/// <param name="tempCacheName">缓存名称</param>
/// <param name="tempBsnoCacheName">委托缓存名称</param>
/// <param name="tempTotalCacheName">合计缓存名称</param>
/// <param name="tempTotalCacheName">委托编号BSNO</param>
/// <returns>返回缓存数据合计费用JSON</returns>
private string ExcuteCheckFee(string tempFeeID, string tempCheckType, string tempCacheName, string tempBsnoCacheName, string tempTotalCacheName, string tempBSNO)
{
string strResult = "";
DataTable feeTable = (DataTable)Session[tempCacheName] ?? CreateFeeTable();
DataTable bsnoTable = (DataTable)Session[tempBsnoCacheName] ?? CreateBsnoTable();
DataTable totalTable = (DataTable)Session[tempTotalCacheName] ?? CreateTotalTable();
int iAuthorityStatus = 0;
if (strDoTypeName == "app")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppSearch");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEAPPSEARCH, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, strBSNO, "", strUserID, "VW_Settlement");//stroplb
}
if (iAuthorityStatus != 1)
{
if (Session[tempCacheName] != null)
{
feeTable = (DataTable)Session[tempCacheName];
}
strResult = GetSumFeeJson(feeTable, -1,0,false);
return strResult;
}
}
else if (strDoTypeName == "import")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceImport");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEIMPORT, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, strBSNO, "", strUserID, "VW_Settlement");//stroplb
}
if (iAuthorityStatus != 1)
{
if (Session[tempCacheName] != null)
{
feeTable = (DataTable)Session[tempCacheName];
}
strResult = GetSumFeeJson(feeTable, -1,0,false);
return strResult;
}
}
#region ####
//if (Session[tempCacheName] != null)
//{
// feeTable = (DataTable)Session[tempCacheName];
// if (tempCheckType.Trim().ToLower().Equals("check"))
// {
// string strSql = String.Format("SELECT GID,BSNO,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT, "
// + " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
// + " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END as CTL, "
// + " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
// + " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END as UCTL FROM ch_fee WHERE GID = '{0}'", tempFeeID);
// DataTable checkFeeTable = new DataTable();
// FeeDA feeDA = new FeeDA();
// checkFeeTable = feeDA.GetFeeListByCondition(strSql).Tables[0];
// if (checkFeeTable.Rows.Count > 0)
// {
// for (int i = 0; i < checkFeeTable.Rows.Count; i++)
// {
// int iCount = 0;
// for (int j = 0; j < feeTable.Rows.Count; j++)
// {
// if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(tempFeeID))
// {
// iCount++;
// break;
// }
// }
// if (iCount == 0)
// {
// //缓存新的费用信息
// DataRow newRow = feeTable.NewRow();
// newRow["GID"] = checkFeeTable.Rows[i]["GID"].ToString();
// newRow["BSNO"] = checkFeeTable.Rows[i]["BSNO"].ToString();
// newRow["FEETYPE"] = checkFeeTable.Rows[i]["FEETYPE"].ToString();
// newRow["CUSTOMERNAME"] = checkFeeTable.Rows[i]["CUSTOMERNAME"].ToString();
// newRow["FEENAME"] = checkFeeTable.Rows[i]["FEENAME"].ToString();
// newRow["CURRENCY"] = checkFeeTable.Rows[i]["CURRENCY"].ToString();
// newRow["AMOUNT"] = checkFeeTable.Rows[i]["AMOUNT"].ToString();
// newRow["CTL"] = checkFeeTable.Rows[i]["CTL"].ToString();
// newRow["UCTL"] = checkFeeTable.Rows[i]["UCTL"].ToString();
// feeTable.Rows.Add(newRow);
// }
// }
// Session[tempCacheName] = feeTable;
// }
// strResult = GetSumFeeJson(feeTable,1);
// }
// else if (tempCheckType.Trim().ToLower().Equals("uncheck"))
// {
// for (int j = 0; j < feeTable.Rows.Count; j++)
// {
// if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(tempFeeID))
// {
// feeTable.Rows.Remove(feeTable.Rows[j]);
// break;
// }
// }
// if (feeTable.Rows.Count == 0)
// {
// Session.Remove(tempCacheName);
// }
// else
// {
// Session[tempCacheName] = feeTable;
// }
// strResult = GetSumFeeJson(feeTable,1);//获取重新计算的费用总额
// }
//}
//else
//{
// if (tempCheckType.Trim().ToLower().Equals("check"))
// {
// string strSql = String.Format("SELECT GID,BSNO,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT, "
// + " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
// + " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END as CTL, "
// + " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
// + " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END as UCTL FROM ch_fee WHERE GID = '{0}'", tempFeeID);
// DataTable checkFeeTable = new DataTable();
// FeeDA feeDA = new FeeDA();
// checkFeeTable = feeDA.GetFeeListByCondition(strSql).Tables[0];
// Session[tempCacheName] = checkFeeTable;
// strResult = GetSumFeeJson(checkFeeTable,1);
// }
//}
#endregion
if (tempCheckType.Trim().ToLower().Equals("check"))
{
DataTable checkFeeTable = GetSimpleFeeByGID(tempFeeID);
for (int i = 0; i < checkFeeTable.Rows.Count; i++)
{
int iCount = 0;
for (int j = 0; j < feeTable.Rows.Count; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(checkFeeTable.Rows[i]["GID"].ToString().Trim()))
{
feeTable.Rows[j]["GID"] = checkFeeTable.Rows[i]["GID"].ToString();
feeTable.Rows[j]["BSNO"] = checkFeeTable.Rows[i]["BSNO"].ToString();
feeTable.Rows[j]["FEETYPE"] = checkFeeTable.Rows[i]["FEETYPE"].ToString();
feeTable.Rows[j]["CUSTOMERNAME"] = checkFeeTable.Rows[i]["CUSTOMERNAME"].ToString();
feeTable.Rows[j]["FEENAME"] = checkFeeTable.Rows[i]["FEENAME"].ToString();
feeTable.Rows[j]["CURRENCY"] = checkFeeTable.Rows[i]["CURRENCY"].ToString();
feeTable.Rows[j]["AMOUNT"] = checkFeeTable.Rows[i]["AMOUNT"].ToString();
feeTable.Rows[j]["CTL"] = checkFeeTable.Rows[i]["CTL"].ToString();
feeTable.Rows[j]["UCTL"] = checkFeeTable.Rows[i]["UCTL"].ToString();
iCount++;
break;
}
}
if (iCount == 0)
{
//缓存新的费用信息
DataRow newRow = feeTable.NewRow();
newRow["GID"] = checkFeeTable.Rows[i]["GID"].ToString();
newRow["BSNO"] = checkFeeTable.Rows[i]["BSNO"].ToString();
newRow["FEETYPE"] = checkFeeTable.Rows[i]["FEETYPE"].ToString();
newRow["CUSTOMERNAME"] = checkFeeTable.Rows[i]["CUSTOMERNAME"].ToString();
newRow["FEENAME"] = checkFeeTable.Rows[i]["FEENAME"].ToString();
newRow["CURRENCY"] = checkFeeTable.Rows[i]["CURRENCY"].ToString();
newRow["AMOUNT"] = checkFeeTable.Rows[i]["AMOUNT"].ToString();
newRow["CTL"] = checkFeeTable.Rows[i]["CTL"].ToString();
newRow["UCTL"] = checkFeeTable.Rows[i]["UCTL"].ToString();
feeTable.Rows.Add(newRow);
}
}
DataTable checkBsnoTable = GetOrderTable(strSearch, tempBSNO);
int iBsnoCount = 0;
for (int j = 0; j < bsnoTable.Rows.Count; j++)
{
if (bsnoTable.Rows[j]["BSNO"].ToString().Trim().Equals(tempBSNO))
{
bsnoTable.Rows[j]["BSNO"] = checkBsnoTable.Rows[0]["BSNO"].ToString();
bsnoTable.Rows[j]["CUSTOMERNAME"] = checkBsnoTable.Rows[0]["CUSTOMERNAME"].ToString();
bsnoTable.Rows[j]["CUSTNO"] = checkBsnoTable.Rows[0]["CUSTNO"].ToString();
bsnoTable.Rows[j]["MBLNO"] = checkBsnoTable.Rows[0]["MBLNO"].ToString();
bsnoTable.Rows[j]["HBLNO"] = checkBsnoTable.Rows[0]["HBLNO"].ToString();
iBsnoCount++;
break;
}
}
if (iBsnoCount == 0)
{
//BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO
//缓存新的委托信息
DataRow newRow = bsnoTable.NewRow();
newRow["BSNO"] = checkBsnoTable.Rows[0]["BSNO"].ToString();
newRow["CUSTOMERNAME"] = checkBsnoTable.Rows[0]["CUSTOMERNAME"].ToString();
newRow["CUSTNO"] = checkBsnoTable.Rows[0]["CUSTNO"].ToString();
newRow["MBLNO"] = checkBsnoTable.Rows[0]["MBLNO"].ToString();
newRow["HBLNO"] = checkBsnoTable.Rows[0]["HBLNO"].ToString();
bsnoTable.Rows.Add(newRow);
}
Session[tempBsnoCacheName] = bsnoTable;
Session[tempCacheName] = feeTable;
strResult = GetSumFeeJson(feeTable, 1, 1, false);
}
else
{
int isExistCount = 0;
DataTable checkFeeTable = GetSimpleFeeByGID(tempFeeID);
for (int i = 0; i < checkFeeTable.Rows.Count; i++)
{
int feeCount = feeTable.Rows.Count;
for (int j = 0; j < feeCount; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(checkFeeTable.Rows[i]["GID"].ToString().Trim()))
{
feeTable.Rows.Remove(feeTable.Rows[j]);
j = j - 1;
feeCount = feeTable.Rows.Count;
isExistCount--;
continue;
}
if (feeTable.Rows[j]["BSNO"].ToString().Trim().Equals(tempBSNO))
{
isExistCount++;
}
}
}
if (isExistCount == 0)
{
for (int j = 0; j < bsnoTable.Rows.Count; j++)
{
if (bsnoTable.Rows[j]["BSNO"].ToString().Trim().Equals(tempBSNO))
{
bsnoTable.Rows.RemoveAt(j);
break;
}
}
if (bsnoTable.Rows.Count > 0)
{
Session[tempBsnoCacheName] = bsnoTable;
}
else
{
Session.Remove(tempBsnoCacheName);
}
}
if (feeTable.Rows.Count > 0)
{
Session[tempCacheName] = feeTable;
}
else
{
Session.Remove(tempCacheName);
}
strResult = GetSumFeeJson(feeTable, 1, 2, false);
}
return strResult;
}
#endregion
#region 执行同一委托下费用全选操作
/// <summary>
/// 执行同一委托下费用全选操作
/// </summary>
/// <param name="tempBSNO">委托编号</param>
/// <param name="tempCheckType">选中类型 值check表示全部选中 值uncheck表示取消全部选中</param>
/// <param name="tempCacheName">缓存名称</param>
/// <param name="tempBsnoCacheName">委托缓存名称</param>
/// <param name="tempTotalCacheName">合计缓存名称</param>
/// <returns>返回合计费用结果JSON</returns>
private string ExcuteCheckAllFee(string tempBSNO, string tempCheckType, string tempCacheName, string tempBsnoCacheName, string tempTotalCacheName)
{
string strResult = "";
DataTable feeTable = (DataTable)Session[tempCacheName] ?? CreateFeeTable();
DataTable bsnoTable = (DataTable)Session[tempBsnoCacheName] ?? CreateBsnoTable();
DataTable totalTable = (DataTable)Session[tempTotalCacheName] ?? CreateTotalTable();
int iAuthorityStatus = 0;
if (strDoTypeName == "app")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppSearch");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEAPPSEARCH, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, tempBSNO, "", strUserID, "VW_Settlement");//stroplb
}
if (iAuthorityStatus != 1)
{
if (Session[tempCacheName] != null)
{
feeTable = (DataTable)Session[tempCacheName];
}
strResult = GetSumFeeJson(feeTable, -1,0,false);
return strResult;
}
}
else if (strDoTypeName == "import")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceImport");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.INVOICEIMPORT, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, tempBSNO, "", strUserID, "VW_Settlement");//stroplb
}
if (iAuthorityStatus != 1)
{
if (Session[tempCacheName] != null)
{
feeTable = (DataTable)Session[tempCacheName];
}
strResult = GetSumFeeJson(feeTable, -1,0,false);
return strResult;
}
}
if (tempCheckType.Trim().ToLower().Equals("check"))
{
DataTable checkFeeTable = GetFeeByOrderBsnoTable(strSearch, tempBSNO);
for (int i = 0; i < checkFeeTable.Rows.Count; i++)
{
int iCount = 0;
for (int j = 0; j < feeTable.Rows.Count; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(checkFeeTable.Rows[i]["GID"].ToString().Trim()))
{
feeTable.Rows[j]["GID"] = checkFeeTable.Rows[i]["GID"].ToString();
feeTable.Rows[j]["BSNO"] = checkFeeTable.Rows[i]["BSNO"].ToString();
feeTable.Rows[j]["FEETYPE"] = checkFeeTable.Rows[i]["FEETYPE"].ToString();
feeTable.Rows[j]["CUSTOMERNAME"] = checkFeeTable.Rows[i]["CUSTOMERNAME"].ToString();
feeTable.Rows[j]["FEENAME"] = checkFeeTable.Rows[i]["FEENAME"].ToString();
feeTable.Rows[j]["CURRENCY"] = checkFeeTable.Rows[i]["CURRENCY"].ToString();
feeTable.Rows[j]["AMOUNT"] = checkFeeTable.Rows[i]["AMOUNT"].ToString();
feeTable.Rows[j]["CTL"] = checkFeeTable.Rows[i]["CTL"].ToString();
feeTable.Rows[j]["UCTL"] = checkFeeTable.Rows[i]["UCTL"].ToString();
iCount++;
break;
}
}
if (iCount == 0)
{
//缓存新的费用信息
DataRow newRow = feeTable.NewRow();
newRow["GID"] = checkFeeTable.Rows[i]["GID"].ToString();
newRow["BSNO"] = checkFeeTable.Rows[i]["BSNO"].ToString();
newRow["FEETYPE"] = checkFeeTable.Rows[i]["FEETYPE"].ToString();
newRow["CUSTOMERNAME"] = checkFeeTable.Rows[i]["CUSTOMERNAME"].ToString();
newRow["FEENAME"] = checkFeeTable.Rows[i]["FEENAME"].ToString();
newRow["CURRENCY"] = checkFeeTable.Rows[i]["CURRENCY"].ToString();
newRow["AMOUNT"] = checkFeeTable.Rows[i]["AMOUNT"].ToString();
newRow["CTL"] = checkFeeTable.Rows[i]["CTL"].ToString();
newRow["UCTL"] = checkFeeTable.Rows[i]["UCTL"].ToString();
feeTable.Rows.Add(newRow);
}
}
DataTable checkBsnoTable = GetOrderTable(strSearch, tempBSNO);
int iBsnoCount = 0;
for (int j = 0; j < bsnoTable.Rows.Count; j++)
{
if (bsnoTable.Rows[j]["BSNO"].ToString().Trim().Equals(tempBSNO))
{
bsnoTable.Rows[j]["BSNO"] = checkBsnoTable.Rows[0]["BSNO"].ToString();
bsnoTable.Rows[j]["CUSTOMERNAME"] = checkBsnoTable.Rows[0]["CUSTOMERNAME"].ToString();
bsnoTable.Rows[j]["CUSTNO"] = checkBsnoTable.Rows[0]["CUSTNO"].ToString();
bsnoTable.Rows[j]["MBLNO"] = checkBsnoTable.Rows[0]["MBLNO"].ToString();
bsnoTable.Rows[j]["HBLNO"] = checkBsnoTable.Rows[0]["HBLNO"].ToString();
iBsnoCount++;
break;
}
}
if (iBsnoCount == 0)
{
//BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO
//缓存新的委托信息
DataRow newRow = bsnoTable.NewRow();
newRow["BSNO"] = checkBsnoTable.Rows[0]["BSNO"].ToString();
newRow["CUSTOMERNAME"] = checkBsnoTable.Rows[0]["CUSTOMERNAME"].ToString();
newRow["CUSTNO"] = checkBsnoTable.Rows[0]["CUSTNO"].ToString();
newRow["MBLNO"] = checkBsnoTable.Rows[0]["MBLNO"].ToString();
newRow["HBLNO"] = checkBsnoTable.Rows[0]["HBLNO"].ToString();
bsnoTable.Rows.Add(newRow);
}
Session[tempBsnoCacheName] = bsnoTable;
Session[tempCacheName] = feeTable;
strResult = GetSumFeeJson(feeTable, 1, 1, false);
}
else if (tempCheckType.Trim().ToLower().Equals("uncheck"))
{
DataTable checkFeeTable = GetFeeByOrderBsnoTable(strSearch, tempBSNO);
for (int i = 0; i < checkFeeTable.Rows.Count; i++)
{
for (int j = 0; j < feeTable.Rows.Count; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(checkFeeTable.Rows[i]["GID"].ToString().Trim()))
{
feeTable.Rows.Remove(feeTable.Rows[j]);
break;
}
}
}
for (int j = 0; j < bsnoTable.Rows.Count; j++)
{
if (bsnoTable.Rows[j]["BSNO"].ToString().Trim().Equals(tempBSNO))
{
bsnoTable.Rows.RemoveAt(j);
break;
}
}
if (bsnoTable.Rows.Count > 0)
{
Session[tempBsnoCacheName] = bsnoTable;
}
else
{
Session.Remove(tempBsnoCacheName);
}
if (feeTable.Rows.Count > 0)
{
Session[tempCacheName] = feeTable;
}
else
{
Session.Remove(tempCacheName);
}
strResult = GetSumFeeJson(feeTable, 1, 2, false);
}
return strResult;
}
#endregion
#region 验证提交的开票信息
/// <summary>
/// 验证提交的开票信息
/// </summary>
/// <param name="tempCacheName">缓存名称</param>
/// <returns>返回JSON状态</returns>
private string ValidatePostInfo(string tempCacheName)
{
string strResult = "";
if (Session[tempCacheName] != null)
{
//获取缓存数据
DataTable feeTable = (DataTable)Session[tempCacheName];
//查看是否有不同的结算单位
int iTempDiffCust = IsDifferentCustomer(feeTable);
//查看是否有不同的结算币别
int iTempDiffCurr = IsDifferentCurrency(feeTable,strCurrency);
//查看是否超过发票最大行数
object configObj = ConfigManager.ConfigManager.Instance().GetConfigInfo(ConfigType.INVOICECONFIG);
IList<InvoiceConfigEntity> invoiceConfigEntities = new List<InvoiceConfigEntity>();
invoiceConfigEntities = (IList<InvoiceConfigEntity>)configObj;
int iTempIsMaxLine = 0;
int iInvoiceMaxLine = 0;
if (invoiceConfigEntities.Count > 0)
{
foreach (InvoiceConfigEntity invoicConfigEntity in invoiceConfigEntities)
{
if (invoicConfigEntity.ItemName.ToLower().Equals("maxline"))
{
iInvoiceMaxLine = int.Parse(invoicConfigEntity.ItemValue);
break;
}
}
}
if (iInvoiceMaxLine > 0)
{
if (feeTable.Rows.Count > iInvoiceMaxLine)
{
iTempIsMaxLine = 1;
}
else
{
iTempIsMaxLine = 0;
}
}
else
{
iTempIsMaxLine = 0;
}
strResult = GetValidateResult(iTempDiffCust, iTempDiffCurr, iTempIsMaxLine, iInvoiceMaxLine);
}
else
{
strResult = GetValidateResult(-2, -2, -2,-2);
}
return strResult;
}
#endregion
#region 获取JSON值
/// <summary>
/// 获取JSON值
/// </summary>
/// <param name="tempCompanyID">公司GID</param>
/// <param name="tempSourceID">报表资源GID</param>
/// <param name="tempUserID">用户GID</param>
/// <returns>返回JSON字符串</returns>
private string GetValidateResult(int tempIsDiffCust,int tempIsDiffCurr,int tempIsMaxLine,int tempMaxLine)
{
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.Append("{");
jsonBuilder.Append("\"validates\":");
jsonBuilder.Append("[");
jsonBuilder.Append("{");
jsonBuilder.Append("\"diffcust\":" + tempIsDiffCust.ToString() + ",");
jsonBuilder.Append("\"diffcurr\":" + tempIsDiffCurr.ToString() + ",");
jsonBuilder.Append("\"ismaxline\":" + tempIsMaxLine.ToString() + ",");
jsonBuilder.Append("\"maxline\":" + tempMaxLine.ToString() + "");
jsonBuilder.Append("}");
jsonBuilder.Append("]");
jsonBuilder.Append("}");
return jsonBuilder.ToString();
}
#endregion
#region 提交开票申请
/// <summary>
/// 提交开票申请
/// </summary>
/// <param name="tempPostSessionName">提交Session名称</param>
/// <param name="tempBsnoCacheName">委托缓存名称</param>
/// <param name="tempCacheName">缓存名称</param>
/// <param name="tempTotalCacheName">合计缓存名称</param>
/// <returns>返回string 值1表示提交成功 值不等于1表示提交失败</returns>
private string PostInvoiceApplicationSession(string tempPostSessionName, string tempBsnoCacheName, string tempCacheName, string tempTotalCacheName)
{
string strResult = "";
#region ####
//StringBuilder appBuilder = new StringBuilder();
//StringBuilder cacheBuilder = new StringBuilder();
//if (Session[tempCacheName] != null)
//{
// DataTable feeTable = (DataTable)Session[tempCacheName];
// appBuilder.Append("{\"caches\":[");
// if (strRename != null)
// {
// //如果定义了自定义名称,则将
// string strCustomerName = "";
// decimal RecvRmbTotal = 0;
// decimal PayRmbTotal = 0;
// decimal RecvUsdTotal = 0;
// decimal PayUsdTotal = 0;
// decimal RmbTotal = 0;
// decimal UsdTotal = 0;
// decimal Total = 0;
// for (int i = 0; i < feeTable.Rows.Count; i++)
// {
// string tempCurrency = feeTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper();
// decimal tempFee = decimal.Parse(feeTable.Rows[i]["CTL"].ToString());
// int tempFeeType = int.Parse(feeTable.Rows[i]["FEETYPE"].ToString());
// if (tempFeeType == 1 && tempCurrency == "RMB" && tempFee > 0)
// {
// RecvRmbTotal += tempFee;
// }
// else if (tempFeeType == 1 && tempCurrency == "USD" && tempFee > 0)
// {
// RecvUsdTotal += tempFee;
// }
// else if (tempFeeType == 2 && tempCurrency == "RMB" && tempFee > 0)
// {
// PayRmbTotal += tempFee;
// }
// else if (tempFeeType == 2 && tempCurrency == "USD" && tempFee > 0)
// {
// PayUsdTotal += tempFee;
// }
// }
// RmbTotal = RecvRmbTotal - PayRmbTotal;
// UsdTotal = RecvUsdTotal - PayUsdTotal;
// if (strCurrency.ToUpper().Equals("RMB"))
// {
// Total = RmbTotal + (UsdTotal * dExchangeRate);
// }
// else
// {
// Total = UsdTotal + (RmbTotal * dExchangeRate);
// }
// cacheBuilder.Append("{");
// cacheBuilder.Append("\"id\":\"" + Guid.NewGuid().ToString() + "\",");
// cacheBuilder.Append("\"type\":0,");
// cacheBuilder.Append("\"bsno\":\"\",");
// cacheBuilder.Append("\"cus\":\"" + feeTable.Rows[0]["CUSTOMERNAME"].ToString() + "\",");
// cacheBuilder.Append("\"fname\":\"" + strRename + "\",");
// cacheBuilder.Append("\"cur\":\"" + strCurrency + "\",");
// cacheBuilder.Append("\"stl\":" + Total.ToString() + ",");
// cacheBuilder.Append("\"cstl\":" + Total.ToString() + ",");
// cacheBuilder.Append("\"ustl\":" + 0 + ",");
// cacheBuilder.Append("\"orig\":3,");
// cacheBuilder.Append("\"oname\":\"" + strRename + "\",");
// cacheBuilder.Append("\"ocstl\":" + Total.ToString() + ",");
// cacheBuilder.Append("\"origcur\":\"\",");//原始币别
// cacheBuilder.Append("\"rate\":0");//原始币别
// cacheBuilder.Append("},");
// for (int i = 0; i < feeTable.Rows.Count; i++)
// {
// cacheBuilder.Append("{");
// cacheBuilder.Append("\"id\":\"" + feeTable.Rows[i]["GID"].ToString() + "\",");
// //int iFeeType = int.Parse(feeTable.Rows[i]["FEETYPE"].ToString()) == ? 1 : 2;
// cacheBuilder.Append("\"type\":" + feeTable.Rows[i]["FEETYPE"].ToString() + ",");
// cacheBuilder.Append("\"bsno\":\"" + feeTable.Rows[i]["BSNO"].ToString() + "\",");
// cacheBuilder.Append("\"cus\":\"" + feeTable.Rows[i]["CUSTOMERNAME"].ToString() + "\",");
// cacheBuilder.Append("\"fname\":\"" + feeTable.Rows[i]["FEENAME"].ToString() + "\",");
// cacheBuilder.Append("\"cur\":\"" + feeTable.Rows[i]["CURRENCY"].ToString() + "\",");
// cacheBuilder.Append("\"stl\":" + feeTable.Rows[i]["AMOUNT"].ToString() + ",");
// cacheBuilder.Append("\"cstl\":" + feeTable.Rows[i]["CTL"].ToString() + ",");
// cacheBuilder.Append("\"ustl\":" + feeTable.Rows[i]["UCTL"].ToString() + ",");
// cacheBuilder.Append("\"orig\":1,");
// cacheBuilder.Append("\"oname\":\"" + feeTable.Rows[i]["FEENAME"].ToString() + "\",");
// cacheBuilder.Append("\"ocstl\":" + feeTable.Rows[i]["CTL"].ToString() + ",");
// cacheBuilder.Append("\"origcur\":\"" + feeTable.Rows[i]["CURRENCY"].ToString() + "\",");//原始币别
// if (feeTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals("RMB") && strCurrency.ToUpper().Equals("USD"))
// {
// cacheBuilder.Append("\"rate\":" + dExchangeRate + "");//原始汇率
// }
// else if (feeTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals("USD") && strCurrency.ToUpper().Equals("RMB"))
// {
// cacheBuilder.Append("\"rate\":" + dExchangeRate + "");//原始汇率
// }
// else
// {
// cacheBuilder.Append("\"rate\":0");//原始汇率
// }
// cacheBuilder.Append("},");
// }
// }
// else
// {
// double exchangeRate = double.Parse(dExchangeRate.ToString());
// for (int i = 0; i < feeTable.Rows.Count; i++)
// {
// double dCSTLFee = 0.0;
// double dUSTLFee = 0.0;
// string tempCurrency = feeTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper();
// double tempFee = double.Parse(feeTable.Rows[i]["CTL"].ToString());
// double tempUFee = double.Parse(feeTable.Rows[i]["UCTL"].ToString());
// int tempFeeType = int.Parse(feeTable.Rows[i]["FEETYPE"].ToString());
// //if (tempCurrency.ToUpper().Equals("RMB") && strCurrency.ToUpper().Equals("USD"))
// //{
// // dCSTLFee = C1Round(tempFee * exchangeRate, 2);
// // dUSTLFee = C1Round(tempUFee * exchangeRate, 2);
// //}
// //else if (tempCurrency.ToUpper().Equals("USD") && strCurrency.ToUpper().Equals("RMB"))
// //{
// // dCSTLFee = C1Round(tempFee * exchangeRate, 2);
// // dUSTLFee = C1Round(tempUFee * exchangeRate, 2);
// //}
// //else
// //{
// // dCSTLFee = tempFee;
// // dUSTLFee = tempUFee;
// //}
// cacheBuilder.Append("{");
// cacheBuilder.Append("\"id\":\"" + feeTable.Rows[i]["GID"].ToString() + "\",");
// //int iFeeType = int.Parse(feeTable.Rows[i]["FEETYPE"].ToString()) == ? 1 : 2;
// cacheBuilder.Append("\"type\":" + feeTable.Rows[i]["FEETYPE"].ToString() + ",");
// cacheBuilder.Append("\"bsno\":\"" + feeTable.Rows[i]["BSNO"].ToString() + "\",");
// cacheBuilder.Append("\"cus\":\"" + feeTable.Rows[i]["CUSTOMERNAME"].ToString() + "\",");
// cacheBuilder.Append("\"fname\":\"" + feeTable.Rows[i]["FEENAME"].ToString() + "\",");
// cacheBuilder.Append("\"cur\":\"" + feeTable.Rows[i]["CURRENCY"].ToString() + "\",");
// cacheBuilder.Append("\"stl\":" + feeTable.Rows[i]["AMOUNT"].ToString() + ",");
// //cacheBuilder.Append("\"cstl\":" + dCSTLFee.ToString() + ",");
// //cacheBuilder.Append("\"ustl\":" + dUSTLFee.ToString() + ",");
// cacheBuilder.Append("\"cstl\":" + feeTable.Rows[i]["CTL"].ToString() + ",");
// cacheBuilder.Append("\"ustl\":" + feeTable.Rows[i]["UCTL"].ToString() + ",");
// cacheBuilder.Append("\"orig\":1,");
// cacheBuilder.Append("\"oname\":\"" + feeTable.Rows[i]["FEENAME"].ToString() + "\",");
// cacheBuilder.Append("\"ocstl\":" + feeTable.Rows[i]["CTL"].ToString() + ",");
// cacheBuilder.Append("\"origcur\":\"" + tempCurrency + "\",");//原始币别
// if (feeTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals("RMB") && strCurrency.ToUpper().Equals("USD"))
// {
// cacheBuilder.Append("\"rate\":" + dExchangeRate + "");//原始汇率
// }
// else if (feeTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals("USD") && strCurrency.ToUpper().Equals("RMB"))
// {
// cacheBuilder.Append("\"rate\":" + dExchangeRate + "");//原始汇率
// }
// else
// {
// cacheBuilder.Append("\"rate\":0");//原始汇率
// }
// cacheBuilder.Append("},");
// }
// }
// if (cacheBuilder.ToString().EndsWith(","))
// {
// appBuilder.Append(cacheBuilder.ToString().Substring(0, cacheBuilder.Length - 1));
// appBuilder.Append("]}");
// Session[tempPostSessionName] = appBuilder.ToString();
// strResult = strResult = GetPostResult(PostNoticeType.POSTSUCCESS);
// }
// else
// {
// appBuilder.Append(cacheBuilder.ToString());
// appBuilder.Append("]}");
// Session[tempPostSessionName] = appBuilder.ToString();
// strResult = strResult = GetPostResult(PostNoticeType.POSTSUCCESS);
// }
//}
#endregion
DataTable bsnoTable = null;
DataTable feeTable = null;
DataTable totalTable = null;
if (Session[tempBsnoCacheName] != null)
{
bsnoTable = (DataTable)Session[tempBsnoCacheName];
}
if (Session[tempCacheName] != null)
{
feeTable = (DataTable)Session[tempCacheName];
}
if (Session[tempTotalCacheName] != null)
{
totalTable = (DataTable)Session[tempTotalCacheName];
}
if (bsnoTable != null && feeTable != null && totalTable != null)
{
DataSet postSet = new DataSet();
postSet.Tables.Add(bsnoTable.Copy());
feeTable.TableName = "feeTableCopy";
postSet.Tables.Add(feeTable.Copy());
totalTable.TableName = "totalTableCopy";
postSet.Tables.Add(totalTable.Copy());
//postSet.Tables["bsno"]. = bsnoTable;
//postSet.Tables["fee"] = feeTable;
//postSet.Tables["total"] = totalTable;
Session[tempPostSessionName] = postSet;
strResult = GetPostResult(PostNoticeType.POSTSUCCESS);
}
else
{
strResult = GetPostResult(PostNoticeType.SESSIONFAILURE);
}
return strResult;
}
#endregion
#region 获取返回状态
/// <summary>
/// 获取返回状态
/// </summary>
/// <param name="tempPostNoticeType">错误类型</param>
/// <returns>返回String类型状态</returns>
private string GetPostResult(PostNoticeType tempPostNoticeType)
{
string strResult = "";
switch (tempPostNoticeType)
{
case PostNoticeType.DIFFCUSTOMER://同时有多个结算单位
strResult = "-1";
break;
case PostNoticeType.DIFFCURRENCY://有不同币别,需要调用汇率
strResult = "-2";
break;
case PostNoticeType.BEYONDMAXLINE://发票明细超过最大显示条数
strResult = "-3";
break;
case PostNoticeType.SESSIONFAILURE://缓存数据异常
strResult = "-4";
break;
case PostNoticeType.POSTSUCCESS://提交申请成功
strResult = "1";
break;
default:
break;
}
return strResult;
}
#endregion
#region 是否有不同的结算单位
/// <summary>
/// 是否有不同的结算单位
/// </summary>
/// <param name="tempDataTable">数据源</param>
/// <returns>值0表示不存在不同的结算单位 值1表示存在不同的结算单位 值小于0表示获取缓存数据异常</returns>
private int IsDifferentCustomer(DataTable tempDataTable)
{
int iResult = 0;
if (tempDataTable.Rows.Count > 0)
{
string strCustomerName = tempDataTable.Rows[0]["CUSTOMERNAME"].ToString().Trim();
int iCount = 0;
for (int i = 1; i < tempDataTable.Rows.Count; i++)
{
if (!tempDataTable.Rows[i]["CUSTOMERNAME"].ToString().Trim().Equals(strCustomerName))
{
iCount++;
break;
}
}
if (iCount > 0)
{
iResult = 1;//存在不同的结算单位
}
else
{
iResult = 0;//验证通过,不存在不同的结算单位
}
}
else
{
iResult = -1;//未取到缓存信息
}
return iResult;
}
#endregion
#region 查看是否有不同币别
/// <summary>
/// 查看是否有不同币别
/// </summary>
/// <param name="tempDataTable">数据源</param>
/// <returns>值0表示不存在不同的币别 值1表示存在不同的币别 值小于0表示获取缓存数据异常</returns>
private int IsDifferentCurrency(DataTable tempDataTable,string tempCurrency)
{
int iResult = 0;
if (tempDataTable.Rows.Count > 0)
{
string strCurrentCurrency = tempDataTable.Rows[0]["CURRENCY"].ToString().Trim();
int iEqualCount = 0;
if (strCurrentCurrency != tempCurrency)
{
iEqualCount++;
}
else
{
for (int i = 1; i < tempDataTable.Rows.Count; i++)
{
if (!tempDataTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals(strCurrentCurrency))
{
iEqualCount++;
break;
}
if (!tempDataTable.Rows[i]["CURRENCY"].ToString().Trim().ToUpper().Equals(tempCurrency))
{
iEqualCount++;
break;
}
}
}
if (iEqualCount > 0)
{
iResult = 1;//存在不同的币别
}
else
{
iResult = 0;//验证通过,不存在不同的币别
}
}
else
{
iResult = -1;//未取到缓存信息
}
return iResult;
}
#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 string CheckAllOrder(string tempSearch, string tempBSNOCacheName, string tempOrderCacheName, string tempTotalCacheName, string tempCheckType)
{
string strResult = "";
if (tempCheckType == "check")
{
#region 先获取全选的委托信息
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
string strSeaeCondition = "";
string strFeeCondition = "";
string strAuthorityCondition = "";
if (strDoTypeName != null)
{
if (strDoTypeName == "app")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppSearch");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEAPPSEARCH, strShowName, strCompanyID, strDeptName, strUserID);
}
}
else if (strDoTypeName == "import")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceImport");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEIMPORT, strShowName, strCompanyID, strDeptName, strUserID);
}
}
}
else
{
strAuthorityCondition = " AND 1< 0 ";
}
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "cus"://Customer
strFeeCondition += String.Format(" AND CUSTOMERNAME = '{0}' ", strArg[1].Replace("\"", ""));
break;
case "bno"://BillNO
strSeaeCondition += String.Format(" AND (CUSTNO LIKE '%{0}%' OR MBLNO LIKE '%{0}%' OR HBLNO LIKE '%{0}%' OR CUSTOMNO LIKE '%{0}%' OR CUSTOMNO2 LIKE '%{0}%')", strArg[1].Replace("\"", ""));
break;
case "bt"://ETD BeginDate
strSeaeCondition += String.Format(" AND ETD >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "et"://ETD EndDate
strSeaeCondition += String.Format(" AND ETD <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "ves"://Vessel
strSeaeCondition += String.Format(" AND VESSEL LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "voy"://Voyno
strSeaeCondition += String.Format(" AND VOYNO LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "fnm"://FeeName
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
int iFeeName = -1;
try
{
iFeeName = int.Parse(strArg[1].Replace("\"", "").Trim());
}
catch { }
if (iFeeName == -1)
{
strFeeCondition += String.Format(" AND FEENAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
}
}
break;
case "fty"://FeeType
int iFeeType = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iFeeType > 0)
{
strFeeCondition += String.Format(" AND FEETYPE = {0}", iFeeType);
}
break;
case "cur"://Currency
int iCurrency = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iCurrency == 1)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "RMB");
}
else if (iCurrency == 2)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "USD");
}
break;
case "amount1"://
strFeeCondition += String.Format(" AND AMOUNT >= '{0}'", strArg[1].Replace("\"", ""));
break;
case "amount2"://
strFeeCondition += String.Format(" AND AMOUNT <= '{0}'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
FeeSettlementDA feeSettlementDA = new FeeSettlementDA();
DataTable sourceTable;
//string strSql = " SELECT BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
// + " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) " + strFeeCondition + strAuthorityCondition + ") " + strSeaeCondition + " ORDER BY CUSTOMERNAME DESC ";
//string strSql = String.Format(" SELECT BSNO,'海运出口' OPLB, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
// + " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} "
// //+ " ORDER BY CUSTOMERNAME DESC "
// + " union all "
// + " SELECT BSNO,'海运进口' OPLB, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seai WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
// + " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} ORDER BY OPLB,CUSTOMERNAME DESC "
// , strFeeCondition, strAuthorityCondition, strSeaeCondition);
//2013-02-05 修改
string strSql = String.Format(" SELECT BSNO,OPLBNAME, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO,CUSTOMNO FROM VW_Settlement WHERE 1 > 0 AND BSNO IN ( "
+ " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
+ " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} "
//+ " and gid not in(select feeid from ch_fee_do where (ISDELETED<>1 or ISDELETED is null))"
+ ") {2} ORDER BY OPLB,CUSTOMERNAME DESC "
, strFeeCondition, strAuthorityCondition, strSeaeCondition);
sourceTable = feeSettlementDA.GetExcuteSql(strSql).Tables[0];
StringBuilder bsnoBuilder = new StringBuilder();
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (i == sourceTable.Rows.Count - 1)
{
bsnoBuilder.Append(sourceTable.Rows[i]["BSNO"].ToString());
}
else
{
bsnoBuilder.Append(sourceTable.Rows[i]["BSNO"].ToString() + ",");
}
}
if (Session[strBsnoCacheName] != null)
{
Session[strBsnoCacheName] = sourceTable;
}
else
{
Session[strBsnoCacheName] = sourceTable;
}
#endregion
#region 再缓存所有选中的委托相关的费用明细信息
string strFeeSql = String.Format(" SELECT BSNO,GID,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END AS CTL, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END AS UCTL, REMARK "
+ " FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) "
//+ " and gid not in(select feeid from ch_fee_do where (ISDELETED<>1 or ISDELETED is null))"
+ strFeeCondition + " ORDER BY CUSTOMERNAME DESC");
DataTable feeTable = feeSettlementDA.GetExcuteSql(strFeeSql).Tables[0];
if (Session[strOrderCacheName] != null)
{
Session[strOrderCacheName] = feeTable;
}
else
{
Session[strOrderCacheName] = feeTable;
}
#endregion
strResult = GetSumFeeJson(feeTable, 1, 1, true);
}
else
{
DataTable feeTable = null;
//如果是取消全部选中,则自动将缓存的委托、费用明细清除
if (Session[strOrderCacheName] != null)
{
Session.Remove(strOrderCacheName);
}
if (Session[strBsnoCacheName] != null)
{
Session.Remove(strBsnoCacheName);
}
strResult = GetSumFeeJson(feeTable, 1, 2, true);
}
return strResult;
}
private DataTable CreateTotalTable()
{
DataTable tempTable = new DataTable();
tempTable.Columns.Add("RECVRMB");
tempTable.Columns.Add("RECVUSD");
tempTable.Columns.Add("PAYRMB");
tempTable.Columns.Add("PAYUSD");
tempTable.Columns.Add("TOTALRMB");
tempTable.Columns.Add("TOTALUSD");
return tempTable;
}
private DataTable CreateBsnoTable()
{
DataTable tempTable = new DataTable();
tempTable.Columns.Add("BSNO");
tempTable.Columns.Add("CUSTOMERNAME");
tempTable.Columns.Add("CUSTNO");
tempTable.Columns.Add("MBLNO");
tempTable.Columns.Add("HBLNO");
return tempTable;
}
private DataTable CreateFeeTable()
{
DataTable tempTable = new DataTable();
tempTable.Columns.Add("GID");
tempTable.Columns.Add("BSNO");
tempTable.Columns.Add("FEETYPE");
tempTable.Columns.Add("CUSTOMERNAME");
tempTable.Columns.Add("FEENAME");
tempTable.Columns.Add("CURRENCY");
tempTable.Columns.Add("AMOUNT");
tempTable.Columns.Add("CTL");
tempTable.Columns.Add("UCTL");
return tempTable;
}
#region 根据查询条件获取委托列表信息
/// <summary>
/// 根据查询条件获取委托列表信息
/// </summary>
/// <param name="tempSearch">查询条件</param>
/// <returns>返回DataTable</returns>
private DataTable GetOrderTable(string tempSearch, string tempBSNO)
{
DataTable sourceTable;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
string strSeaeCondition = "";
string strFeeCondition = "";
string strAuthorityCondition = "";
if (strDoTypeName != null)
{
if (strDoTypeName == "app")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppSearch");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEAPPSEARCH, strShowName, strCompanyID, strDeptName, strUserID);
}
}
else if (strDoTypeName == "import")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceImport");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEIMPORT, strShowName, strCompanyID, strDeptName, strUserID);
}
}
}
else
{
strAuthorityCondition = " AND 1< 0 ";
}
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "cus"://Customer
strFeeCondition += String.Format(" AND CUSTOMERNAME = '{0}' ", strArg[1].Replace("\"", ""));
break;
case "bno"://BillNO
strSeaeCondition += String.Format(" AND (CUSTNO LIKE '%{0}%' OR MBLNO LIKE '%{0}%' OR HBLNO LIKE '%{0}%' OR CUSTOMNO LIKE '%{0}%' OR CUSTOMNO2 LIKE '%{0}%')", strArg[1].Replace("\"", ""));
break;
case "bt"://ETD BeginDate
strSeaeCondition += String.Format(" AND ETD >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "et"://ETD EndDate
strSeaeCondition += String.Format(" AND ETD <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "ves"://Vessel
strSeaeCondition += String.Format(" AND VESSEL LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "voy"://Voyno
strSeaeCondition += String.Format(" AND VOYNO LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "fnm"://FeeName
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
int iFeeName = -1;
try
{
iFeeName = int.Parse(strArg[1].Replace("\"", "").Trim());
}
catch { }
if (iFeeName == -1)
{
strFeeCondition += String.Format(" AND FEENAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
}
}
break;
case "fty"://FeeType
int iFeeType = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iFeeType > 0)
{
strFeeCondition += String.Format(" AND FEETYPE = {0}", iFeeType);
}
break;
case "cur"://Currency
int iCurrency = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iCurrency == 1)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "RMB");
}
else if (iCurrency == 2)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "USD");
}
break;
default:
break;
}
}
}
if (strBSNO != null)
{
strSeaeCondition += String.Format(" AND BSNO = '{0}' ", tempBSNO);
}
FeeSettlementDA feeSettlementDA = new FeeSettlementDA();
//string strSql = " SELECT BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE BSNO IN "
// + " (SELECT BSNO FROM ch_fee WHERE (ISNULL(SETTLEMENT,0) < AMOUNT AND ISNULL(ORDERAMOUNT,0) < AMOUNT AND (FEESTATUS = 0 OR FEESTATUS = 8)) "
// + strFeeCondition + strAuthorityCondition + " ) " + strSeaeCondition + " ORDER BY CUSTOMERNAME DESC ";
//string strSql = " SELECT BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
// + " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) " + strFeeCondition + strAuthorityCondition + ") " + strSeaeCondition + " ORDER BY CUSTOMERNAME DESC ";
//string strSql =String.Format( " SELECT BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
// + " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} "
// //+ " ORDER BY CUSTOMERNAME DESC "
// + " union all "
// + " SELECT BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seai WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
// + " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} ORDER BY CUSTOMERNAME DESC "
// , strFeeCondition, strAuthorityCondition, strSeaeCondition);
//2013-02-05 修改
string strSql = String.Format(" SELECT BSNO,CUSTOMERNAME,CUSTNO,MBLNO,HBLNO,CUSTOMNO,CUSTOMNO2 FROM VW_Settlement WHERE 1 > 0 AND BSNO IN ( "
+ " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
+ " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} "
//+ " and gid not in(select feeid from ch_fee_do where (ISDELETED<>1 or ISDELETED is null))"
+ " ) {2} ORDER BY CUSTOMERNAME DESC "
, strFeeCondition, strAuthorityCondition, strSeaeCondition);
sourceTable = feeSettlementDA.GetExcuteSql(strSql).Tables[0];
return sourceTable;
}
#endregion
#region 根据查询数据获取委托相关费用明细数据信息
/// <summary>
/// 根据查询数据获取委托相关费用明细数据信息
/// </summary>
/// <param name="tempSearch">查询条件</param>
/// <param name="tempBSNO">委托编号</param>
/// <returns>返回DataTable</returns>
private DataTable GetFeeByOrderBsnoTable(string tempSearch, string tempBSNO)
{
DataTable sourceTable;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
string strSeaeCondition = "";
string strFeeCondition = "";
string strAuthorityCondition = "";
if (strDoTypeName != null)
{
if (strDoTypeName == "app")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppSearch");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEAPPSEARCH, strShowName, strCompanyID, strDeptName, strUserID);
}
}
else if (strDoTypeName == "import")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceImport");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEIMPORT, strShowName, strCompanyID, strDeptName, strUserID);
}
}
}
else
{
strAuthorityCondition = " AND 1< 0 ";
}
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "cus"://Customer
strFeeCondition += String.Format(" AND CUSTOMERNAME = '{0}' ", strArg[1].Replace("\"", ""));
break;
case "bno"://BillNO
strSeaeCondition += String.Format(" AND (CUSTNO LIKE '%{0}%' OR MBLNO LIKE '%{0}%' OR HBLNO LIKE '%{0}%')", strArg[1].Replace("\"", ""));
break;
case "bt"://ETD BeginDate
strSeaeCondition += String.Format(" AND ETD >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "et"://ETD EndDate
strSeaeCondition += String.Format(" AND ETD <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "ves"://Vessel
strSeaeCondition += String.Format(" AND VESSEL LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "voy"://Voyno
strSeaeCondition += String.Format(" AND VOYNO LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "fnm"://FeeName
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
int iFeeName = -1;
try
{
iFeeName = int.Parse(strArg[1].Replace("\"", "").Trim());
}
catch { }
if (iFeeName == -1)
{
strFeeCondition += String.Format(" AND FEENAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
}
}
break;
case "fty"://FeeType
int iFeeType = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iFeeType > 0)
{
strFeeCondition += String.Format(" AND FEETYPE = {0}", iFeeType);
}
break;
case "cur"://Currency
int iCurrency = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iCurrency == 1)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "RMB");
}
else if (iCurrency == 2)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "USD");
}
break;
default:
break;
}
}
}
if (strBSNO != null)
{
strFeeCondition += String.Format(" AND BSNO = '{0}' ", tempBSNO);
}
string strSql = String.Format(" SELECT BSNO,GID,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END AS CTL, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END AS UCTL, REMARK "
+ " FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) AND BSNO IN ('{0}') AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) " + strFeeCondition
//+ " and gid not in(select feeid from ch_fee_do where (ISDELETED<>1 or ISDELETED is null))"
+ " ORDER BY CUSTOMERNAME DESC", tempBSNO);
FeeSettlementDA feeSettlementDA = new FeeSettlementDA();
sourceTable = feeSettlementDA.GetExcuteSql(strSql).Tables[0];
return sourceTable;
}
#endregion
#region 根据费用GID获取结算费用明细
/// <summary>
/// 根据费用GID获取结算费用明细
/// </summary>
/// <param name="tempFeeGID">费用GID</param>
/// <returns>返回DataTable费用数据集</returns>
private DataTable GetSimpleFeeByGID(string tempFeeGID)
{
DataTable sourceTable = null;
string strSql = String.Format(" SELECT BSNO,GID,FEETYPE,CUSTOMERNAME,FEENAME,CURRENCY,AMOUNT, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END AS CTL, "
+ " CASE WHEN ISINVOICE = 1 THEN CASE WHEN ISNULL(INVOICE,0) <> AMOUNT THEN CASE WHEN ISNULL(ORDERINVOICE,0) >= ISNULL(INVOICE,0) THEN AMOUNT - ISNULL(ORDERINVOICE,0) ELSE AMOUNT - ISNULL(INVOICE,0) END "
+ " ELSE AMOUNT - ISNULL(INVOICE,0) END ELSE AMOUNT - ISNULL(ORDERINVOICE,0) END AS UCTL, REMARK "
+ " FROM ch_fee WHERE GID = '{0}' ", tempFeeGID);
FeeSettlementDA feeSettlementDA = new FeeSettlementDA();
sourceTable = feeSettlementDA.GetExcuteSql(strSql).Tables[0];
return sourceTable;
}
#endregion
private string RefreshOrder(string tempSearch, string tempBSNOCacheName, string tempOrderCacheName, string tempTotalCacheName, string tempCheckType)
{
DataTable orderTable = new DataTable();
if (Session[tempBSNOCacheName] != null)
{
orderTable = (DataTable)Session[tempBSNOCacheName];
}
if (tempCheckType == "check")
{
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < orderTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + orderTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"1\",");
for (int j = 1; j < orderTable.Columns.Count; j++)
{
if (j == orderTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + orderTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + orderTable.Rows[i][j].ToString() + "\",");
}
}
if (i == orderTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
else
{
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
string strSeaeCondition = "";
string strFeeCondition = "";
string strAuthorityCondition = "";
if (strDoTypeName != null)
{
if (strDoTypeName == "app")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceAppSearch");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEAPPSEARCH, strShowName, strCompanyID, strDeptName, strUserID);
}
}
else if (strDoTypeName == "import")
{
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceImport");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEIMPORT, strShowName, strCompanyID, strDeptName, strUserID);
}
}
}
else
{
strAuthorityCondition = " AND 1< 0 ";
}
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "cus"://Customer
strFeeCondition += String.Format(" AND CUSTOMERNAME = '{0}' ", strArg[1].Replace("\"", ""));
break;
case "bno"://BillNO
strSeaeCondition += String.Format(" AND (CUSTNO LIKE '%{0}%' OR MBLNO LIKE '%{0}%' OR HBLNO LIKE '%{0}%' OR CUSTOMNO LIKE '%{0}%' OR CUSTOMNO2 LIKE '%{0}%')", strArg[1].Replace("\"", ""));
break;
case "bt"://ETD BeginDate
strSeaeCondition += String.Format(" AND ETD >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "et"://ETD EndDate
strSeaeCondition += String.Format(" AND ETD <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "ves"://Vessel
strSeaeCondition += String.Format(" AND VESSEL LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "voy"://Voyno
strSeaeCondition += String.Format(" AND VOYNO LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "fnm"://FeeName
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
int iFeeName = -1;
try
{
iFeeName = int.Parse(strArg[1].Replace("\"", "").Trim());
}
catch { }
if (iFeeName == -1)
{
strFeeCondition += String.Format(" AND FEENAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
}
}
break;
case "fty"://FeeType
int iFeeType = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iFeeType > 0)
{
strFeeCondition += String.Format(" AND FEETYPE = {0}", iFeeType);
}
break;
case "cur"://Currency
int iCurrency = int.Parse(strArg[1].Replace("\"", "").Trim());
if (iCurrency == 1)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "RMB");
}
else if (iCurrency == 2)
{
strFeeCondition += String.Format(" AND CURRENCY LIKE '%{0}%' ", "USD");
}
break;
case "amount1"://
strFeeCondition += String.Format(" AND AMOUNT >= '{0}'", strArg[1].Replace("\"", ""));
break;
case "amount2"://
strFeeCondition += String.Format(" AND AMOUNT <= '{0}'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
FeeSettlementDA feeSettlementDA = new FeeSettlementDA();
DataTable sourceTable;
//string strSql = " SELECT BSNO, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
// + " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) " + strFeeCondition + strAuthorityCondition + ") " + strSeaeCondition + " ORDER BY CUSTOMERNAME DESC ";
//string strSql = String.Format(" SELECT BSNO,'海运出口' OPLB, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seae WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
// + " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} "
// //+" ORDER BY CUSTOMERNAME DESC "
// + " union all "
// + " SELECT BSNO,'海运进口' OPLB, CUSTOMERNAME,CUSTNO,MBLNO,HBLNO FROM op_seai WHERE 1 > 0 AND BSNO IN ( "
// + " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
// + " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} ) {2} ORDER BY CUSTOMERNAME DESC "
// , strFeeCondition, strAuthorityCondition, strSeaeCondition);
//2013-02-05 修改
string strSql = String.Format(" SELECT BSNO,OPLBNAME,CUSTOMERNAME,CUSTNO,MBLNO,HBLNO,CUSTOMNO,CUSTOMNO2 FROM VW_Settlement WHERE 1 > 0 AND BSNO IN ( "
+ " SELECT BSNO FROM ch_fee WHERE ((ISINVOICE = 1 AND ISNULL(INVOICE,0) <> AMOUNT) OR (ISINVOICE = 0 AND ISNULL(ORDERINVOICE,0) <> AMOUNT)) "
+ " AND (FEESTATUS = 0 OR FEESTATUS = 8 OR FEESTATUS = 9) {0} {1} "
//+ " and gid not in(select feeid from ch_fee_do where (ISDELETED<>1 or ISDELETED is null))"
+ ") {2} ORDER BY CUSTOMERNAME DESC "
, strFeeCondition, strAuthorityCondition, strSeaeCondition);
sourceTable = feeSettlementDA.GetExcuteSql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
}
}
public enum PostNoticeType
{
DIFFCUSTOMER = 0,
DIFFCURRENCY = 1,
BEYONDMAXLINE = 2,
SESSIONFAILURE = 3,
POSTSUCCESS = 4
}
}