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.

2458 lines
125 KiB
C#

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsOpBillProfit;
using DSWeb.MvcShipping.Models.InfoSaleProfitSharePlan;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using System.IO;
using HcUtility.Core;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.MvcShipping.DAL.MsInfoSaleProfitShareSet;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.MvcShipping.DAL.MsRptSaleBalProfitShareDAL
{
public class MsRptSaleBalProfitShareDAL
{
#region 查询
static public List<MsOpBillProfit> GetDataList(string strCondition, string strStlCondition, string DStlCondition, string DStlCondition2, bool isdrzero, bool isallstl, string userid, string usercode, string companyid, string sort = null)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT * FROM (SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME,B.STLDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,T.STLTTLDR MONTHSTLTTLDR");
strSql.Append(",(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
strSql.Append(" FROM v_op_bill_gain B ");
if (isallstl)
{
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
}
else
{
strSql.Append("LEFT JOIN (select BSNO,MAX(SETTLETIME) SETTLETIME,SUM(ORIGAMOUNT*ORIGEXCHANGERATE) STLTTLDR FROM v_fee_do_settlement T WHERE FEETYPE='1' ");
if (!string.IsNullOrEmpty(strStlCondition))
{
strSql.Append(" and " + strStlCondition);
}
strSql.Append(" GROUP BY BSNO ) T ON (T.BSNO=B.BSNO) ");
}
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
if (!string.IsNullOrEmpty(strStlCondition))
{
strSql.Append(" and " + strStlCondition);
}
if (isdrzero) {
strSql.Append(" union SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME,B.STLDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,0 MONTHSTLTTLDR ");
strSql.Append(",(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSCR T ON (T.BSNO=B.BSNO) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where B.TTLDR=0 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='SALERPAMEND'");
if (RPTPRNOCANCEL.PARAMVALUE == "ACCDATE")
{
if (!string.IsNullOrEmpty(DStlCondition))
{
strSql.Append(" and " + DStlCondition);
}
}
else if (RPTPRNOCANCEL.PARAMVALUE == "AUDITDATE")
{
if (!string.IsNullOrEmpty(DStlCondition2))
{
strSql.Append(" and " + DStlCondition2);
}
}
}
strSql.Append(" ) AS V ");
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ETD desc");
}
return SetData(strSql);
}
static public string GetDataListStr(string strCondition, string strStlCondition, string DStlCondition, string DStlCondition2, bool isdrzero, bool isallstl, string userid, string usercode, string companyid, string sort = null)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT * FROM (SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME,B.STLDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,T.STLTTLDR MONTHSTLTTLDR ");
strSql.Append(",(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
strSql.Append(" FROM v_op_bill_gain B ");
if (isallstl)
{
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
}
else
{
strSql.Append("LEFT JOIN (select BSNO,MAX(SETTLETIME) SETTLETIME,SUM(ORIGAMOUNT*ORIGEXCHANGERATE) STLTTLDR FROM v_fee_do_settlement T WHERE FEETYPE='1' ");
if (!string.IsNullOrEmpty(strStlCondition))
{
strSql.Append(" and " + strStlCondition);
}
strSql.Append(" GROUP BY BSNO ) T ON (T.BSNO=B.BSNO) ");
}
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
if (!string.IsNullOrEmpty(strStlCondition))
{
strSql.Append(" and " + strStlCondition);
}
if (isdrzero)
{
strSql.Append(" union SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME,B.STLDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,0 MONTHSTLTTLDR ");
strSql.Append(",(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSCR T ON (T.BSNO=B.BSNO) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where B.TTLDR=0 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='SALERPAMEND'");
if (RPTPRNOCANCEL.PARAMVALUE == "ACCDATE")
{
if (!string.IsNullOrEmpty(DStlCondition))
{
strSql.Append(" and " + DStlCondition);
}
}
else if (RPTPRNOCANCEL.PARAMVALUE == "AUDITDATE")
{
if (!string.IsNullOrEmpty(DStlCondition2))
{
strSql.Append(" and " + DStlCondition2);
}
}
}
//
strSql.Append(" ) AS V ");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ETD desc");
}
return strSql.ToString();
}
private static List<MsOpBillProfit> SetData(StringBuilder strSql)
{
var headList = new List<MsOpBillProfit>();
Database db = DatabaseFactory.CreateDatabase();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 1200000; //要加这一句
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
MsOpBillProfit data = new MsOpBillProfit();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);//业务编号
data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.CARRIER = Convert.ToString(reader["CARRIER"]);
data.FORWARDER = Convert.ToString(reader["FORWARDER"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.OPDATE = Convert.ToString(reader["OPDATE"]);
data.CUSTOMDATE = Convert.ToString(reader["CUSTOMDATE"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.LANE = Convert.ToString(reader["LANE"]);
data.BLFRT = Convert.ToString(reader["BLFRT"]);
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
if (reader["RMBDR"] != DBNull.Value)
data.RMBDR = Convert.ToDecimal(reader["RMBDR"]);
if (reader["RMBCR"] != DBNull.Value)
data.RMBCR = Convert.ToDecimal(reader["RMBCR"]);
if (reader["STLRMBDR"] != DBNull.Value)
data.STLRMBDR = Convert.ToDecimal(reader["STLRMBDR"]);
if (reader["STLRMBCR"] != DBNull.Value)
data.STLRMBCR = Convert.ToDecimal(reader["STLRMBCR"]);
if (reader["RMBNODR"] != DBNull.Value)
data.RMBNODR = Convert.ToDecimal(reader["RMBNODR"]);
if (reader["RMBNOCR"] != DBNull.Value)
data.RMBNOCR = Convert.ToDecimal(reader["RMBNOCR"]);
if (reader["RMBPROFIT"] != DBNull.Value)
data.RMBPROFIT = Convert.ToDecimal(reader["RMBPROFIT"]);
if (reader["USDDR"] != DBNull.Value)
data.USDDR = Convert.ToDecimal(reader["USDDR"]);
if (reader["USDCR"] != DBNull.Value)
data.USDCR = Convert.ToDecimal(reader["USDCR"]);
if (reader["STLUSDDR"] != DBNull.Value)
data.STLUSDDR = Convert.ToDecimal(reader["STLUSDDR"]);
if (reader["STLUSDCR"] != DBNull.Value)
data.STLUSDCR = Convert.ToDecimal(reader["STLUSDCR"]);
if (reader["USDNODR"] != DBNull.Value)
data.USDNODR = Convert.ToDecimal(reader["USDNODR"]);
if (reader["USDNOCR"] != DBNull.Value)
data.USDNOCR = Convert.ToDecimal(reader["USDNOCR"]);
if (reader["USDPROFIT"] != DBNull.Value)
data.USDPROFIT = Convert.ToDecimal(reader["USDPROFIT"]);
if (reader["OTDR"] != DBNull.Value)
data.OTDR = Convert.ToDecimal(reader["OTDR"]);
if (reader["OTCR"] != DBNull.Value)
data.OTCR = Convert.ToDecimal(reader["OTCR"]);
if (reader["STLOTDR"] != DBNull.Value)
data.STLOTDR = Convert.ToDecimal(reader["STLOTDR"]);
if (reader["STLOTCR"] != DBNull.Value)
data.STLOTCR = Convert.ToDecimal(reader["STLOTCR"]);
if (reader["OTNODR"] != DBNull.Value)
data.OTNODR = Convert.ToDecimal(reader["OTNODR"]);
if (reader["OTNOCR"] != DBNull.Value)
data.OTNOCR = Convert.ToDecimal(reader["OTNOCR"]);
if (reader["OTPROFIT"] != DBNull.Value)
data.OTPROFIT = Convert.ToDecimal(reader["OTPROFIT"]);
if (reader["TTLDR"] != DBNull.Value)
data.TTLDR = Convert.ToDecimal(reader["TTLDR"]);
if (reader["TTLCR"] != DBNull.Value)
data.TTLCR = Convert.ToDecimal(reader["TTLCR"]);
if (reader["STLTTLDR"] != DBNull.Value)
data.STLTTLDR = Convert.ToDecimal(reader["STLTTLDR"]);
if (reader["MONTHSTLTTLDR"] != DBNull.Value)
data.MONTHSTLTTLDR = Convert.ToDecimal(reader["MONTHSTLTTLDR"]);
if (reader["STLTTLCR"] != DBNull.Value)
data.STLTTLCR = Convert.ToDecimal(reader["STLTTLCR"]);
if (reader["TTLNODR"] != DBNull.Value)
data.TTLNODR = Convert.ToDecimal(reader["TTLNODR"]);
if (reader["TTLNOCR"] != DBNull.Value)
data.TTLNOCR = Convert.ToDecimal(reader["TTLNOCR"]);
if (reader["TTLPROFIT"] != DBNull.Value)
data.TTLPROFIT = Convert.ToDecimal(reader["TTLPROFIT"]);
data.PROFITRATE = Convert.ToString(reader["PROFITRATE"]);
if (reader["SETTLETIME"] != DBNull.Value)
data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]).ToString("yyyy-MM-dd");
// if (reader["ISFEEREF"] != DBNull.Value && Convert.ToString(reader["ISFEEREF"])!="")
data.ISSALEFEE = Convert.ToString(reader["ISFEEREF"]);
data.INTEREST = Getlx(data.ETD, data.BSNO, data.SALE);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<MsOpBillProfit> GetLHDataList(string strCondition, string Month, string userid, string usercode, string companyid, string sort = null)
{
DateTime CurDateBegin = Convert.ToDateTime(Month + "-01");
DateTime CurDateEnd = CurDateBegin.AddMonths(1).AddDays(-1);
DateTime LastDateBegin = CurDateBegin.AddMonths(-1);
DateTime LastDateEnd = CurDateBegin.AddDays(-1);
DateTime LastFourDateBegin = CurDateBegin.AddMonths(-4);
var MsSaleMonthProfitList = GetSaleMonthDataList(strCondition, CurDateBegin, CurDateEnd);
var MsSaleMonthTTLProfitList = GetSaleMonthTTLDataList(strCondition, CurDateBegin, CurDateEnd);
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var etdmonth = LastDateBegin.ToString("yyyy-MM");
var saletravelfeelist = GetSaleTravelFeeList("ACCDATE>='" + LastFourDateBegin.ToString("yyyy-MM") + "'"," ACCDATE DESC ");
if (saletravelfeelist != null) {
foreach (var enumValue in saletravelfeelist)
{
MsSaleMonthTTLProfitList.ForEach(i =>
{
if (i.SALE == enumValue.SALE && i.ETDMONTH == enumValue.ACCDATE)
{
i.TRAVEFEE =enumValue.TRAVELFEEAMOUNT;
}
});
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT * FROM (SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME");
strSql.Append(",CASE WHEN B.STLDATE=B.ETD THEN B.STLDATE ELSE B.STLDATE+1 END STLDATE ");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.NOACCTAXTTLPROFIT TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,T.STLTTLDR MONTHSTLTTLDR,DATEDIFF([day],B.ETD,T.SETTLETIME) ACTUALDAY,DATEDIFF([day],CASE WHEN B.STLDATE=B.ETD THEN B.STLDATE ELSE B.STLDATE+1 END,T.SETTLETIME) NODAY");
strSql.Append(",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
strSql.Append(",isnull((select top 1 case ACCTYPE WHEN '月结' then accmonth*30 + accdays WHEN '季结' then accmonth*90 + accdays else accdays end from Info_Client_ACCDATE where LINKGID = (select top 1 GID from info_client where shortname =B.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=B.SALE)) and BGNDATE<=B.OPDATE AND ENDDATE>=B.OPDATE),0) NOMONTH ");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where B.TTLDR=B.STLTTLDR AND B.TTLDR<>0 ");
strSql.Append("AND ((T.SETTLETIME>='" + CurDateBegin.ToString("yyyy-MM-dd") + "' AND T.SETTLETIME<='" + CurDateEnd.ToString("yyyy-MM-dd 23:59:59") + "' ");
strSql.Append(" AND B.ACCDATE<'" + CurDateBegin.ToString("yyyy-MM") + "') OR (T.SETTLETIME>='" + LastDateBegin.ToString("yyyy-MM-dd") + "' AND T.SETTLETIME<='" + LastDateEnd.ToString("yyyy-MM-dd 23:59:59") + "' ");
strSql.Append(" AND B.ACCDATE>='" + LastDateBegin.ToString("yyyy-MM") + "' AND B.ACCDATE<='" + LastDateEnd.ToString("yyyy-MM") + "') ) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" union SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME");
strSql.Append(",CASE WHEN B.STLDATE=B.ETD THEN B.STLDATE ELSE B.STLDATE+1 END STLDATE ");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.NOACCTAXTTLPROFIT TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,0 MONTHSTLTTLDR,DATEDIFF([day],B.ETD,T.SETTLETIME) ACTUALDAY,DATEDIFF([day],CASE WHEN B.STLDATE=B.ETD THEN B.STLDATE ELSE B.STLDATE+1 END,T.SETTLETIME) NODAY");
strSql.Append(",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
strSql.Append(",isnull((select top 1 case ACCTYPE WHEN '月结' then accmonth*30 + accdays WHEN '季结' then accmonth*90 + accdays else accdays end from Info_Client_ACCDATE where LINKGID = (select top 1 GID from info_client where shortname =B.CUSTOMERNAME ) AND ((ISNULL(SALE,'')='') or (ISNULL(SALE,'')=B.SALE)) and BGNDATE<=B.OPDATE AND ENDDATE>=B.OPDATE),0) NOMONTH ");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_CR T ON (T.BSNO=B.BSNO) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where B.TTLCR=B.STLTTLCR AND B.TTLDR=0 ");
strSql.Append("AND ((T.SETTLETIME>='" + CurDateBegin.ToString("yyyy-MM-dd") + "' AND T.SETTLETIME<='" + CurDateEnd.ToString("yyyy-MM-dd 23:59:59") + "' ");
strSql.Append(" AND B.ACCDATE<'" + CurDateBegin.ToString("yyyy-MM") + "') OR (T.SETTLETIME>='" + LastDateBegin.ToString("yyyy-MM-dd") + "' AND T.SETTLETIME<='" + LastDateEnd.ToString("yyyy-MM-dd 23:59:59") + "' ");
strSql.Append(" AND B.ACCDATE>='" + LastDateBegin.ToString("yyyy-MM") + "' AND B.ACCDATE<='" + LastDateEnd.ToString("yyyy-MM") + "') ) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" ) AS V ");
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by SALE,(CASE WHEN TTLPROFIT<0 THEN convert(datetime,convert(varchar(7),ACCDATE)+'-01') ELSE convert(datetime,convert(varchar(7),ACCDATE)+'-02') END),SETTLETIME,CREATETIME DESC");
// strSql.Append(" order by SALE,SETTLETIME,ETD,CREATETIME DESC");
}
return SetLHData(strSql, MsSaleMonthProfitList, MsSaleMonthTTLProfitList);
}
static public List<MsSaleMonthProfit> GetSaleMonthDataList(string strCondition, DateTime CurDateBegin, DateTime CurDateEnd)
{
DateTime LastDateBegin = CurDateBegin.AddMonths(-1);
DateTime LastDateEnd = CurDateBegin.AddDays(-1);
DateTime LastThreeDateBegin = CurDateBegin.AddMonths(-3);
DateTime LastFourDateBegin = CurDateBegin.AddMonths(-4);
var strSql = new StringBuilder();
strSql.Append("SELECT SALE,ETDMONTH,SUM(TTLPROFIT) TTLPROFIT FROM (SELECT B.SALE,B.ACCDATE ETDMONTH,B.NOACCTAXTTLPROFIT TTLPROFIT");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
strSql.Append("where ");
strSql.Append(" B.TTLDR=B.STLTTLDR AND B.TTLDR<>0 AND T.SETTLETIME>='" + LastFourDateBegin.ToString("yyyy-MM-dd") + "' AND T.SETTLETIME<='" + LastDateEnd.ToString("yyyy-MM-dd 23:59:59") + "' ");
strSql.Append(" AND B.ACCDATE<'" + LastDateBegin.ToString("yyyy-MM") + "' and B.ACCDATE>='" + LastFourDateBegin.ToString("yyyy-MM") + "' ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" union ALL SELECT B.SALE,B.ACCDATE ETDMONTH,B.NOTAXTTLPROFIT TTLPROFIT");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_CR T ON (T.BSNO=B.BSNO) ");
strSql.Append("where B.TTLCR=B.STLTTLCR AND B.TTLDR=0 ");
strSql.Append("AND T.SETTLETIME>='" + LastFourDateBegin.ToString("yyyy-MM-dd") + "' AND T.SETTLETIME<='" + LastDateEnd.ToString("yyyy-MM-dd 23:59:59") + "' ");
strSql.Append(" AND B.ACCDATE<'" + LastDateBegin.ToString("yyyy-MM") + "' and B.ACCDATE>='" + LastFourDateBegin.ToString("yyyy-MM") + "' ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" ) AS V GROUP BY SALE,ETDMONTH ");
return SetSaleMonthData(strSql);
}
static public List<MsSaleMonthProfit> GetSaleMonthTTLDataList(string strCondition, DateTime CurDateBegin, DateTime CurDateEnd)
{
DateTime LastDateBegin = CurDateBegin.AddMonths(-1);
DateTime LastDateEnd = CurDateBegin.AddDays(-1);
DateTime LastThreeDateBegin = CurDateBegin.AddMonths(-3);
DateTime LastFourDateBegin = CurDateBegin.AddMonths(-4);
var strSql = new StringBuilder();
strSql.Append("SELECT SALE,ETDMONTH,SUM(TTLPROFIT) TTLPROFIT FROM (SELECT B.SALE,B.ACCDATE ETDMONTH,B.NOACCTAXTTLPROFIT TTLPROFIT");
strSql.Append(" FROM v_op_bill_gain B ");
//strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
strSql.Append("where ");
//strSql.Append(" B.TTLDR=B.STLTTLDR AND B.TTLDR<>0 ");
strSql.Append(" B.ACCDATE<'" + CurDateBegin.ToString("yyyy-MM") + "' and B.ACCDATE>='" + LastFourDateBegin.ToString("yyyy-MM") + "' ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//strSql.Append(" union ALL SELECT B.SALE,B.ACCDATE ETDMONTH,B.NOTAXTTLPROFIT TTLPROFIT");
//strSql.Append(" FROM v_op_bill_gain B ");
//strSql.Append("where B.TTLCR=B.STLTTLCR AND B.TTLDR=0 ");
//strSql.Append(" AND B.ACCDATE<'" + CurDateBegin.ToString("yyyy-MM") + "' and B.ACCDATE>='" + LastFourDateBegin.ToString("yyyy-MM") + "' ");
//if (!string.IsNullOrEmpty(strCondition))
//{
// strSql.Append(" and " + strCondition);
//}
strSql.Append(" ) AS V GROUP BY SALE,ETDMONTH ");
return SetSaleMonthData(strSql);
}
private static List<MsOpBillProfit> SetLHData(StringBuilder strSql, List<MsSaleMonthProfit> MsSaleMonthProfitList, List<MsSaleMonthProfit> MsSaleMonthTTLProfitList)
{
var saleprofitlist = MsInfoSaleProfitShareSetDAL.GetSaleProfitDetailDataList("");
var POORDAY = 0;
var MONTHPOORDAY = 0;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 1200000; //要加这一句
var headList = new List<MsOpBillProfit>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
MsOpBillProfit data = new MsOpBillProfit();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);//业务编号
data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.ETDMONTH = Convert.ToString(reader["ETDMONTH"]);
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.CARRIER = Convert.ToString(reader["CARRIER"]);
data.FORWARDER = Convert.ToString(reader["FORWARDER"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.OPDATE = Convert.ToString(reader["OPDATE"]);
data.CUSTOMDATE = Convert.ToString(reader["CUSTOMDATE"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.LANE = Convert.ToString(reader["LANE"]);
data.BLFRT = Convert.ToString(reader["BLFRT"]);
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.STLNAME = Convert.ToString(reader["STLNAME"]);
if (reader["RMBDR"] != DBNull.Value)
data.RMBDR = Convert.ToDecimal(reader["RMBDR"]);
if (reader["RMBCR"] != DBNull.Value)
data.RMBCR = Convert.ToDecimal(reader["RMBCR"]);
if (reader["STLRMBDR"] != DBNull.Value)
data.STLRMBDR = Convert.ToDecimal(reader["STLRMBDR"]);
if (reader["STLRMBCR"] != DBNull.Value)
data.STLRMBCR = Convert.ToDecimal(reader["STLRMBCR"]);
if (reader["RMBNODR"] != DBNull.Value)
data.RMBNODR = Convert.ToDecimal(reader["RMBNODR"]);
if (reader["RMBNOCR"] != DBNull.Value)
data.RMBNOCR = Convert.ToDecimal(reader["RMBNOCR"]);
if (reader["RMBPROFIT"] != DBNull.Value)
data.RMBPROFIT = Convert.ToDecimal(reader["RMBPROFIT"]);
if (reader["USDDR"] != DBNull.Value)
data.USDDR = Convert.ToDecimal(reader["USDDR"]);
if (reader["USDCR"] != DBNull.Value)
data.USDCR = Convert.ToDecimal(reader["USDCR"]);
if (reader["STLUSDDR"] != DBNull.Value)
data.STLUSDDR = Convert.ToDecimal(reader["STLUSDDR"]);
if (reader["STLUSDCR"] != DBNull.Value)
data.STLUSDCR = Convert.ToDecimal(reader["STLUSDCR"]);
if (reader["USDNODR"] != DBNull.Value)
data.USDNODR = Convert.ToDecimal(reader["USDNODR"]);
if (reader["USDNOCR"] != DBNull.Value)
data.USDNOCR = Convert.ToDecimal(reader["USDNOCR"]);
if (reader["USDPROFIT"] != DBNull.Value)
data.USDPROFIT = Convert.ToDecimal(reader["USDPROFIT"]);
if (reader["OTDR"] != DBNull.Value)
data.OTDR = Convert.ToDecimal(reader["OTDR"]);
if (reader["OTCR"] != DBNull.Value)
data.OTCR = Convert.ToDecimal(reader["OTCR"]);
if (reader["STLOTDR"] != DBNull.Value)
data.STLOTDR = Convert.ToDecimal(reader["STLOTDR"]);
if (reader["STLOTCR"] != DBNull.Value)
data.STLOTCR = Convert.ToDecimal(reader["STLOTCR"]);
if (reader["OTNODR"] != DBNull.Value)
data.OTNODR = Convert.ToDecimal(reader["OTNODR"]);
if (reader["OTNOCR"] != DBNull.Value)
data.OTNOCR = Convert.ToDecimal(reader["OTNOCR"]);
if (reader["OTPROFIT"] != DBNull.Value)
data.OTPROFIT = Convert.ToDecimal(reader["OTPROFIT"]);
if (reader["TTLDR"] != DBNull.Value)
data.TTLDR = Convert.ToDecimal(reader["TTLDR"]);
if (reader["TTLCR"] != DBNull.Value)
data.TTLCR = Convert.ToDecimal(reader["TTLCR"]);
if (reader["STLTTLDR"] != DBNull.Value)
data.STLTTLDR = Convert.ToDecimal(reader["STLTTLDR"]);
if (reader["MONTHSTLTTLDR"] != DBNull.Value)
data.MONTHSTLTTLDR = Convert.ToDecimal(reader["MONTHSTLTTLDR"]);
if (reader["STLTTLCR"] != DBNull.Value)
data.STLTTLCR = Convert.ToDecimal(reader["STLTTLCR"]);
if (reader["TTLNODR"] != DBNull.Value)
data.TTLNODR = Convert.ToDecimal(reader["TTLNODR"]);
if (reader["TTLNOCR"] != DBNull.Value)
data.TTLNOCR = Convert.ToDecimal(reader["TTLNOCR"]);
if (reader["TTLPROFIT"] != DBNull.Value)
data.TTLPROFIT = Convert.ToDecimal(reader["TTLPROFIT"]);
if (reader["ACTUALDAY"] != DBNull.Value)
data.ACTUALDAY = Convert.ToInt32(reader["ACTUALDAY"]);
if (reader["NODAY"] != DBNull.Value)
data.NODAY = Convert.ToInt32(reader["NODAY"]);
if (reader["NOMONTH"] != DBNull.Value)
data.NOMONTH = Convert.ToInt32(reader["NOMONTH"]);
if (data.TTLPROFIT < 0) {
data.ACTUALDAY = 0;
}
var isfind = false;
MsSaleMonthProfitList.ForEach(i =>
{
if (i.SALE == data.SALE && i.ETDMONTH == data.ETDMONTH)
{
i.TTLPROFIT = i.TTLPROFIT + data.TTLPROFIT;
data.COMPR = i.TTLPROFIT;
isfind = true;
}
});
MsSaleMonthTTLProfitList.ForEach(i =>
{
if (i.SALE == data.SALE && i.ETDMONTH == data.ETDMONTH)
{
data.MONTHTTLPR = i.TTLPROFIT;
data.MONTHTRAVEFEE = i.TRAVEFEE;
}
});
if (!isfind) {
var salemonthprofit = new MsSaleMonthProfit();
salemonthprofit.SALE = data.SALE;
salemonthprofit.ETDMONTH = data.ETDMONTH;
salemonthprofit.TTLPROFIT = data.TTLPROFIT;
data.COMPR = data.TTLPROFIT;
MsSaleMonthProfitList.Add(salemonthprofit);
}
decimal beginplan = 0;
decimal endplan = 0;
decimal SHAREPR = 0;
if (data.TTLPROFIT <= 0)
{
data.NODAY = 0;
}
saleprofitlist.ForEach(i =>
{
if (i.SALE == data.SALE && data.COMPR > i.PROFITDOWN && data.COMPR <= i.PROFITUP&& ((data.MONTHTTLPR>=i.PROFITPLAN&& i.PROFITPLAN>0) || (i.PROFITPLAN<=0)))
{
POORDAY = i.POORDAY;
MONTHPOORDAY = i.MONTHPOORDAY;
if (data.STLNAME == "现结买单" || data.STLNAME == "" || data.STLNAME == null)
{
data.ACTNODAY = data.NODAY;
//if (data.TTLPROFIT < 0)
//{
// data.ACTUALDAY = 0;
//}
if (data.ACTNODAY <= 21)
{
// data.NOMONTH = 0;
data.TiChengQuJian = 100;
}
else if (data.ACTNODAY > 22 && data.ACTNODAY <= 30)
{
// data.NOMONTH = 1;
data.TiChengQuJian = 80;
}
else if (data.ACTNODAY > 31 && data.ACTNODAY <= 45)
{
// data.NOMONTH = 2;
data.TiChengQuJian = 60;
}
else if (data.ACTNODAY > 46)
{
// data.NOMONTH = 3;
data.TiChengQuJian = 0;
}
// data.ACTNODAY = data.NODAY - POORDAY;
}
else
{
data.ACTNODAY = data.NODAY - MONTHPOORDAY;
//if (data.TTLPROFIT < 0)
//{
// data.ACTUALDAY = 0;
//}
if (data.ACTNODAY <= 0)
{
//data.NOMONTH = 0;
data.TiChengQuJian = 100;
}
else if (data.ACTNODAY > 0 && data.ACTNODAY <= 30)
{
// data.NOMONTH = 1;
data.TiChengQuJian = 80;
}
else if (data.ACTNODAY > 30 && data.ACTNODAY <= 60)
{
// data.NOMONTH = 2;
data.TiChengQuJian = 60;
}
else if (data.ACTNODAY > 60)
{
// data.NOMONTH = 3;
data.TiChengQuJian = 0;
}
}
data.TiChengBiLi = i.SHAREPR * data.TiChengQuJian / 100;
SHAREPR = i.SHAREPR;
beginplan = i.PROFITDOWN;
endplan = i.PROFITUP;
}
});
decimal lasttc = 0;
decimal lastpr = 0;
decimal lasttcxs = 0;
var TTLPROFIT = data.TTLPROFIT;
if ((data.COMPR - TTLPROFIT) >= (data.MONTHTTLPR - data.MONTHTRAVEFEE)&&data.COMPR>0)
TTLPROFIT = 0;
else if ((data.COMPR) >= (data.MONTHTTLPR - data.MONTHTRAVEFEE)&&(data.COMPR>0))
TTLPROFIT = (data.MONTHTTLPR - data.MONTHTRAVEFEE)- (data.COMPR - TTLPROFIT);
data.TiChengBiLiStr = Convert.ToString(data.TiChengQuJian / 100) + "*(" + TTLPROFIT.ToString() + "*" + Convert.ToString(SHAREPR / 100) + ")";
if (data.TiChengBiLi != 0) {
if (beginplan > (data.COMPR - TTLPROFIT)) {
var bpr = (data.COMPR - beginplan);
data.TiCheng = Math.Round(data.TiChengBiLi * bpr / 100, 2);
data.TiChengBiLiStr = Convert.ToString(data.TiChengQuJian / 100) + "*(" + bpr.ToString() + "*" + Convert.ToString(SHAREPR / 100) + ")";
lastpr = data.COMPR - TTLPROFIT;
saleprofitlist.ForEach(i =>
{
if (i.SALE == data.SALE && lastpr > i.PROFITDOWN && lastpr <= i.PROFITUP)
{
lasttcxs = i.SHAREPR * data.TiChengQuJian / 100;
SHAREPR = i.SHAREPR;
beginplan = i.PROFITDOWN;
endplan = i.PROFITUP;
}
});
if (TTLPROFIT - bpr > 0) {
lasttc = Math.Round(lasttcxs * (TTLPROFIT - bpr) / 100, 2);
if (lasttc != 0)
data.TiChengBiLiStr = data.TiChengBiLiStr + "+" + Convert.ToString(data.TiChengQuJian / 100) + "*(" + (TTLPROFIT - bpr).ToString() + "*" + Convert.ToString(SHAREPR / 100) + ")";
}
if (lasttc != 0) {
data.TiCheng = data.TiCheng + lasttc;
data.PRREMARK = "系数:" + lasttcxs.ToString() + "提成:" + lasttc.ToString();
}
} else
data.TiCheng = Math.Round(data.TiChengBiLi * TTLPROFIT / 100, 2);
} else data.TiCheng = 0;
data.PROFITRATE = Convert.ToString(reader["PROFITRATE"]);
if (reader["SETTLETIME"] != DBNull.Value)
data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]).ToString("yyyy-MM-dd");
data.ISSALEFEE = Convert.ToString(reader["ISFEEREF"]);
// data.ACTUALDAY=
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
private static List<MsSaleMonthProfit> SetSaleMonthData(StringBuilder strSql)
{
var headList = new List<MsSaleMonthProfit>();
Database db = DatabaseFactory.CreateDatabase();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 1200000; //要加这一句
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
MsSaleMonthProfit data = new MsSaleMonthProfit();
#region Set DB data to Object
data.SALE = Convert.ToString(reader["SALE"]);
data.ETDMONTH = Convert.ToString(reader["ETDMONTH"]);
if (reader["TTLPROFIT"] != DBNull.Value)
data.TTLPROFIT = Convert.ToDecimal(reader["TTLPROFIT"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
static public decimal Getlx(string etd, string bsno, string sale)
{
decimal result = 0;
if (etd == "" || sale == "") return 0;
var lxdataset = MsInfoSaleProfitShareSetDAL.GetSaleProfitLxDataList(" PLANID IN (SELECT TOP 1 PLANID FROM info_sale_profitShareSet WHERE SALE='" + sale + "') ");
if (lxdataset != null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" SETTLETIME,SUM(ORIGAMOUNT*ORIGEXCHANGERATE) AS AMOUNT ");
strSql.Append(" from v_fee_do_settlement ");
strSql.Append(" where BSNO='" + bsno + "' AND FEETYPE=1 ");
strSql.Append(" group by SETTLETIME ");
decimal amount = 0;
decimal lxrate = 0;
DateTime stldate;
DateTime etddate = Convert.ToDateTime(etd);
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
amount = Convert.ToDecimal(reader["AMOUNT"]);
stldate = Convert.ToDateTime(reader["SETTLETIME"]);
int days = Math.Abs((stldate - etddate).Days);
foreach (var enumValue in lxdataset)
{
if (enumValue.DEDUCTIN == 0) result = result + 0;
else
{
if (days >= enumValue.BDAY && days <= enumValue.EDAY)
{
lxrate = enumValue.DEDUCTIN / 100;
result = result + (amount * lxrate * (days - enumValue.BDAY));
}
else if (days > enumValue.EDAY)
{
lxrate = enumValue.DEDUCTIN / 100;
result = result + (amount * lxrate * (enumValue.EDAY - enumValue.BDAY));
}
}
}
}
reader.Close();
}
}
else result = 0;
return result;
}
public static DBResult SetFee(List<MsOpBillProfit> boday, String USERID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_sale_proftfee (GID,BSNO,ISFEE,FCOP,INPUTDATE,INPUTBY)
values (@GID,@BSNO,@ISFEE,@FCOP,@INPUTDATE,@INPUTBY) ");
var cmddelete =
db.GetSqlStringCommand(
@"delete from op_sale_proftfee where BSNO=@BSNO ");
foreach (var enumValue in boday)
{
cmddelete.Parameters.Clear();
db.AddInParameter(cmddelete, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmddelete, tran);
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdInsert, "@ISFEE", DbType.Boolean, true);
db.AddInParameter(cmdInsert, "@FCOP", DbType.String, enumValue.FCOP);
db.AddInParameter(cmdInsert, "@INPUTDATE", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, USERID);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
result = new DBResult();
result.Success = true;
result.Message = "设置完成";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "设置出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "设置完成";
return result;
}
public static DBResult SetFeeRQ(List<MsOpBillProfit> boday, string type,string ffdate,String USERID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
foreach (var enumValue in boday)
{
if (type == "1")
{
var cmdUpdate = db.GetSqlStringCommand(
@"if (select bsno from op_sale_proftfee where bsno='" + enumValue.BSNO + "') is null insert into op_sale_proftfee values(newid(),'" + enumValue.BSNO + "',1,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "','" + USERID + "','',0,'" + ffdate + "',null) else update op_sale_proftfee set ISFEEDATE='" + ffdate
+ "',ISFEE=1 where BSNO='" + enumValue.BSNO + "' ");
db.ExecuteNonQuery(cmdUpdate, tran);
} else if (type == "2")
{
var cmdUpdate = db.GetSqlStringCommand(
@"if (select bsno from op_sale_proftfee where bsno='" + enumValue.BSNO + "') is null insert into op_sale_proftfee values(newid(),'" + enumValue.BSNO + "',0,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "','" + USERID + "','',1,null,'" + ffdate + "') else update op_sale_proftfee set FCISFEEDATE='" + ffdate
+ "',FCISFEE=1 where BSNO='" + enumValue.BSNO + "' ");
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
result = new DBResult();
result.Success = true;
result.Message = "设置完成";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "设置出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "设置完成";
return result;
}
public static DBResult CancelSetFee(List<MsOpBillProfit> boday, String USERID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
//var cmddelete =
// db.GetSqlStringCommand(
// @"delete from op_sale_proftfee where BSNO=@BSNO ");
var cmdupdate =
db.GetSqlStringCommand(
@"update op_sale_proftfee set ISFEE=0 where BSNO=@BSNO ");
foreach (var enumValue in boday)
{
//if (enumValue.FCOP == "")
//{
// cmddelete.Parameters.Clear();
// db.AddInParameter(cmddelete, "@BSNO", DbType.String, enumValue.BSNO);
// db.ExecuteNonQuery(cmddelete, tran);
//}
//else {
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdupdate, tran);
//}
}
}
result = new DBResult();
result.Success = true;
result.Message = "设置完成";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "设置出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "设置完成";
return result;
}
public static DBResult CancelSetFeeRQ(List<MsOpBillProfit> boday, String USERID,string type)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
//var cmddelete =
// db.GetSqlStringCommand(
// @"delete from op_sale_proftfee where BSNO=@BSNO ");
foreach (var enumValue in boday)
{
if (type == "1")
{
var cmdupdate =
db.GetSqlStringCommand(
@"update op_sale_proftfee set ISFEE=0,ISFEEDATE=null where BSNO=@BSNO ");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdupdate, tran);
}
else if (type == "2")
{
var cmdupdate =
db.GetSqlStringCommand(
@"update op_sale_proftfee set FCISFEE=0,FCISFEEDATE=null where BSNO=@BSNO ");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdupdate, tran);
}
}
}
result = new DBResult();
result.Success = true;
result.Message = "设置完成";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "设置出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "设置完成";
return result;
}
public static DBResult SaveFee(List<MsOpBillProfit> boday, String USERID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_sale_proftfee (GID,BSNO,ISFEE,FCOP,INPUTDATE,INPUTBY,FCISFEE,ISFEEDATE,FCISFEEDATE)
values (@GID,@BSNO,@ISFEE,@FCOP,@INPUTDATE,@INPUTBY,@FCISFEE,@ISFEEDATE,@FCISFEEDATE) ");
var cmddelete =
db.GetSqlStringCommand(
@"delete from op_sale_proftfee where BSNO=@BSNO ");
foreach (var enumValue in boday)
{
cmddelete.Parameters.Clear();
db.AddInParameter(cmddelete, "@BSNO", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmddelete, tran);
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, enumValue.BSNO);
if (enumValue.ISSALEFEE == "已发放")
db.AddInParameter(cmdInsert, "@ISFEE", DbType.Boolean, true);
else
db.AddInParameter(cmdInsert, "@ISFEE", DbType.Boolean, false);
if (enumValue.ISFCSALEFEE == "已发放")
db.AddInParameter(cmdInsert, "@FCISFEE", DbType.Boolean, true);
else
db.AddInParameter(cmdInsert, "@FCISFEE", DbType.Boolean, false);
if (enumValue.ISFEEDATE == "")
db.AddInParameter(cmdInsert, "@ISFEEDATE", DbType.String, null);
else
db.AddInParameter(cmdInsert, "@ISFEEDATE", DbType.String, enumValue.ISFEEDATE);
if (enumValue.FCISFEEDATE == "")
db.AddInParameter(cmdInsert, "@FCISFEEDATE", DbType.String, null);
else
db.AddInParameter(cmdInsert, "@FCISFEEDATE", DbType.String, enumValue.FCISFEEDATE);
db.AddInParameter(cmdInsert, "@FCOP", DbType.String, enumValue.FCOP);
db.AddInParameter(cmdInsert, "@INPUTDATE", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, USERID);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
result = new DBResult();
result.Success = true;
result.Message = "设置完成";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "设置出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "设置完成";
return result;
}
static public List<OpSaleTravelFee> GetSaleTravelFeeList(string strCondition, string sort)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,SALE,ACCDATE,TRAVELFEEAMOUNT,INPUTDATE,INPUTBY");
strSql.Append(",(select ShowName from [user] where GID=op_sale_travelfee.INPUTBY) as INPUTBYREF");
strSql.Append(" FROM op_sale_travelfee ");
strSql.Append("where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ACCDATE DESC,SALE ");
//if (amendstr == "true")
// strSql.Append(" order by F.CUSTOMERNAME,A.OPDATE ");
//else strSql.Append(" order by F.CUSTOMERNAME,B.OPDATE ");
}
return SetOpSaleTravelFeeData(strSql);
}
private static List<OpSaleTravelFee> SetOpSaleTravelFeeData(StringBuilder strSql)
{
var headList = new List<OpSaleTravelFee>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
OpSaleTravelFee data = new OpSaleTravelFee();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
if (reader["TRAVELFEEAMOUNT"] != DBNull.Value)
data.TRAVELFEEAMOUNT = Convert.ToDecimal(reader["TRAVELFEEAMOUNT"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]);
if (reader["INPUTDATE"] != DBNull.Value)
data.INPUTDATE = Convert.ToDateTime(reader["INPUTDATE"]).ToString("yyyy-MM-dd");
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveTravelFee(List<OpSaleTravelFee> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_sale_travelfee (GID,SALE,ACCDATE,TRAVELFEEAMOUNT,INPUTBY,INPUTDATE)
values (@GID,@SALE,@ACCDATE,@TRAVELFEEAMOUNT,@INPUTBY,@INPUTDATE) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_sale_travelfee set SALE=@SALE,ACCDATE=@ACCDATE,TRAVELFEEAMOUNT=@TRAVELFEEAMOUNT,INPUTBY=@INPUTBY,INPUTDATE=@INPUTDATE where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.GID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@SALE", DbType.String, enumValue.SALE);
db.AddInParameter(cmdInsert, "@ACCDATE", DbType.String, enumValue.ACCDATE);
db.AddInParameter(cmdInsert, "@TRAVELFEEAMOUNT", DbType.Decimal, enumValue.TRAVELFEEAMOUNT);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid);
db.AddInParameter(cmdInsert, "@INPUTDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@SALE", DbType.String, enumValue.SALE);
db.AddInParameter(cmdUpdate, "@ACCDATE", DbType.String, enumValue.ACCDATE);
db.AddInParameter(cmdUpdate, "@TRAVELFEEAMOUNT", DbType.Decimal, enumValue.TRAVELFEEAMOUNT);
db.AddInParameter(cmdUpdate, "@INPUTBY", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@INPUTDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult DeleteOpSaleTravelDetail(List<OpSaleTravelFee> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmd = db.GetSqlStringCommand("delete from op_sale_travelfee where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmd, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
#region 瑞琴提成
static public List<MsOpBillProfit> GetRQDataList(string strCondition, string strStlCondition, string DStlCondition, string DStlCondition2, bool isdrzero, bool isallstl, string userid, string usercode, string companyid, string sort = null)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT * FROM (SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME,B.DELIVERYDATE STLDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,T.STLTTLDR MONTHSTLTTLDR,f.FCOP,DATEDIFF([day],B.DELIVERYDATE,T.SETTLETIME) NODAY,c.TICHENG,c.FENCHENG,c.TICHENGCANYU ");
strSql.Append(",(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,(CASE f.FCISFEE WHEN 1 THEN '已发放' else '未发放' end) as FCISFEEREF,f.ISFEEDATE,f.FCISFEEDATE ");
strSql.Append(" FROM v_op_bill_gain_tc B ");
if (isallstl)
{
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
// strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR PT ON (PT.BSNO=B.PARENTID) ");
}
else
{
strSql.Append("LEFT JOIN (select BSNO,MAX(SETTLETIME) SETTLETIME,SUM(ORIGAMOUNT*ORIGEXCHANGERATE) STLTTLDR FROM v_fee_do_settlement T WHERE FEETYPE='1' ");
if (!string.IsNullOrEmpty(strStlCondition))
{
strSql.Append(" and " + strStlCondition);
}
strSql.Append(" GROUP BY BSNO ) T ON (T.BSNO=B.BSNO) ");
}
strSql.Append("LEFT JOIN info_client c ON (c.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
if (!string.IsNullOrEmpty(strStlCondition))
{
strSql.Append(" and " + strStlCondition);
}
if (isdrzero)
{
strSql.Append(" union SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME,B.DELIVERYDATE STLDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",(CASE WHEN OPTYPE='更改单' THEN PT.SETTLETIME ELSE T.SETTLETIME END) SETTLETIME ,f.ISFEE,0 MONTHSTLTTLDR,f.FCOP,(CASE WHEN OPTYPE='更改单' THEN DATEDIFF([day],B.DELIVERYDATE,PT.SETTLETIME) ELSE 30 END) NODAY,c.TICHENG,c.FENCHENG,c.TICHENGCANYU ");
strSql.Append(",(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,(CASE f.FCISFEE WHEN 1 THEN '已发放' else '未发放' end) as FCISFEEREF,f.ISFEEDATE,f.FCISFEEDATE ");
strSql.Append(" FROM v_op_bill_gain_tc B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSCR T ON (T.BSNO=B.BSNO) ");
strSql.Append("LEFT JOIN info_client c ON (c.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where B.TTLDR=0 ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR PT ON (PT.BSNO=B.PARENTID) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='SALERPAMEND'");
if (RPTPRNOCANCEL.PARAMVALUE == "ACCDATE")
{
if (!string.IsNullOrEmpty(DStlCondition))
{
strSql.Append(" and " + DStlCondition);
}
}
else if (RPTPRNOCANCEL.PARAMVALUE == "AUDITDATE")
{
if (!string.IsNullOrEmpty(DStlCondition2))
{
strSql.Append(" and " + DStlCondition2);
}
}
}
strSql.Append(" ) AS V ");
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ETD desc");
}
return SetRQData(strSql);
}
private static List<MsOpBillProfit> SetRQData(StringBuilder strSql)
{
var headList = new List<MsOpBillProfit>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpBillProfit data = new MsOpBillProfit();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);//业务编号
data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);
data.FEESTATUS = Convert.ToString(reader["FEESTATUS"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.CARRIER = Convert.ToString(reader["CARRIER"]);
data.FORWARDER = Convert.ToString(reader["FORWARDER"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.OPDATE = Convert.ToString(reader["OPDATE"]);
data.CUSTOMDATE = Convert.ToString(reader["CUSTOMDATE"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.LANE = Convert.ToString(reader["LANE"]);
data.BLFRT = Convert.ToString(reader["BLFRT"]);
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.FCOP = Convert.ToString(reader["FCOP"]);
data.TICHENGCANYU = Convert.ToString(reader["TICHENGCANYU"]);
if (data.FCOP == "") data.FCOP = data.TICHENGCANYU;
if (reader["STLDATE"] != DBNull.Value)
data.STLDATE = Convert.ToDateTime(reader["STLDATE"]).ToString("yyyy-MM-dd");
if (reader["RMBDR"] != DBNull.Value)
data.RMBDR = Convert.ToDecimal(reader["RMBDR"]);
if (reader["RMBCR"] != DBNull.Value)
data.RMBCR = Convert.ToDecimal(reader["RMBCR"]);
if (reader["STLRMBDR"] != DBNull.Value)
data.STLRMBDR = Convert.ToDecimal(reader["STLRMBDR"]);
if (reader["STLRMBCR"] != DBNull.Value)
data.STLRMBCR = Convert.ToDecimal(reader["STLRMBCR"]);
if (reader["RMBNODR"] != DBNull.Value)
data.RMBNODR = Convert.ToDecimal(reader["RMBNODR"]);
if (reader["RMBNOCR"] != DBNull.Value)
data.RMBNOCR = Convert.ToDecimal(reader["RMBNOCR"]);
if (reader["RMBPROFIT"] != DBNull.Value)
data.RMBPROFIT = Convert.ToDecimal(reader["RMBPROFIT"]);
if (reader["USDDR"] != DBNull.Value)
data.USDDR = Convert.ToDecimal(reader["USDDR"]);
if (reader["USDCR"] != DBNull.Value)
data.USDCR = Convert.ToDecimal(reader["USDCR"]);
if (reader["STLUSDDR"] != DBNull.Value)
data.STLUSDDR = Convert.ToDecimal(reader["STLUSDDR"]);
if (reader["STLUSDCR"] != DBNull.Value)
data.STLUSDCR = Convert.ToDecimal(reader["STLUSDCR"]);
if (reader["USDNODR"] != DBNull.Value)
data.USDNODR = Convert.ToDecimal(reader["USDNODR"]);
if (reader["USDNOCR"] != DBNull.Value)
data.USDNOCR = Convert.ToDecimal(reader["USDNOCR"]);
if (reader["USDPROFIT"] != DBNull.Value)
data.USDPROFIT = Convert.ToDecimal(reader["USDPROFIT"]);
if (reader["OTDR"] != DBNull.Value)
data.OTDR = Convert.ToDecimal(reader["OTDR"]);
if (reader["OTCR"] != DBNull.Value)
data.OTCR = Convert.ToDecimal(reader["OTCR"]);
if (reader["STLOTDR"] != DBNull.Value)
data.STLOTDR = Convert.ToDecimal(reader["STLOTDR"]);
if (reader["STLOTCR"] != DBNull.Value)
data.STLOTCR = Convert.ToDecimal(reader["STLOTCR"]);
if (reader["OTNODR"] != DBNull.Value)
data.OTNODR = Convert.ToDecimal(reader["OTNODR"]);
if (reader["OTNOCR"] != DBNull.Value)
data.OTNOCR = Convert.ToDecimal(reader["OTNOCR"]);
if (reader["OTPROFIT"] != DBNull.Value)
data.OTPROFIT = Convert.ToDecimal(reader["OTPROFIT"]);
if (reader["TTLDR"] != DBNull.Value)
data.TTLDR = Convert.ToDecimal(reader["TTLDR"]);
if (reader["TTLCR"] != DBNull.Value)
data.TTLCR = Convert.ToDecimal(reader["TTLCR"]);
if (reader["STLTTLDR"] != DBNull.Value)
data.STLTTLDR = Convert.ToDecimal(reader["STLTTLDR"]);
if (reader["STLTTLCR"] != DBNull.Value)
data.STLTTLCR = Convert.ToDecimal(reader["STLTTLCR"]);
if (reader["TTLNODR"] != DBNull.Value)
data.TTLNODR = Convert.ToDecimal(reader["TTLNODR"]);
if (reader["TTLNOCR"] != DBNull.Value)
data.TTLNOCR = Convert.ToDecimal(reader["TTLNOCR"]);
if (reader["TTLPROFIT"] != DBNull.Value)
data.TTLPROFIT = Convert.ToDecimal(reader["TTLPROFIT"]);
if (reader["NODAY"] != DBNull.Value)
data.NODAY = Convert.ToInt32(reader["NODAY"]);
data.PROFITRATE = Convert.ToString(reader["PROFITRATE"]);
if (reader["SETTLETIME"] != DBNull.Value)
data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]).ToString("yyyy-MM-dd");
data.ISSALEFEE = Convert.ToString(reader["ISFEEREF"]);
data.ISFCSALEFEE = Convert.ToString(reader["FCISFEEREF"]);
if (reader["ISFEEDATE"] != DBNull.Value)
data.ISFEEDATE = Convert.ToDateTime(reader["ISFEEDATE"]).ToString("yyyy-MM-dd");
if (reader["FCISFEEDATE"] != DBNull.Value)
data.FCISFEEDATE = Convert.ToDateTime(reader["FCISFEEDATE"]).ToString("yyyy-MM-dd");
if (reader["TICHENG"] != DBNull.Value)
data.TiChengBiLi = Convert.ToDecimal(reader["TICHENG"]);
if (reader["FENCHENG"] != DBNull.Value)
data.TiChengQuJian = Convert.ToDecimal(reader["FENCHENG"]);
if (data.TiChengBiLi != 0)
{
if (data.TTLPROFIT >= 0)
{
if (data.STLDATE == "")
{
data.ShiJiTiChengBiLi = data.TiChengBiLi;
}
else
{
if (data.NODAY < 0)
data.ShiJiTiChengBiLi = data.TiChengBiLi + 2;
else
{
decimal bili = Math.Round(data.NODAY * Convert.ToDecimal(2) / Convert.ToDecimal(30), 4);
data.ShiJiTiChengBiLi = Math.Round(Convert.ToDecimal(data.TiChengBiLi + 2 - bili), 2);
}
}
data.TiChengJiShu = data.TTLPROFIT * data.ShiJiTiChengBiLi / 100;
data.TiCheng = data.TTLPROFIT * data.ShiJiTiChengBiLi / 100 * (1 - data.TiChengQuJian / 100);
data.ShiFa = data.TTLPROFIT * data.ShiJiTiChengBiLi / 100 * (data.TiChengQuJian / 100);
}
else
{
if (data.STLDATE == "")
{
data.ShiJiTiChengBiLi = data.TiChengBiLi;
data.TiChengJiShu = (data.TTLPROFIT * data.TiChengBiLi / 100);
}
else
{
if (data.NODAY < 0)
{
data.ShiJiTiChengBiLi = data.TiChengBiLi;
data.TiChengJiShu = (data.TTLPROFIT * data.TiChengBiLi / 100);
}
else
{
data.NODAY = data.NODAY - 30;
decimal bili = Math.Round(data.NODAY * Convert.ToDecimal(2) / Convert.ToDecimal(30), 4);
data.ShiJiTiChengBiLi = Math.Round(data.TiChengBiLi + bili, 2);
data.TiChengJiShu = data.TTLPROFIT * data.ShiJiTiChengBiLi / 100;
}
}
data.TiCheng = data.TiChengJiShu * (1 - data.TiChengQuJian / 100);
data.ShiFa = data.TiChengJiShu * (data.TiChengQuJian / 100);
}
}
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 倍通提成
static public List<MsOpBillProfit> GetBTDataList(string strCondition, string strStlCondition, string DStlCondition, string DStlCondition2, string dateCondition, string datetype, bool isdrzero, bool isallstl, string userid, string usercode, string companyid, string sort = null)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var MsSaleMonthProfitList = GetBTSaleMonthDataList(dateCondition);
var strSql = new StringBuilder();
strSql.Append("SELECT * FROM (SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME,B.STLDATE STLDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,T.STLTTLDR MONTHSTLTTLDR,f.FCOP,DATEDIFF([day],B.STLDATE,T.SETTLETIME) NODAY,c.TICHENG,c.FENCHENG ");
strSql.Append(",(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
strSql.Append(" FROM v_op_bill_gain B ");
if (isallstl)
{
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
}
else
{
strSql.Append("LEFT JOIN (select BSNO,MAX(SETTLETIME) SETTLETIME,SUM(ORIGAMOUNT*ORIGEXCHANGERATE) STLTTLDR FROM v_fee_do_settlement T WHERE FEETYPE='1' ");
if (!string.IsNullOrEmpty(strStlCondition))
{
strSql.Append(" and " + strStlCondition);
}
strSql.Append(" GROUP BY BSNO ) T ON (T.BSNO=B.BSNO) ");
}
strSql.Append("LEFT JOIN info_client c ON (c.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
if (!string.IsNullOrEmpty(strStlCondition))
{
strSql.Append(" and " + strStlCondition);
}
if (isdrzero)
{
strSql.Append(" union SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME,B.STLDATE STLDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,0 MONTHSTLTTLDR,f.FCOP,30 NODAY,c.TICHENG,c.FENCHENG ");
strSql.Append(",(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSCR T ON (T.BSNO=B.BSNO) ");
strSql.Append("LEFT JOIN info_client c ON (c.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where B.TTLDR=0 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='SALERPAMEND'");
if (RPTPRNOCANCEL.PARAMVALUE == "ACCDATE")
{
if (!string.IsNullOrEmpty(DStlCondition))
{
strSql.Append(" and " + DStlCondition);
}
}
else if (RPTPRNOCANCEL.PARAMVALUE == "AUDITDATE")
{
if (!string.IsNullOrEmpty(DStlCondition2))
{
strSql.Append(" and " + DStlCondition2);
}
}
}
strSql.Append(" ) AS V ");
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ETD desc");
}
return SetBTData(strSql, MsSaleMonthProfitList, datetype);
}
private static List<MsOpBillProfit> SetBTData(StringBuilder strSql, List<MsSaleMonthProfit> MsSaleMonthProfitList, string datetype)
{
var saleprofitlist = MsInfoSaleProfitShareSetDAL.GetSaleProfitDetailDataList("");
var POORDAY = 0;
var MONTHPOORDAY = 0;
var headList = new List<MsOpBillProfit>();
Database db = DatabaseFactory.CreateDatabase();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 1200000; //要加这一句
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
MsOpBillProfit data = new MsOpBillProfit();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);//业务编号
data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.CARRIER = Convert.ToString(reader["CARRIER"]);
data.FORWARDER = Convert.ToString(reader["FORWARDER"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.OPDATE = Convert.ToString(reader["OPDATE"]);
data.CUSTOMDATE = Convert.ToString(reader["CUSTOMDATE"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.LANE = Convert.ToString(reader["LANE"]);
data.BLFRT = Convert.ToString(reader["BLFRT"]);
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]);
data.STLDATE = Convert.ToString(reader["STLDATE"]);//结算时间
data.CORPID = Convert.ToString(reader["CORPID"]);
if (reader["RMBDR"] != DBNull.Value)
data.RMBDR = Convert.ToDecimal(reader["RMBDR"]);
if (reader["RMBCR"] != DBNull.Value)
data.RMBCR = Convert.ToDecimal(reader["RMBCR"]);
if (reader["STLRMBDR"] != DBNull.Value)
data.STLRMBDR = Convert.ToDecimal(reader["STLRMBDR"]);
if (reader["STLRMBCR"] != DBNull.Value)
data.STLRMBCR = Convert.ToDecimal(reader["STLRMBCR"]);
if (reader["RMBNODR"] != DBNull.Value)
data.RMBNODR = Convert.ToDecimal(reader["RMBNODR"]);
if (reader["RMBNOCR"] != DBNull.Value)
data.RMBNOCR = Convert.ToDecimal(reader["RMBNOCR"]);
if (reader["RMBPROFIT"] != DBNull.Value)
data.RMBPROFIT = Convert.ToDecimal(reader["RMBPROFIT"]);
if (reader["USDDR"] != DBNull.Value)
data.USDDR = Convert.ToDecimal(reader["USDDR"]);
if (reader["USDCR"] != DBNull.Value)
data.USDCR = Convert.ToDecimal(reader["USDCR"]);
if (reader["STLUSDDR"] != DBNull.Value)
data.STLUSDDR = Convert.ToDecimal(reader["STLUSDDR"]);
if (reader["STLUSDCR"] != DBNull.Value)
data.STLUSDCR = Convert.ToDecimal(reader["STLUSDCR"]);
if (reader["USDNODR"] != DBNull.Value)
data.USDNODR = Convert.ToDecimal(reader["USDNODR"]);
if (reader["USDNOCR"] != DBNull.Value)
data.USDNOCR = Convert.ToDecimal(reader["USDNOCR"]);
if (reader["USDPROFIT"] != DBNull.Value)
data.USDPROFIT = Convert.ToDecimal(reader["USDPROFIT"]);
if (reader["OTDR"] != DBNull.Value)
data.OTDR = Convert.ToDecimal(reader["OTDR"]);
if (reader["OTCR"] != DBNull.Value)
data.OTCR = Convert.ToDecimal(reader["OTCR"]);
if (reader["STLOTDR"] != DBNull.Value)
data.STLOTDR = Convert.ToDecimal(reader["STLOTDR"]);
if (reader["STLOTCR"] != DBNull.Value)
data.STLOTCR = Convert.ToDecimal(reader["STLOTCR"]);
if (reader["OTNODR"] != DBNull.Value)
data.OTNODR = Convert.ToDecimal(reader["OTNODR"]);
if (reader["OTNOCR"] != DBNull.Value)
data.OTNOCR = Convert.ToDecimal(reader["OTNOCR"]);
if (reader["OTPROFIT"] != DBNull.Value)
data.OTPROFIT = Convert.ToDecimal(reader["OTPROFIT"]);
if (reader["TTLDR"] != DBNull.Value)
data.TTLDR = Convert.ToDecimal(reader["TTLDR"]);
if (reader["TTLCR"] != DBNull.Value)
data.TTLCR = Convert.ToDecimal(reader["TTLCR"]);
if (reader["STLTTLDR"] != DBNull.Value)
data.STLTTLDR = Convert.ToDecimal(reader["STLTTLDR"]);
if (reader["STLTTLCR"] != DBNull.Value)
data.STLTTLCR = Convert.ToDecimal(reader["STLTTLCR"]);
if (reader["TTLNODR"] != DBNull.Value)
data.TTLNODR = Convert.ToDecimal(reader["TTLNODR"]);
if (reader["TTLNOCR"] != DBNull.Value)
data.TTLNOCR = Convert.ToDecimal(reader["TTLNOCR"]);
if (reader["TTLPROFIT"] != DBNull.Value)
data.TTLPROFIT = Convert.ToDecimal(reader["TTLPROFIT"]);
if (reader["NODAY"] != DBNull.Value)
data.NODAY = Convert.ToInt32(reader["NODAY"]);
data.PROFITRATE = Convert.ToString(reader["PROFITRATE"]);
if (reader["SETTLETIME"] != DBNull.Value)
data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]).ToString("yyyy-MM-dd");
data.ISSALEFEE = Convert.ToString(reader["ISFEEREF"]);
var mssaleprofit = MsSaleMonthProfitList.Find(i => i.SALE == data.SALE);
var ttlprofit = mssaleprofit.TTLPROFIT;
var monthnum = 0;
if (data.STLDATE != "")
{
if (datetype == "ACCDATE")
monthnum = betweenmonth(Convert.ToDateTime(data.ACCDATE + "-01"), Convert.ToDateTime(data.STLDATE));
else
monthnum = betweenmonth(Convert.ToDateTime(data.OPDATE), Convert.ToDateTime(data.STLDATE));
monthnum = monthnum - 1;
var saleprofit = saleprofitlist.Find(i => i.SALE == data.SALE && ttlprofit > i.PROFITDOWN && ttlprofit <= i.PROFITUP && i.MONTHNUM == monthnum);
if (saleprofit != null)
{
if (monthnum == 0)
data.TiChengBiLi = saleprofit.SHAREPR;
else data.TiChengBiLi = saleprofit.BEFORESHAREPR;
}
}
if (data.SETTLETIME != "")
{
if (datetype == "ACCDATE")
monthnum = betweenmonth(Convert.ToDateTime(data.ACCDATE + "-01"), Convert.ToDateTime(data.SETTLETIME));
else
monthnum = betweenmonth(Convert.ToDateTime(data.OPDATE), Convert.ToDateTime(data.SETTLETIME));
monthnum = monthnum - 1;
var saleprofit2 = saleprofitlist.Find(i => i.SALE == data.SALE && ttlprofit > i.PROFITDOWN && ttlprofit <= i.PROFITUP && i.MONTHNUM == monthnum);
if (saleprofit2 != null)
{
if (monthnum == 0)
data.ShiJiTiChengBiLi = saleprofit2.SHAREPR;
else data.ShiJiTiChengBiLi = saleprofit2.BEFORESHAREPR;
data.TiCheng = data.TTLPROFIT * data.TiChengBiLi / 100;
data.ShiFa = data.TTLPROFIT * data.ShiJiTiChengBiLi / 100;
}
}
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<MsSaleMonthProfit> SumBTData(List<MsOpBillProfit> MsOpBillProfit)
{
var headList = new List<MsSaleMonthProfit>();
foreach (var enumValue in MsOpBillProfit)
{
var isfind = false;
headList.ForEach(i =>
{
if (i.SALE == enumValue.SALE)
{
i.TTLPROFIT = i.TTLPROFIT + enumValue.TTLPROFIT;
i.TiCheng = i.TiCheng + enumValue.TiCheng;
i.ShiFa = i.ShiFa + enumValue.ShiFa;
isfind = true;
}
});
if (!isfind)
{
var salemonthprofit = new MsSaleMonthProfit();
salemonthprofit.SALE = enumValue.SALE;
salemonthprofit.TTLPROFIT = enumValue.TTLPROFIT;
salemonthprofit.TiCheng = enumValue.TiCheng;
salemonthprofit.ShiFa = enumValue.ShiFa;
headList.Add(salemonthprofit);
}
}
return headList;
}
public static int betweenmonth(DateTime d1, DateTime d2)
{
DateTime max = d1 > d2 ? d1 : d2;
DateTime min = d1 > d2 ? d2 : d1;
int yeardiff = max.Year - min.Year;
int monthdiff = max.Month - min.Month;
return yeardiff * 12 + monthdiff + 1;
}
static public List<MsSaleMonthProfit> GetBTSaleMonthDataList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT SALE,SUM(isnull(TTLPROFIT,0)) TTLPROFIT,'' ETDMONTH FROM (SELECT B.SALE,B.TTLPROFIT");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
strSql.Append("where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" ) AS V GROUP BY SALE ");
return SetSaleMonthData(strSql);
}
#endregion
#region 恒洋提成
static public List<MsOpBillProfit> GetHYDataList(string strCondition, string strStlCondition, string DStlCondition, string DStlCondition2, string dateCondition, string datetype, bool isdrzero, bool isallstl, string userid, string usercode, string companyid, string sort = null)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var MsSaleMonthProfitList = GetBTSaleMonthDataList(dateCondition);
var strSql = new StringBuilder();
strSql.Append("SELECT * FROM (SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME,B.STLDATE STLDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,T.STLTTLDR MONTHSTLTTLDR,f.FCOP,DATEDIFF([day],B.STLDATE,T.SETTLETIME) NODAY,c.TICHENG,c.FENCHENG ");
strSql.Append(",dbo.F_HYKOUXI(B.BSNO,B.BSSOURCE,B.ETD) as KOUXI ");
strSql.Append(",(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
strSql.Append("LEFT JOIN info_client c ON (c.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
if (!string.IsNullOrEmpty(strStlCondition))
{
strSql.Append(" and " + strStlCondition);
}
if (isdrzero)
{
strSql.Append(" union SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("B.ETD,B.OPDATE,B.CUSTOMDATE,B.FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL,B.STLNAME,B.STLDATE STLDATE");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",B.RMBDR,B.RMBCR,B.STLRMBDR,B.STLRMBCR,B.USDDR,B.USDCR,B.STLUSDDR,B.STLUSDCR,B.OTDR,B.OTCR,B.STLOTDR,B.STLOTCR,B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
strSql.Append(",B.USDPROFIT,B.RMBPROFIT,B.OTPROFIT,B.TTLPROFIT,B.PROFITRATE,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
strSql.Append(",T.SETTLETIME,f.ISFEE,0 MONTHSTLTTLDR,f.FCOP,30 NODAY,c.TICHENG,c.FENCHENG ");
strSql.Append(",(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSCR T ON (T.BSNO=B.BSNO) ");
strSql.Append("LEFT JOIN info_client c ON (c.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append("LEFT JOIN op_sale_proftfee f ON (f.BSNO=B.BSNO) where B.TTLDR=0 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='SALERPAMEND'");
if (RPTPRNOCANCEL.PARAMVALUE == "ACCDATE")
{
if (!string.IsNullOrEmpty(DStlCondition))
{
strSql.Append(" and " + DStlCondition);
}
}
else if (RPTPRNOCANCEL.PARAMVALUE == "AUDITDATE")
{
if (!string.IsNullOrEmpty(DStlCondition2))
{
strSql.Append(" and " + DStlCondition2);
}
}
}
strSql.Append(" ) AS V ");
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ETD desc");
}
return SetHYData(strSql, MsSaleMonthProfitList, datetype);
}
private static List<MsOpBillProfit> SetHYData(StringBuilder strSql, List<MsSaleMonthProfit> MsSaleMonthProfitList, string datetype)
{
var saleprofitlist = MsInfoSaleProfitShareSetDAL.GetSaleProfitDetailDataList("");
var POORDAY = 0;
var MONTHPOORDAY = 0;
var headList = new List<MsOpBillProfit>();
Database db = DatabaseFactory.CreateDatabase();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 1200000; //要加这一句
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
MsOpBillProfit data = new MsOpBillProfit();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);//业务编号
data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.CARRIER = Convert.ToString(reader["CARRIER"]);
data.FORWARDER = Convert.ToString(reader["FORWARDER"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.OPDATE = Convert.ToString(reader["OPDATE"]);
data.CUSTOMDATE = Convert.ToString(reader["CUSTOMDATE"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.LANE = Convert.ToString(reader["LANE"]);
data.BLFRT = Convert.ToString(reader["BLFRT"]);
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]);
data.STLDATE = Convert.ToString(reader["STLDATE"]);//结算时间
data.CORPID = Convert.ToString(reader["CORPID"]);
if (reader["RMBDR"] != DBNull.Value)
data.RMBDR = Convert.ToDecimal(reader["RMBDR"]);
if (reader["RMBCR"] != DBNull.Value)
data.RMBCR = Convert.ToDecimal(reader["RMBCR"]);
if (reader["STLRMBDR"] != DBNull.Value)
data.STLRMBDR = Convert.ToDecimal(reader["STLRMBDR"]);
if (reader["STLRMBCR"] != DBNull.Value)
data.STLRMBCR = Convert.ToDecimal(reader["STLRMBCR"]);
if (reader["RMBNODR"] != DBNull.Value)
data.RMBNODR = Convert.ToDecimal(reader["RMBNODR"]);
if (reader["RMBNOCR"] != DBNull.Value)
data.RMBNOCR = Convert.ToDecimal(reader["RMBNOCR"]);
if (reader["RMBPROFIT"] != DBNull.Value)
data.RMBPROFIT = Convert.ToDecimal(reader["RMBPROFIT"]);
if (reader["USDDR"] != DBNull.Value)
data.USDDR = Convert.ToDecimal(reader["USDDR"]);
if (reader["USDCR"] != DBNull.Value)
data.USDCR = Convert.ToDecimal(reader["USDCR"]);
if (reader["STLUSDDR"] != DBNull.Value)
data.STLUSDDR = Convert.ToDecimal(reader["STLUSDDR"]);
if (reader["STLUSDCR"] != DBNull.Value)
data.STLUSDCR = Convert.ToDecimal(reader["STLUSDCR"]);
if (reader["USDNODR"] != DBNull.Value)
data.USDNODR = Convert.ToDecimal(reader["USDNODR"]);
if (reader["USDNOCR"] != DBNull.Value)
data.USDNOCR = Convert.ToDecimal(reader["USDNOCR"]);
if (reader["USDPROFIT"] != DBNull.Value)
data.USDPROFIT = Convert.ToDecimal(reader["USDPROFIT"]);
if (reader["OTDR"] != DBNull.Value)
data.OTDR = Convert.ToDecimal(reader["OTDR"]);
if (reader["OTCR"] != DBNull.Value)
data.OTCR = Convert.ToDecimal(reader["OTCR"]);
if (reader["STLOTDR"] != DBNull.Value)
data.STLOTDR = Convert.ToDecimal(reader["STLOTDR"]);
if (reader["STLOTCR"] != DBNull.Value)
data.STLOTCR = Convert.ToDecimal(reader["STLOTCR"]);
if (reader["OTNODR"] != DBNull.Value)
data.OTNODR = Convert.ToDecimal(reader["OTNODR"]);
if (reader["OTNOCR"] != DBNull.Value)
data.OTNOCR = Convert.ToDecimal(reader["OTNOCR"]);
if (reader["OTPROFIT"] != DBNull.Value)
data.OTPROFIT = Convert.ToDecimal(reader["OTPROFIT"]);
if (reader["TTLDR"] != DBNull.Value)
data.TTLDR = Convert.ToDecimal(reader["TTLDR"]);
if (reader["TTLCR"] != DBNull.Value)
data.TTLCR = Convert.ToDecimal(reader["TTLCR"]);
if (reader["STLTTLDR"] != DBNull.Value)
data.STLTTLDR = Convert.ToDecimal(reader["STLTTLDR"]);
if (reader["STLTTLCR"] != DBNull.Value)
data.STLTTLCR = Convert.ToDecimal(reader["STLTTLCR"]);
if (reader["TTLNODR"] != DBNull.Value)
data.TTLNODR = Convert.ToDecimal(reader["TTLNODR"]);
if (reader["TTLNOCR"] != DBNull.Value)
data.TTLNOCR = Convert.ToDecimal(reader["TTLNOCR"]);
if (reader["TTLPROFIT"] != DBNull.Value)
data.TTLPROFIT = Convert.ToDecimal(reader["TTLPROFIT"]);
if (reader["KOUXI"] != DBNull.Value)
data.KouXi = Convert.ToDecimal(reader["KOUXI"]);
if (reader["NODAY"] != DBNull.Value)
data.NODAY = Convert.ToInt32(reader["NODAY"]);
data.PROFITRATE = Convert.ToString(reader["PROFITRATE"]);
if (reader["SETTLETIME"] != DBNull.Value)
data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]).ToString("yyyy-MM-dd");
data.ISSALEFEE = Convert.ToString(reader["ISFEEREF"]);
var mssaleprofit = MsSaleMonthProfitList.Find(i => i.SALE == data.SALE);
var ttlprofit = mssaleprofit.TTLPROFIT;
var monthnum = 0;
if (data.STLDATE != "")
{
if (datetype == "ACCDATE")
monthnum = betweenmonth(Convert.ToDateTime(data.ACCDATE + "-01"), Convert.ToDateTime(data.STLDATE));
else
monthnum = betweenmonth(Convert.ToDateTime(data.OPDATE), Convert.ToDateTime(data.STLDATE));
var saleprofit = saleprofitlist.Find(i => i.SALE == data.SALE && ttlprofit > i.PROFITDOWN && ttlprofit <= i.PROFITUP && i.MONTHNUM == monthnum);
if (saleprofit != null)
{
if (monthnum == 0)
data.TiChengBiLi = saleprofit.SHAREPR;
else data.TiChengBiLi = saleprofit.BEFORESHAREPR;
}
}
if (data.SETTLETIME != "")
{
if (datetype == "ACCDATE")
monthnum = betweenmonth(Convert.ToDateTime(data.ACCDATE + "-01"), Convert.ToDateTime(data.SETTLETIME));
else
monthnum = betweenmonth(Convert.ToDateTime(data.OPDATE), Convert.ToDateTime(data.SETTLETIME));
var saleprofit2 = saleprofitlist.Find(i => i.SALE == data.SALE && ttlprofit > i.PROFITDOWN && ttlprofit <= i.PROFITUP && i.MONTHNUM == monthnum);
if (saleprofit2 != null)
{
if (monthnum == 0)
data.ShiJiTiChengBiLi = saleprofit2.SHAREPR;
else data.ShiJiTiChengBiLi = saleprofit2.BEFORESHAREPR;
data.TiCheng = data.TTLPROFIT * data.TiChengBiLi / 100;
data.ShiFa = (data.TTLPROFIT - data.KouXi) * data.ShiJiTiChengBiLi / 100;
}
}
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<MsSaleMonthProfit> GetHYSaleMonthDataList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT SALE,SUM(isnull(TTLPROFIT,0)) TTLPROFIT,'' ETDMONTH FROM (SELECT B.SALE,B.TTLPROFIT");
strSql.Append(" FROM v_op_bill_gain B ");
strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
strSql.Append("where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" ) AS V GROUP BY SALE ");
return SetSaleMonthData(strSql);
}
#endregion
public static string GetRangDAStr(string tb, string userid, string usercode, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modSaleProfitShare' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = "1=2";
}
else if (visiblerange == "3")
{
str = " (B.OP='" + usercode + "' OR B.SALE='" + usercode + "')";
}
else if (visiblerange == "2")
{
if (tb == "index")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
var userstr = new StringBuilder();
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " (B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
}
else
{
str = str + " or B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
};
}
str = str + ")";
reader.Close();
}
}
else
{
str = " UPPER(B.Corpid)='" + companyid + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(B.Corpid)='" + companyid + "'";
}
return str;
}
}
}