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 ;
using DSWeb.Common.DB ;
using System.Linq ;
using DSWeb.MvcShipping.DAL.MsRptZjTotalDAL ;
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 ;
}
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 ) ;
saleprofitlist . ForEach ( i = >
{
if ( i . SALE = = data . SALE & & ( ( data . COMPR > i . PROFITDOWN ) | | ( ( data . COMPR - TTLPROFIT ) > i . PROFITDOWN ) ) & & ( ( 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 ;
if ( ( ( data . COMPR - TTLPROFIT ) < = i . PROFITUP | | data . COMPR < = i . PROFITUP ) )
{
if ( data . COMPR < = i . PROFITUP )
{
var TMPTTLPROFIT = TTLPROFIT ;
if ( ( data . COMPR - TTLPROFIT ) < = i . PROFITDOWN ) TMPTTLPROFIT = ( data . COMPR - i . PROFITDOWN + 1 ) - ( data . TTLPROFIT - TTLPROFIT ) ;
//TMPTTLPROFIT = TMPTTLPROFIT + 1;
data . TiCheng = data . TiCheng + TMPTTLPROFIT * data . TiChengBiLi / 100 ;
if ( ! string . IsNullOrEmpty ( data . TiChengBiLiStr ) )
data . TiChengBiLiStr = data . TiChengBiLiStr + "+" + Convert . ToString ( data . TiChengQuJian / 100 ) + "*(" + TMPTTLPROFIT . ToString ( ) + "*" + Convert . ToString ( SHAREPR / 100 ) + ")" ;
else
data . TiChengBiLiStr = Convert . ToString ( data . TiChengQuJian / 100 ) + "*(" + TMPTTLPROFIT . ToString ( ) + "*" + Convert . ToString ( SHAREPR / 100 ) + ")" ;
}
else
{
var TMPTTLPROFIT = ( i . PROFITUP - i . PROFITDOWN ) + 1 ;
if ( ( data . COMPR - data . TTLPROFIT ) > i . PROFITDOWN ) TMPTTLPROFIT = ( i . PROFITUP - ( data . COMPR - data . TTLPROFIT ) ) ;
if ( TTLPROFIT = = 0 ) TMPTTLPROFIT = 0 ;
data . TiCheng = data . TiCheng + TMPTTLPROFIT * data . TiChengBiLi / 100 ;
if ( ! string . IsNullOrEmpty ( data . TiChengBiLiStr ) )
data . TiChengBiLiStr = data . TiChengBiLiStr + "+" + Convert . ToString ( data . TiChengQuJian / 100 ) + "*(" + TMPTTLPROFIT . ToString ( ) + "*" + Convert . ToString ( SHAREPR / 100 ) + ")" ;
else
data . TiChengBiLiStr = Convert . ToString ( data . TiChengQuJian / 100 ) + "*(" + TMPTTLPROFIT . ToString ( ) + "*" + Convert . ToString ( SHAREPR / 100 ) + ")" ;
}
}
}
} ) ;
//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
#region 晨星
static public List < MsOpBillProfit > GetCXDataList ( string strCondition , string Month , string expDate_Min , string expDate_Max , 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 ) ;
if ( ! string . IsNullOrEmpty ( expDate_Min ) ) CurDateBegin = Convert . ToDateTime ( expDate_Min ) ;
if ( ! string . IsNullOrEmpty ( expDate_Max ) ) CurDateEnd = Convert . ToDateTime ( expDate_Max ) ;
var rangstr = GetRangDAStr ( "index" , userid , usercode , companyid ) ;
var strConditionAll = strCondition ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strConditionAll = strCondition + " and " + rangstr ;
}
else
{
strConditionAll = rangstr ;
}
}
var strSql = new StringBuilder ( ) ;
strSql . Append ( " if object_id('tempdb..##SALEPROFITSHARE" + usercode + "') is not null Begin DROP TABLE ##SALEPROFITSHARE" + usercode + " End " ) ;
strSql . Append ( "SELECT * into ##SALEPROFITSHARE" + usercode + " 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.FEESTATUSREF,B.BLFRT,B.STLNAME" ) ;
strSql . Append ( ",B.STLDATE " ) ;
strSql . Append ( ",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.CNTRTOTAL,B.CORPID" ) ;
strSql . Append ( ",B.FEESTATUS" ) ;
strSql . Append ( ",B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR" ) ;
strSql . Append ( ",B.TTLPROFIT,B.TTLNODR,B.TTLNOCR " ) ;
strSql . Append ( ",B.SETTLETIME,f.ISFEE,DATEDIFF([day],B.ETD,B.SETTLETIME) ACTUALDAY,DATEDIFF([day],B.STLDATE,B.SETTLETIME) NODAY" ) ;
strSql . Append ( ",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF " ) ;
strSql . Append ( " FROM v_op_bill_gain_cxtc B " ) ;
strSql . Append ( "LEFT JOIN op_sale_tc f ON (f.BSNO=B.BSNO) where B.NODAILIBALDR=0 AND B.TTLDR<>0 AND B.TTLPROFIT>=0 " ) ;
strSql . Append ( "AND ((B.SETTLETIME>='" + CurDateBegin . ToString ( "yyyy-MM-dd" ) + "' AND B.SETTLETIME<='" + CurDateEnd . ToString ( "yyyy-MM-dd 23:59:59" ) + "' " ) ;
strSql . Append ( " AND B.ACCDATE<='" + Month + "') OR " ) ;
strSql . Append ( " ( B.ACCDATE='" + CurDateBegin . ToString ( "yyyy-MM" ) + "' AND B.SETTLETIME<'" + CurDateBegin . ToString ( "yyyy-MM-dd" ) + "') ) " ) ;
if ( ! string . IsNullOrEmpty ( strConditionAll ) )
{
strSql . Append ( " and " + strConditionAll ) ;
}
//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(",B.STLDATE ");
//strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
//strSql.Append(",B.FEESTATUS");
//strSql.Append(",B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
//strSql.Append(",B.TTLPROFIT,B.TTLNODR,B.TTLNOCR ");
//strSql.Append(",B.SETTLETIME,f.ISFEE,DATEDIFF([day],B.ETD,B.SETTLETIME) ACTUALDAY,DATEDIFF([day],B.STLDATE,B.SETTLETIME) NODAY");
//strSql.Append(",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
//strSql.Append(" FROM v_op_bill_gain_cxtc 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 AND B.TTLPROFIT>=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") + "') ");
//if (!string.IsNullOrEmpty(strConditionAll))
//{
// strSql.Append(" and " + strConditionAll);
//}
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.FEESTATUSREF,B.BLFRT,B.STLNAME" ) ;
strSql . Append ( ",B.STLDATE " ) ;
strSql . Append ( ",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.CNTRTOTAL,B.CORPID" ) ;
strSql . Append ( ",B.FEESTATUS" ) ;
strSql . Append ( ",B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR" ) ;
strSql . Append ( ",B.TTLPROFIT,B.TTLNODR,B.TTLNOCR " ) ;
strSql . Append ( ",B.SETTLETIME,f.ISFEE,DATEDIFF([day],B.ETD,B.SETTLETIME) ACTUALDAY,DATEDIFF([day],B.STLDATE,B.SETTLETIME) NODAY" ) ;
strSql . Append ( ",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF " ) ;
strSql . Append ( " FROM v_op_bill_gain_cxtc B " ) ;
strSql . Append ( "LEFT JOIN op_sale_tc f ON (f.BSNO=B.BSNO) where B.TTLPROFIT<=0 " ) ;
strSql . Append ( " AND B.ACCDATE='" + Month + "' " ) ;
if ( ! string . IsNullOrEmpty ( strConditionAll ) )
{
strSql . Append ( " and " + strConditionAll ) ;
}
strSql . Append ( " ) AS V " ) ;
/ /
var sortstring = DatasetSort . Getsortstring ( sort ) ;
if ( ! string . IsNullOrEmpty ( sortstring ) )
{
strSql . Append ( " order by " + sortstring ) ;
}
else
{
strSql . Append ( " order by SALE,BSSOURCE,(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");
}
strSql . Append ( " SELECT * FROM ##SALEPROFITSHARE" + usercode + " " ) ;
return SetCXData ( strCondition , strSql , Month , expDate_Min , expDate_Max , usercode ) ;
}
static public string GetCXDataListStr ( string strCondition , string Month , string expDate_Min , string expDate_Max , 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 ) ;
if ( ! string . IsNullOrEmpty ( expDate_Min ) ) CurDateBegin = Convert . ToDateTime ( expDate_Min ) ;
if ( ! string . IsNullOrEmpty ( expDate_Max ) ) CurDateEnd = Convert . ToDateTime ( expDate_Max ) ;
var rangstr = GetRangDAStr ( "index" , userid , usercode , companyid ) ;
var strConditionAll = strCondition ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strConditionAll = strCondition + " and " + rangstr ;
}
else
{
strConditionAll = rangstr ;
}
}
var strSql = new StringBuilder ( ) ;
strSql . Append ( " if object_id('tempdb..##SALEPROFITSHARE" + usercode + "') is not null Begin DROP TABLE ##SALEPROFITSHARE" + usercode + " End " ) ;
strSql . Append ( "SELECT * into ##SALEPROFITSHARE" + usercode + " 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.FEESTATUSREF,B.BLFRT,B.STLNAME" ) ;
strSql . Append ( ",B.STLDATE " ) ;
strSql . Append ( ",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.CNTRTOTAL,B.CORPID" ) ;
strSql . Append ( ",B.FEESTATUS" ) ;
strSql . Append ( ",B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR" ) ;
strSql . Append ( ",B.TTLPROFIT,B.TTLNODR,B.TTLNOCR " ) ;
strSql . Append ( ",B.SETTLETIME,f.ISFEE,DATEDIFF([day],B.ETD,B.SETTLETIME) ACTUALDAY,DATEDIFF([day],B.STLDATE,B.SETTLETIME) NODAY" ) ;
strSql . Append ( ",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF " ) ;
strSql . Append ( " FROM v_op_bill_gain_cxtc B " ) ;
strSql . Append ( "LEFT JOIN op_sale_tc f ON (f.BSNO=B.BSNO) where B.NODAILIBALDR=0 AND B.TTLDR<>0 AND B.TTLPROFIT>=0 " ) ;
strSql . Append ( "AND ((B.SETTLETIME>='" + CurDateBegin . ToString ( "yyyy-MM-dd" ) + "' AND B.SETTLETIME<='" + CurDateEnd . ToString ( "yyyy-MM-dd 23:59:59" ) + "' " ) ;
strSql . Append ( " AND B.ACCDATE<='" + Month + "') OR " ) ;
strSql . Append ( " ( B.ACCDATE='" + CurDateBegin . ToString ( "yyyy-MM" ) + "' AND B.SETTLETIME<'" + CurDateBegin . ToString ( "yyyy-MM-dd" ) + "') ) " ) ;
if ( ! string . IsNullOrEmpty ( strConditionAll ) )
{
strSql . Append ( " and " + strConditionAll ) ;
}
//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(",B.STLDATE ");
//strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
//strSql.Append(",B.FEESTATUS");
//strSql.Append(",B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR");
//strSql.Append(",B.TTLPROFIT,B.TTLNODR,B.TTLNOCR ");
//strSql.Append(",B.SETTLETIME,f.ISFEE,DATEDIFF([day],B.ETD,B.SETTLETIME) ACTUALDAY,DATEDIFF([day],B.STLDATE,B.SETTLETIME) NODAY");
//strSql.Append(",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF ");
//strSql.Append(" FROM v_op_bill_gain_cxtc 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 AND B.TTLPROFIT>=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") + "') ");
//if (!string.IsNullOrEmpty(strConditionAll))
//{
// strSql.Append(" and " + strConditionAll);
//}
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.FEESTATUSREF,B.BLFRT,B.STLNAME" ) ;
strSql . Append ( ",B.STLDATE " ) ;
strSql . Append ( ",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.CNTRTOTAL,B.CORPID" ) ;
strSql . Append ( ",B.FEESTATUS" ) ;
strSql . Append ( ",B.TTLDR,B.TTLCR,B.STLTTLDR,B.STLTTLCR" ) ;
strSql . Append ( ",B.TTLPROFIT,B.TTLNODR,B.TTLNOCR " ) ;
strSql . Append ( ",B.SETTLETIME,f.ISFEE,DATEDIFF([day],B.ETD,B.SETTLETIME) ACTUALDAY,DATEDIFF([day],B.STLDATE,B.SETTLETIME) NODAY" ) ;
strSql . Append ( ",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF " ) ;
strSql . Append ( " FROM v_op_bill_gain_cxtc B " ) ;
strSql . Append ( "LEFT JOIN op_sale_tc f ON (f.BSNO=B.BSNO) where B.TTLPROFIT<=0 " ) ;
strSql . Append ( " AND B.ACCDATE='" + Month + "' " ) ;
if ( ! string . IsNullOrEmpty ( strConditionAll ) )
{
strSql . Append ( " and " + strConditionAll ) ;
}
strSql . Append ( " ) AS V " ) ;
/ /
var sortstring = DatasetSort . Getsortstring ( sort ) ;
if ( ! string . IsNullOrEmpty ( sortstring ) )
{
strSql . Append ( " order by " + sortstring ) ;
}
else
{
strSql . Append ( " order by SALE,BSSOURCE,(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");
}
strSql . Append ( " SELECT * FROM ##SALEPROFITSHARE" + usercode + " " ) ;
return strSql . ToString ( ) ;
}
static public List < MsSaleMonthProfit > GetCXSaleMonthDataList ( string strCondition , string Month , DateTime CurDateBegin , DateTime CurDateEnd , string userid )
{
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,SUM(ZKTTLPROFIT) ZKTTLPROFIT,SUM(THTTLPROFIT) THTTLPROFIT FROM (SELECT B.SALE,B.ACCDATE ETDMONTH,BSSOURCE,B.TTLPROFIT" ) ;
strSql . Append ( ",(CASE WHEN BSSOURCE='直客' THEN TTLPROFIT ELSE 0 END) ZKTTLPROFIT,(CASE WHEN BSSOURCE='直客' THEN 0 ELSE TTLPROFIT END) THTTLPROFIT " ) ;
strSql . Append ( " FROM v_op_bill_gain_cxtc B " ) ;
strSql . Append ( "where " ) ;
strSql . Append ( " B.NODAILIBALDR=0 AND B.TTLDR<>0 AND B.TTLPROFIT>=0 " ) ;
strSql . Append ( "AND B.SETTLETIME<'" + CurDateBegin . ToString ( "yyyy-MM-dd" ) + "' AND B.ACCDATE<'" + Month + "' " ) ;
strSql . Append ( " AND B.ACCDATE IN (SELECT DISTINCT ACCDATE FROM ##SALEPROFITSHARE" + userid + ") " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " and " + strCondition ) ;
}
//strSql.Append(" union ALL SELECT B.SALE,B.ACCDATE ETDMONTH,BSSOURCE,B.TTLPROFIT");
//strSql.Append(",(CASE WHEN BSSOURCE='直客' THEN TTLPROFIT ELSE 0 END) ZKTTLPROFIT,(CASE WHEN BSSOURCE='直客' THEN 0 ELSE TTLPROFIT END) THTTLPROFIT ");
//strSql.Append(" FROM v_op_bill_gain_tc 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 AND B.TTLPROFIT>=0 ");
//strSql.Append(" AND T.SETTLETIME<='" + LastDateEnd.ToString("yyyy-MM-dd 23:59:59") + "' ");
//strSql.Append(" AND B.ACCDATE IN (SELECT DISTINCT ACCDATE FROM ##SALEPROFITSHARE) ");
//if (!string.IsNullOrEmpty(strCondition))
//{
// strSql.Append(" and " + strCondition);
//}
strSql . Append ( " union ALL SELECT B.SALE,B.ACCDATE ETDMONTH,BSSOURCE,B.TTLPROFIT" ) ;
strSql . Append ( ",(CASE WHEN BSSOURCE='直客' THEN TTLPROFIT ELSE 0 END) ZKTTLPROFIT,(CASE WHEN BSSOURCE='直客' THEN 0 ELSE TTLPROFIT END) THTTLPROFIT " ) ;
strSql . Append ( " FROM v_op_bill_gain_cxtc B " ) ;
strSql . Append ( "where B.TTLPROFIT<=0 AND B.ACCDATE<'" + Month + "'" ) ;
strSql . Append ( " AND B.ACCDATE IN (SELECT DISTINCT ACCDATE FROM ##SALEPROFITSHARE" + userid + ") " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " and " + strCondition ) ;
}
strSql . Append ( " ) AS V GROUP BY SALE,ETDMONTH " ) ;
return SetCXSaleMonthData ( strSql ) ;
}
static public List < MsSaleMonthProfit > GetCXSaleMonthTTLDataList ( string strCondition , DateTime CurDateBegin , DateTime CurDateEnd , string userid )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT SALE,ETDMONTH,SUM(TTLPROFIT) TTLPROFIT,SUM(ZKTTLPROFIT) ZKTTLPROFIT,SUM(THTTLPROFIT) THTTLPROFIT FROM (SELECT B.SALE,B.ACCDATE ETDMONTH,B.BSSOURCE,B.TTLPROFIT TTLPROFIT" ) ;
strSql . Append ( ",(CASE WHEN BSSOURCE='直客' THEN TTLPROFIT ELSE 0 END) ZKTTLPROFIT,(CASE WHEN BSSOURCE='直客' THEN 0 ELSE TTLPROFIT END) THTTLPROFIT " ) ;
strSql . Append ( " FROM v_op_bill_gain_cxtc B " ) ;
strSql . Append ( " where 1=1 " ) ;
strSql . Append ( " AND B.ACCDATE IN (SELECT DISTINCT ACCDATE FROM ##SALEPROFITSHARE" + userid + ") " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " and " + strCondition ) ;
}
strSql . Append ( " ) AS V GROUP BY SALE,ETDMONTH " ) ;
return SetCXSaleMonthData ( strSql ) ;
}
private static List < MsOpBillProfit > SetCXData ( string strCondition , StringBuilder strSql , string Month , string expDate_Min , string expDate_Max , string userid )
{
DateTime CurDateBegin = Convert . ToDateTime ( Month + "-01" ) ;
DateTime CurDateEnd = CurDateBegin . AddMonths ( 1 ) . AddDays ( - 1 ) ;
if ( ! string . IsNullOrEmpty ( expDate_Min ) ) CurDateBegin = Convert . ToDateTime ( expDate_Min ) ;
var saleprofitlist = MsInfoSaleProfitShareSetDAL . GetSaleProfitDetailDataList ( "" ) ;
var saleprofitcqlist = MsInfoSaleProfitShareSetDAL . GetSaleProfitCqDataList ( "" ) ;
var POORDAY = 0 ;
var MONTHPOORDAY = 0 ;
SqlCommand cmd = new SqlCommand ( ) ;
cmd . CommandText = strSql . ToString ( ) ;
cmd . CommandTimeout = 1200000 ; //要加这一句
decimal BaseComp = 0 ;
var sale = "" ;
var headList = new List < MsOpBillProfit > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( cmd ) )
{
var MsSaleMonthProfitList = GetCXSaleMonthDataList ( strCondition , Month , CurDateBegin , CurDateEnd , userid ) ;
var MsSaleMonthTTLProfitList = GetCXSaleMonthTTLDataList ( strCondition , CurDateBegin , CurDateEnd , userid ) ;
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 . 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 . 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 . CORPID = Convert . ToString ( reader [ "CORPID" ] ) ;
data . STLNAME = Convert . ToString ( reader [ "STLNAME" ] ) ;
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 ;
if ( data . BSSOURCE = = "直客" )
{
i . ZKTTLPROFIT = i . ZKTTLPROFIT + data . TTLPROFIT ;
data . ZKTTLPROFIT = i . ZKTTLPROFIT ;
data . THTTLPROFIT = i . THTTLPROFIT ;
}
else
{
i . THTTLPROFIT = i . THTTLPROFIT + data . TTLPROFIT ;
data . THTTLPROFIT = i . THTTLPROFIT ;
data . ZKTTLPROFIT = i . ZKTTLPROFIT ;
}
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 ;
if ( data . BSSOURCE = = "直客" )
{
salemonthprofit . ZKTTLPROFIT = salemonthprofit . ZKTTLPROFIT + data . TTLPROFIT ;
data . ZKTTLPROFIT = salemonthprofit . ZKTTLPROFIT ;
}
else
{
salemonthprofit . THTTLPROFIT = salemonthprofit . THTTLPROFIT + data . TTLPROFIT ;
data . THTTLPROFIT = salemonthprofit . THTTLPROFIT ;
}
MsSaleMonthProfitList . Add ( salemonthprofit ) ;
}
decimal beginplan = 0 ;
decimal endplan = 0 ;
decimal SHAREPR = 0 ;
if ( data . TTLPROFIT < = 0 )
{
data . NODAY = 0 ;
}
data . TiChengQuJian = 100 ;
var isnottc = false ;
if ( BaseComp = = 0 | | sale ! = data . SALE )
saleprofitlist . ForEach ( i = >
{
if ( i . SALE = = data . SALE & & i . BSSOURCE = = "" )
{
data . TiChengBiLi = 0 ;
if ( i . PROFITUP > BaseComp )
BaseComp = i . PROFITUP ;
sale = data . SALE ;
if ( data . COMPR > i . PROFITDOWN & & data . COMPR < = i . PROFITUP )
{
isnottc = true ;
}
}
} ) ;
var TTLCOMPR = data . ZKTTLPROFIT ;
if ( data . BSSOURCE ! = "直客" )
{
TTLCOMPR = data . THTTLPROFIT ;
}
else
{
if ( data . THTTLPROFIT < BaseComp )
{
TTLCOMPR = TTLCOMPR - BaseComp + data . THTTLPROFIT ;
}
}
if ( ! isnottc & & data . COMPR > BaseComp )
{
saleprofitlist . ForEach ( i = >
{
if ( i . SALE = = data . SALE & & i . BSSOURCE = = data . BSSOURCE & & ( ( TTLCOMPR - data . TTLPROFIT ) > i . PROFITDOWN | | TTLCOMPR > i . PROFITDOWN ) & & ( ( data . MONTHTTLPR > = i . PROFITPLAN & & i . PROFITPLAN > 0 ) | | ( i . PROFITPLAN < = 0 ) ) )
{
if ( ( ( TTLCOMPR - data . TTLPROFIT ) < = i . PROFITUP | | TTLCOMPR < = i . PROFITUP ) )
{
POORDAY = i . POORDAY ;
MONTHPOORDAY = i . MONTHPOORDAY ;
if ( data . NODAY < = 0 )
{
data . TiChengQuJian = 100 ;
}
else
{
saleprofitcqlist . ForEach ( j = >
{
if ( j . SALE = = data . SALE & & data . NODAY > = j . BDAY & & data . NODAY < = j . EDAY )
{
data . TiChengQuJian = j . DEDUCTIN ;
}
} ) ;
}
data . TiChengBiLi = i . SHAREPR * data . TiChengQuJian / 100 ;
data . ShiJiTiChengBiLi = i . SHAREPR / 100 ;
SHAREPR = i . SHAREPR ;
beginplan = i . PROFITDOWN ;
endplan = i . PROFITUP ;
if ( TTLCOMPR < = i . PROFITUP )
{
var TMPTTLPROFIT = data . TTLPROFIT ;
if ( ( TTLCOMPR - data . TTLPROFIT ) < = i . PROFITDOWN ) TMPTTLPROFIT = ( TTLCOMPR - i . PROFITDOWN ) ;
if ( ( data . COMPR - data . TTLPROFIT ) < BaseComp ) TMPTTLPROFIT = data . COMPR - BaseComp ;
data . TiCheng = data . TiCheng + TMPTTLPROFIT * data . TiChengBiLi / 100 ;
data . KouXi = data . KouXi + ( TMPTTLPROFIT * i . SHAREPR / 100 - TMPTTLPROFIT * data . TiChengBiLi / 100 ) ;
if ( ! string . IsNullOrEmpty ( data . TiChengBiLiStr ) )
data . TiChengBiLiStr = data . TiChengBiLiStr + "+" + Convert . ToString ( data . TiChengQuJian / 100 ) + "*(" + TMPTTLPROFIT . ToString ( ) + "*" + Convert . ToString ( SHAREPR / 100 ) + ")" ;
else
data . TiChengBiLiStr = Convert . ToString ( data . TiChengQuJian / 100 ) + "*(" + TMPTTLPROFIT . ToString ( ) + "*" + Convert . ToString ( SHAREPR / 100 ) + ")" ;
}
else
{
var TMPTTLPROFIT = data . TTLPROFIT - ( TTLCOMPR - i . PROFITUP ) ;
if ( ( data . COMPR - data . TTLPROFIT ) < BaseComp ) TMPTTLPROFIT = data . COMPR - BaseComp ;
data . TiCheng = data . TiCheng + TMPTTLPROFIT * data . TiChengBiLi / 100 ;
data . KouXi = data . KouXi + ( TMPTTLPROFIT * i . SHAREPR / 100 - TMPTTLPROFIT * data . TiChengBiLi / 100 ) ;
if ( ! string . IsNullOrEmpty ( data . TiChengBiLiStr ) )
data . TiChengBiLiStr = data . TiChengBiLiStr + "+" + Convert . ToString ( data . TiChengQuJian / 100 ) + "*(" + TMPTTLPROFIT . ToString ( ) + "*" + Convert . ToString ( SHAREPR / 100 ) + ")" ;
else
data . TiChengBiLiStr = Convert . ToString ( data . TiChengQuJian / 100 ) + "*(" + TMPTTLPROFIT . ToString ( ) + "*" + Convert . ToString ( SHAREPR / 100 ) + ")" ;
}
}
}
} ) ;
// var salemonthprofit = new MsSaleMonthProfit();
// salemonthprofit.SALE = data.SALE;
// salemonthprofit.ETDMONTH = data.ETDMONTH;
// salemonthprofit.TTLPROFIT = data.TTLPROFIT;
// data.COMPR = data.TTLPROFIT;
// if (data.BSSOURCE == "直客")
// {
// salemonthprofit.ZKTTLPROFIT = salemonthprofit.ZKTTLPROFIT + data.TTLPROFIT;
// data.ZKTTLPROFIT = salemonthprofit.ZKTTLPROFIT;
// }
// else
// {
// salemonthprofit.THTTLPROFIT = salemonthprofit.THTTLPROFIT + data.TTLPROFIT;
// data.THTTLPROFIT = salemonthprofit.THTTLPROFIT;
// }
// MsSaleMonthProfitList.Add(salemonthprofit);
//}
//decimal beginplan = 0;
//decimal endplan = 0;
//decimal SHAREPR = 0;
//if (data.TTLPROFIT <= 0)
//{
// data.NODAY = 0;
//}
//data.TiChengQuJian = 100;
//var isnottc = false;
//if (BaseComp==0||sale!=data.SALE)
//saleprofitlist.ForEach(i =>
//{
// if (i.SALE == data.SALE && i.BSSOURCE =="")
// {
// data.TiChengBiLi =0;
// if (i.PROFITUP> BaseComp)
// BaseComp = i.PROFITUP;
// sale = data.SALE;
// if (data.COMPR > i.PROFITDOWN && data.COMPR <= i.PROFITUP) {
// isnottc = true;
// }
// }
//});
//var TTLCOMPR = data.ZKTTLPROFIT;
//if (data.BSSOURCE != "直客")
//{
// TTLCOMPR = data.THTTLPROFIT;
//}
//else {
// if (data.THTTLPROFIT < BaseComp) {
// TTLCOMPR = TTLCOMPR - BaseComp +data.THTTLPROFIT;
// }
//}
//var mblno = data.MBLNO;
//if (mblno == "QDSR061873") {
// mblno = "111";
//}
//if (!isnottc&&data.COMPR>BaseComp)
//{
// saleprofitlist.ForEach(i =>
// {
// if (i.SALE == data.SALE && i.BSSOURCE == data.BSSOURCE && ((TTLCOMPR-data.TTLPROFIT)> i.PROFITDOWN ||TTLCOMPR>i.PROFITDOWN) && ((data.MONTHTTLPR >= i.PROFITPLAN && i.PROFITPLAN > 0) || (i.PROFITPLAN <= 0)))
// {
// if (((TTLCOMPR - data.TTLPROFIT) <= i.PROFITUP || TTLCOMPR <= i.PROFITUP))
// {
// POORDAY = i.POORDAY;
// MONTHPOORDAY = i.MONTHPOORDAY;
// if (data.NODAY <= 0)
// {
// data.TiChengQuJian = 100;
// }
// else
// {
// saleprofitcqlist.ForEach(j =>
// {
// if (j.SALE == data.SALE && data.NODAY >= j.BDAY && data.NODAY <= j.EDAY)
// {
// data.TiChengQuJian = j.DEDUCTIN;
// }
// });
// }
// data.TiChengBiLi = i.SHAREPR * data.TiChengQuJian / 100;
// data.ShiJiTiChengBiLi= i.SHAREPR / 100;
// SHAREPR = i.SHAREPR;
// beginplan = i.PROFITDOWN;
// endplan = i.PROFITUP;
// if (TTLCOMPR <= i.PROFITUP)
// {
// var TMPTTLPROFIT = data.TTLPROFIT;
// decimal basecompr = TTLCOMPR;
// if ((data.COMPR - data.TTLPROFIT) < BaseComp) basecompr = data.COMPR - BaseComp;
// if ((TTLCOMPR - data.TTLPROFIT) <= i.PROFITDOWN) TMPTTLPROFIT = (data.COMPR - i.PROFITDOWN);
// data.TiCheng = data.TiCheng + TMPTTLPROFIT * data.TiChengBiLi / 100;
// data.KouXi=data.KouXi+ (TMPTTLPROFIT * i.SHAREPR / 100- TMPTTLPROFIT * data.TiChengBiLi / 100);
// if (!string.IsNullOrEmpty(data.TiChengBiLiStr))
// data.TiChengBiLiStr = data.TiChengBiLiStr+"+"+ Convert.ToString(data.TiChengQuJian / 100) + "*(" + TMPTTLPROFIT.ToString() + "*" + Convert.ToString(SHAREPR / 100) + ")";
// else
// data.TiChengBiLiStr = Convert.ToString(data.TiChengQuJian / 100) + "*(" + TMPTTLPROFIT.ToString() + "*" + Convert.ToString(SHAREPR / 100) + ")";
// }
// else {
// decimal basecompr = TTLCOMPR;
// if ((data.COMPR - data.TTLPROFIT) < BaseComp) basecompr = data.COMPR - BaseComp;
// var TMPTTLPROFIT = data.TTLPROFIT - (basecompr - i.PROFITUP);
// if ((TTLCOMPR - data.TTLPROFIT) < i.PROFITDOWN && (TMPTTLPROFIT > (i.PROFITUP - i.PROFITDOWN))) TMPTTLPROFIT = i.PROFITUP - i.PROFITDOWN;
// //if ((data.COMPR - data.TTLPROFIT) < BaseComp) TMPTTLPROFIT = data.COMPR - BaseComp;
// data.TiCheng = data.TiCheng + TMPTTLPROFIT * data.TiChengBiLi/100;
// data.KouXi = data.KouXi + (TMPTTLPROFIT * i.SHAREPR / 100 - TMPTTLPROFIT * data.TiChengBiLi / 100);
// if (!string.IsNullOrEmpty(data.TiChengBiLiStr))
// data.TiChengBiLiStr = data.TiChengBiLiStr + "+" + Convert.ToString(data.TiChengQuJian / 100) + "*(" + TMPTTLPROFIT.ToString() + "*" + Convert.ToString(SHAREPR / 100) + ")";
// else
// data.TiChengBiLiStr = Convert.ToString(data.TiChengQuJian / 100) + "*(" + TMPTTLPROFIT.ToString() + "*" + Convert.ToString(SHAREPR / 100) + ")";
// }
// }
// }
// });
}
if ( reader [ "SETTLETIME" ] ! = DBNull . Value )
data . SETTLETIME = Convert . ToDateTime ( reader [ "SETTLETIME" ] ) . ToString ( "yyyy-MM-dd" ) ;
data . ISSALEFEE = Convert . ToString ( reader [ "ISFEEREF" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
private static List < MsSaleMonthProfit > SetCXSaleMonthData ( 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" ] ) ;
if ( reader [ "ZKTTLPROFIT" ] ! = DBNull . Value )
data . ZKTTLPROFIT = Convert . ToDecimal ( reader [ "ZKTTLPROFIT" ] ) ;
if ( reader [ "THTTLPROFIT" ] ! = DBNull . Value )
data . THTTLPROFIT = Convert . ToDecimal ( reader [ "THTTLPROFIT" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
# endregion
#region 展鸿
static public List < MsOpBillProfit > GetZHDataList ( string strCondition , string isalldr , string isonlystl , string userid , string usercode , string companyid , string sort = null )
{
var rangstr = GetRangDAStr ( "index" , userid , usercode , companyid ) ;
var strConditionAll = strCondition ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strConditionAll = strCondition + " and " + rangstr ;
}
else
{
strConditionAll = rangstr ;
}
}
var strSql = new StringBuilder ( ) ;
strSql . Append ( " if object_id('tempdb..##SALEPROFITSHARE') is not null Begin DROP TABLE ##SALEPROFITSHARE End " ) ;
strSql . Append ( "SELECT * into ##SALEPROFITSHARE 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 ( ",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.TAXPROFIT,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,CASE WHEN B.TTLDR<0 THEN 0 ELSE DATEDIFF([day],B.STLDATE,ISNULL(T.SETTLETIME,GETDATE())) END NODAY" ) ;
strSql . Append ( ",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,CASE WHEN (B.TTLDR-B.STLTTLDR)<0 THEN 0 ELSE (dbo.GetZHZYTTL(B.STLDATE,B.BSNO)+TTLNODR*ZYRATE*DATEDIFF([day],B.STLDATE,GETDATE())) END ZYTTL " ) ;
strSql . Append ( " FROM v_op_bill_gain_zh 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<>0 " ) ;
if ( isonlystl = = "1" )
strSql . Append ( " AND B.TTLDR=B.STLTTLDR " ) ;
if ( ! string . IsNullOrEmpty ( strConditionAll ) )
{
strSql . Append ( " and " + strConditionAll ) ;
}
if ( isalldr = = "1" )
{
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 ( ",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.TAXPROFIT,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,isnull(T.SETTLETIME,GETDATE())) ACTUALDAY,0 NODAY" ) ;
strSql . Append ( ",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,0 ZYTTL " ) ;
strSql . Append ( " FROM v_op_bill_gain_zh 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.TTLDR=0 " ) ;
if ( isonlystl = = "1" )
strSql . Append ( " AND B.TTLCR=B.STLTTLCR " ) ;
if ( ! string . IsNullOrEmpty ( strConditionAll ) )
{
strSql . Append ( " and " + strConditionAll ) ;
}
}
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");
}
strSql . Append ( " SELECT * FROM ##SALEPROFITSHARE " ) ;
return SetZHData ( strCondition , strSql ) ;
}
static public List < MsSaleMonthProfit > GetZHSaleMonthTTLDataList ( string strCondition )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT SALE,ETDMONTH,SUM(TTLPROFIT) TTLPROFIT FROM (SELECT B.SALE,B.ACCDATE ETDMONTH,B.TTLPROFIT TTLPROFIT" ) ;
strSql . Append ( " FROM v_op_bill_gain_zh B " ) ;
strSql . Append ( " where 1=1 " ) ;
strSql . Append ( " AND B.ACCDATE IN (SELECT DISTINCT ACCDATE FROM ##SALEPROFITSHARE) " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " and " + strCondition ) ;
}
strSql . Append ( " ) AS V GROUP BY SALE,ETDMONTH " ) ;
//strSql.Append(" drop table ##SALEPROFITSHARE ");
return SetZHSaleMonthData ( strSql ) ;
}
private static List < MsOpBillProfit > SetZHData ( string strCondition , StringBuilder strSql )
{
//DateTime CurDateBegin = Convert.ToDateTime(Month + "-01");
//DateTime CurDateEnd = CurDateBegin.AddMonths(1).AddDays(-1);
var saleprofitlist = MsInfoSaleProfitShareSetDAL . GetSaleProfitDetailDataList ( "" ) ;
var saleprofitcqlist = MsInfoSaleProfitShareSetDAL . GetSaleProfitCqDataList ( "" ) ;
var tmpsaleprofitlist = saleprofitlist ;
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 ) )
{
//var MsSaleMonthProfitList = GetZHSaleMonthDataList(strCondition);
var MsSaleMonthTTLProfitList = GetZHSaleMonthTTLDataList ( strCondition ) ;
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" ] ) ;
data . STLDATE = Convert . ToString ( reader [ "STLDATE" ] ) ;
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 [ "ZYTTL" ] ! = DBNull . Value )
data . ZYTTL = Convert . ToDecimal ( reader [ "ZYTTL" ] ) ;
if ( reader [ "TAXPROFIT" ] ! = DBNull . Value )
data . TAXPROFIT = Convert . ToDecimal ( reader [ "TAXPROFIT" ] ) ;
if ( data . TTLPROFIT < 0 )
{
data . ACTUALDAY = 0 ;
}
MsSaleMonthTTLProfitList . ForEach ( i = >
{
if ( i . SALE = = data . SALE & & i . ETDMONTH = = data . ETDMONTH )
{
i . MONTHPROFIT = i . MONTHPROFIT + data . TTLPROFIT ;
data . MONTHTTLPR = i . MONTHPROFIT ;
}
} ) ;
//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;
//}
foreach ( var i in saleprofitlist )
{
if ( i . SALE = = data . SALE & & ( ( ( data . MONTHTTLPR - data . TTLPROFIT ) > i . PROFITDOWN ) | | ( data . MONTHTTLPR > i . PROFITDOWN ) ) & & i . SHAREPR ! = 0 )
{
if ( ( ( data . MONTHTTLPR - data . TTLPROFIT ) < = i . PROFITUP | | ( data . MONTHTTLPR ) < = i . PROFITUP ) )
{
data . TiChengBiLi = i . SHAREPR / 100 ;
if ( data . MONTHTTLPR < = i . PROFITUP )
{
SHAREPR = i . SHAREPR ;
beginplan = i . PROFITDOWN ;
endplan = i . PROFITUP ;
var TTLPROFIT = data . TTLPROFIT ;
if ( ( data . MONTHTTLPR - data . TTLPROFIT ) < = i . PROFITDOWN ) TTLPROFIT = ( data . MONTHTTLPR - i . PROFITDOWN ) ;
data . TiCheng = data . TiCheng + TTLPROFIT * data . TiChengBiLi ;
}
else
{
var TTLPROFIT = data . TTLPROFIT - ( data . MONTHTTLPR - i . PROFITUP ) ;
data . TiCheng = data . TiCheng + TTLPROFIT * data . TiChengBiLi ;
}
if ( data . MONTHTTLPR > 50000 )
{
data . TiCheng = data . TiCheng ;
}
}
}
}
// saleprofitlist.ForEach(i =>
//{
//});
data . COMPR = data . TiCheng - data . TAXPROFIT - data . ZYTTL ;
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" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
private static List < MsSaleMonthProfit > SetZHSaleMonthData ( 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
#region 好品佳和
static public List < MsOpBillProfit > GetHPJHDataList ( string strCondition , string isalldr , string isonlystl , string userid , string usercode , string companyid , string sort = null )
{
var rangstr = GetRangDAStr ( "index" , userid , usercode , companyid ) ;
var strConditionAll = strCondition ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strConditionAll = strCondition + " and " + rangstr ;
}
else
{
strConditionAll = rangstr ;
}
}
var strSql = new StringBuilder ( ) ;
strSql . Append ( " if object_id('tempdb..##SALEPROFITSHARE') is not null Begin DROP TABLE ##SALEPROFITSHARE End " ) ;
strSql . Append ( "SELECT * into ##SALEPROFITSHARE 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 ( ",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.TAXPROFIT,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,CASE WHEN B.TTLDR<0 THEN 0 ELSE DATEDIFF([day],B.STLDATE,ISNULL(T.SETTLETIME,GETDATE())) END NODAY" ) ;
strSql . Append ( ",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,B.KXRATE " ) ;
strSql . Append ( " FROM v_op_bill_gain_hpjh 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<>0 " ) ;
if ( isonlystl = = "1" )
strSql . Append ( " AND B.TTLDR=B.STLTTLDR " ) ;
if ( ! string . IsNullOrEmpty ( strConditionAll ) )
{
strSql . Append ( " and " + strConditionAll ) ;
}
if ( isalldr = = "1" )
{
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 ( ",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.TAXPROFIT,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,isnull(T.SETTLETIME,GETDATE())) ACTUALDAY,0 NODAY" ) ;
strSql . Append ( ",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,B.KXRATE " ) ;
strSql . Append ( " FROM v_op_bill_gain_hpjh 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.TTLDR=0 " ) ;
if ( isonlystl = = "1" )
strSql . Append ( " AND B.TTLCR=B.STLTTLCR " ) ;
if ( ! string . IsNullOrEmpty ( strConditionAll ) )
{
strSql . Append ( " and " + strConditionAll ) ;
}
}
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");
}
strSql . Append ( " SELECT * FROM ##SALEPROFITSHARE " ) ;
return SetHPJHData ( strCondition , strSql ) ;
}
static public List < MsSaleMonthProfit > GetHPJHSaleMonthTTLDataList ( string strCondition )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT SALE,ETDMONTH,SUM(TTLPROFIT) TTLPROFIT FROM (SELECT B.SALE,B.ACCDATE ETDMONTH,B.TTLPROFIT TTLPROFIT" ) ;
strSql . Append ( " FROM v_op_bill_gain_hpjh B " ) ;
strSql . Append ( " where 1=1 " ) ;
strSql . Append ( " AND B.ACCDATE IN (SELECT DISTINCT ACCDATE FROM ##SALEPROFITSHARE) " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " and " + strCondition ) ;
}
strSql . Append ( " ) AS V GROUP BY SALE,ETDMONTH " ) ;
//strSql.Append(" drop table ##SALEPROFITSHARE ");
return SetHPJHSaleMonthData ( strSql ) ;
}
private static List < MsOpBillProfit > SetHPJHData ( string strCondition , StringBuilder strSql )
{
//DateTime CurDateBegin = Convert.ToDateTime(Month + "-01");
//DateTime CurDateEnd = CurDateBegin.AddMonths(1).AddDays(-1);
var saleprofitlist = MsInfoSaleProfitShareSetDAL . GetSaleProfitDetailDataList ( "" ) ;
var saleprofitcqlist = MsInfoSaleProfitShareSetDAL . GetSaleProfitCqDataList ( "" ) ;
var tmpsaleprofitlist = saleprofitlist ;
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 ) )
{
//var MsSaleMonthProfitList = GetZHSaleMonthDataList(strCondition);
var MsSaleMonthTTLProfitList = GetZHSaleMonthTTLDataList ( strCondition ) ;
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" ] ) ;
data . STLDATE = Convert . ToString ( reader [ "STLDATE" ] ) ;
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" ] ) ;
decimal KXRATE = 0 ;
if ( reader [ "KXRATE" ] ! = DBNull . Value )
KXRATE = Convert . ToDecimal ( reader [ "KXRATE" ] ) ;
if ( data . TTLPROFIT < 0 )
{
data . ACTUALDAY = 0 ;
}
MsSaleMonthTTLProfitList . ForEach ( i = >
{
if ( i . SALE = = data . SALE & & i . ETDMONTH = = data . ETDMONTH )
{
i . MONTHPROFIT = i . MONTHPROFIT + data . TTLPROFIT ;
data . MONTHTTLPR = i . MONTHPROFIT ;
}
} ) ;
//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;
//}
foreach ( var i in saleprofitlist )
{
if ( i . SALE = = data . SALE & & ( ( ( data . MONTHTTLPR - data . TTLPROFIT ) > i . PROFITDOWN ) | | ( data . MONTHTTLPR > i . PROFITDOWN ) ) & & i . SHAREPR ! = 0 )
{
if ( ( ( data . MONTHTTLPR - data . TTLPROFIT ) < = i . PROFITUP | | ( data . MONTHTTLPR ) < = i . PROFITUP ) )
{
data . TiChengBiLi = i . SHAREPR / 100 ;
if ( data . MONTHTTLPR < = i . PROFITUP )
{
SHAREPR = i . SHAREPR ;
beginplan = i . PROFITDOWN ;
endplan = i . PROFITUP ;
var TTLPROFIT = data . TTLPROFIT ;
if ( ( data . MONTHTTLPR - data . TTLPROFIT ) < = i . PROFITDOWN ) TTLPROFIT = ( data . MONTHTTLPR - i . PROFITDOWN ) ;
data . TiCheng = data . TiCheng + TTLPROFIT * data . TiChengBiLi ;
}
else
{
var TTLPROFIT = data . TTLPROFIT - ( data . MONTHTTLPR - i . PROFITUP ) ;
data . TiCheng = data . TiCheng + TTLPROFIT * data . TiChengBiLi ;
}
}
}
}
// saleprofitlist.ForEach(i =>
//{
//});
if ( data . NODAY > 0 )
data . KouXi = data . TiCheng * KXRATE * data . NODAY ;
data . COMPR = data . TiCheng - data . KouXi ;
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" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
private static List < MsSaleMonthProfit > SetHPJHSaleMonthData ( 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
#region 泰邦 提成计算
static public List < MsOpBillProfit > GetTBDataList ( string strCondition , string TEU , string PROFITBOUNDS , string userid , string usercode , string companyid , string sort = null )
{
//var rangstr = GetRangDAStr("index", userid, usercode, companyid);
//var strConditionAll = strCondition;
//if (!string.IsNullOrEmpty(rangstr))
//{
// if (!string.IsNullOrEmpty(strCondition))
// {
// strConditionAll = strCondition + " and " + rangstr;
// }
// else
// {
// strConditionAll = rangstr;
// }
//}
//var strSql = new StringBuilder();
//strSql.Append(" if object_id('tempdb..##SALEPROFITSHARE') is not null Begin DROP TABLE ##SALEPROFITSHARE End ");
//strSql.Append("SELECT * into ##SALEPROFITSHARE 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(",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.TAXPROFIT,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");
////该客户的 Info_Client_ACCDATE.BGNDATE (生效日期) 减 每票货的开船日期得出是否超过一年以内
////一年以内则提成30% 一年之外为15%
////此处ACTUALDAY为ETD-帐期生效日期。大于1年则ACTUALDAY小于-365
//strSql.Append(",DATEDIFF([day],b.ETD,(select min(bgndate) from Info_Client_ACCDATE where LINKGID=(select gid from Info_Client where SHORTNAME=b.CUSTOMERNAME)))+1 ACTUALDAY");
//strSql.Append(",DATEDIFF([day],ISNULL(T.SETTLETIME,GETDATE()),(select min(bgndate) from Info_Client_ACCDATE where LINKGID=(select gid from Info_Client where SHORTNAME=b.CUSTOMERNAME))) NODAY");
//strSql.Append(",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,CASE WHEN (B.TTLDR-B.STLTTLDR)<0 THEN 0 ELSE (dbo.GetZHZYTTL(B.STLDATE,B.BSNO)+TTLNODR*ZYRATE*DATEDIFF([day],B.STLDATE,GETDATE())) END ZYTTL ");
//strSql.Append(" FROM v_op_bill_gain_zh 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<>0 ");
//strSql.Append(" AND B.TTLDR=B.STLTTLDR ");
//if (!string.IsNullOrEmpty(strConditionAll))
//{
// strSql.Append(" and " + strConditionAll);
//}
////if (isalldr == "1")
////{
// 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(",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.TAXPROFIT,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR ");
// strSql.Append(",T.SETTLETIME,f.ISFEE,0 MONTHSTLTTLDR");
// //该客户的 Info_Client_ACCDATE.BGNDATE (生效日期) 减 每票货的开船日期得出是否超过一年以内
// //一年以内则提成30% 一年之外为15%
// //此处NODAY为ETD-帐期生效日期。大于1年则noday小于-365
// strSql.Append(",DATEDIFF([day],b.ETD,(select min(bgndate) from Info_Client_ACCDATE where LINKGID=(select gid from Info_Client where SHORTNAME=b.CUSTOMERNAME)))+1 ACTUALDAY");
// strSql.Append(",DATEDIFF([day],ISNULL(T.SETTLETIME,GETDATE()),(select min(bgndate) from Info_Client_ACCDATE where LINKGID=(select gid from Info_Client where SHORTNAME=b.CUSTOMERNAME))) NODAY");
// strSql.Append(",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,0 ZYTTL ");
// strSql.Append(" FROM v_op_bill_gain_zh 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.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") + "') ");
// if (!string.IsNullOrEmpty(strConditionAll))
// {
// strSql.Append(" and " + strConditionAll);
// }
////}
//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");
//}
//strSql.Append(" SELECT * FROM ##SALEPROFITSHARE ");
var strSql = GetTBDataListStr ( strCondition , TEU , PROFITBOUNDS , userid , usercode , companyid , sort ) ;
return SetTBData ( strCondition , strSql , TEU , PROFITBOUNDS ) ;
}
static public StringBuilder GetTBDataListStr ( string strCondition , string TEU , string PROFITBOUNDS , string userid , string usercode , string companyid , string sort = null )
{
var rangstr = GetRangDAStr ( "index" , userid , usercode , companyid ) ;
var strConditionAll = strCondition ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strConditionAll = strCondition + " and " + rangstr ;
}
else
{
strConditionAll = rangstr ;
}
}
var strSql = new StringBuilder ( ) ;
strSql . Append ( " if object_id('tempdb..##SALEPROFITSHARE') is not null Begin DROP TABLE ##SALEPROFITSHARE End " ) ;
strSql . Append ( "SELECT * into ##SALEPROFITSHARE 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 ( ",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.TAXPROFIT,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" ) ;
//该客户的 Info_Client_ACCDATE.BGNDATE (生效日期) 减 每票货的开船日期得出是否超过一年以内
//一年以内则提成30% 一年之外为15%
//此处ACTUALDAY为ETD-帐期生效日期。大于1年则ACTUALDAY小于-365
strSql . Append ( ",DATEDIFF([day],b.ETD,(select min(bgndate) from Info_Client_ACCDATE where LINKGID=(select gid from Info_Client where SHORTNAME=b.CUSTOMERNAME)))+1 ACTUALDAY" ) ;
strSql . Append ( ",DATEDIFF([day],ISNULL(T.SETTLETIME,GETDATE()),(select min(bgndate) from Info_Client_ACCDATE where LINKGID=(select gid from Info_Client where SHORTNAME=b.CUSTOMERNAME))) NODAY" ) ;
strSql . Append ( ",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,CASE WHEN (B.TTLDR-B.STLTTLDR)<0 THEN 0 ELSE (dbo.GetZHZYTTL(B.STLDATE,B.BSNO)+TTLNODR*ZYRATE*DATEDIFF([day],B.STLDATE,GETDATE())) END ZYTTL " ) ;
strSql . Append ( " FROM v_op_bill_gain_zh 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<>0 " ) ;
strSql . Append ( " AND B.TTLDR=B.STLTTLDR " ) ;
if ( ! string . IsNullOrEmpty ( strConditionAll ) )
{
strSql . Append ( " and " + strConditionAll ) ;
}
//if (isalldr == "1")
//{
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 ( ",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.TAXPROFIT,B.RMBNODR,B.USDNODR,B.OTNODR,B.TTLNODR,B.RMBNOCR,B.USDNOCR,B.OTNOCR,B.TTLNOCR " ) ;
strSql . Append ( ",T.SETTLETIME,f.ISFEE,0 MONTHSTLTTLDR" ) ;
//该客户的 Info_Client_ACCDATE.BGNDATE (生效日期) 减 每票货的开船日期得出是否超过一年以内
//一年以内则提成30% 一年之外为15%
//此处NODAY为ETD-帐期生效日期。大于1年则noday小于-365
strSql . Append ( ",DATEDIFF([day],b.ETD,(select min(bgndate) from Info_Client_ACCDATE where LINKGID=(select gid from Info_Client where SHORTNAME=b.CUSTOMERNAME)))+1 ACTUALDAY" ) ;
strSql . Append ( ",DATEDIFF([day],ISNULL(T.SETTLETIME,GETDATE()),(select min(bgndate) from Info_Client_ACCDATE where LINKGID=(select gid from Info_Client where SHORTNAME=b.CUSTOMERNAME))) NODAY" ) ;
strSql . Append ( ",B.ACCDATE ETDMONTH,(CASE f.ISFEE WHEN 1 THEN '已发放' else '未发放' end) as ISFEEREF,0 ZYTTL " ) ;
strSql . Append ( " FROM v_op_bill_gain_zh 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.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") + "') ");
if ( ! string . IsNullOrEmpty ( strConditionAll ) )
{
strSql . Append ( " and " + strConditionAll ) ;
}
//}
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");
}
strSql . Append ( " SELECT * FROM ##SALEPROFITSHARE " ) ;
//return SetTBData(strCondition, strSql, TEU, PROFITBOUNDS);
return strSql ;
}
private static List < MsOpBillProfit > SetTBData ( string strCondition , StringBuilder strSql , string TEU , string PROFITBOUNDS )
{
//DateTime CurDateBegin = Convert.ToDateTime(Month + "-01");
//DateTime CurDateEnd = CurDateBegin.AddMonths(1).AddDays(-1);
var saleprofitlist = MsInfoSaleProfitShareSetDAL . GetSaleProfitDetailDataList ( "" ) ;
var saleprofitcqlist = MsInfoSaleProfitShareSetDAL . GetSaleProfitCqDataList ( "" ) ;
var tmpsaleprofitlist = saleprofitlist ;
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" ] ) ;
data . STLDATE = Convert . ToString ( reader [ "STLDATE" ] ) ;
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 [ "NODAY" ] ! = DBNull . Value )
data . NODAY = Convert . ToInt32 ( reader [ "NODAY" ] ) ;
data . TiChengBiLi = 0 M ;
data . TiChengBiLiStr = "" ;
data . TiCheng = 0 ;
if ( reader [ "ACTUALDAY" ] ! = DBNull . Value )
{
data . ACTUALDAY = - Convert . ToInt32 ( reader [ "ACTUALDAY" ] ) ;
if ( data . ACTUALDAY < = 365 )
{
data . TiChengBiLi = 0.3 M ;
data . TiChengBiLiStr = "30%" ;
data . TiCheng = data . TTLPROFIT * data . TiChengBiLi ;
}
if ( data . ACTUALDAY > 365 )
{
data . TiChengBiLi = 0.15 M ;
data . TiChengBiLiStr = "15%" ;
data . TiCheng = data . TTLPROFIT * data . TiChengBiLi ;
}
/ /
}
if ( reader [ "ZYTTL" ] ! = DBNull . Value )
data . ZYTTL = Convert . ToDecimal ( reader [ "ZYTTL" ] ) ;
if ( reader [ "TAXPROFIT" ] ! = DBNull . Value )
data . TAXPROFIT = Convert . ToDecimal ( reader [ "TAXPROFIT" ] ) ;
if ( data . TTLPROFIT < 0 )
{
data . ACTUALDAY = 0 ;
}
decimal beginplan = 0 ;
decimal endplan = 0 ;
decimal SHAREPR = 0 ;
data . COMPR = data . TiCheng - data . TAXPROFIT - data . ZYTTL ;
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" ] ) ;
if ( reader [ "TEU" ] ! = DBNull . Value )
data . TEU = Convert . ToDecimal ( reader [ "TEU" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
//优先使用往来单位自己的提成数据
var cdc = new CommonDataContext ( ) ;
var customerlist = headList . Select ( s = > s . CUSTOMERNAME ) . Distinct ( ) . ToList ( ) ;
var custinfolist = cdc . info_client . Where ( x = > customerlist . Contains ( x . SHORTNAME ) ) . ToList ( ) ;
foreach ( var item in headList ) {
if ( custinfolist . Exists ( x = > x . SHORTNAME = = item . CUSTOMERNAME ) ) {
var _customer = custinfolist . FirstOrDefault ( x = > x . SHORTNAME = = item . CUSTOMERNAME ) ;
var tichengbili = item . TiChengBiLi ;
if ( _customer . TICHENG ! = null & & Convert . ToDecimal ( _customer . TICHENG ) ! = 0 )
{
//
//优先使用客户本身的提成数据
/ /
tichengbili = Convert . ToDecimal ( _customer . TICHENG ) / 100 ;
}
if ( tichengbili ! = item . TiChengBiLi ) {
item . TiChengBiLi = tichengbili ;
item . TiChengBiLiStr = ( tichengbili * 100 ) . ToString ( ) + "%" ;
item . TiCheng = item . TTLPROFIT * item . TiChengBiLi ;
}
}
}
//20220510 按sale统计teu和合计利润TTLPROFIT
var saleinfoList =
( from grouping in headList . GroupBy ( x = > new Tuple < string > ( x . SALE ) )
select new sumitem
{
SALE = grouping . Key . Item1 ,
TEU = grouping . Sum ( x = > x . TEU ) ,
TTLPROFIT = grouping . Sum ( x = > x . TTLPROFIT )
} ) . ToList ( ) ;
var TEU_BOUND = 100 M ;
var PROFIT_BOUND = 99999999 M ;
try
{
TEU_BOUND = Convert . ToDecimal ( TEU ) ;
}
finally { }
if ( ! string . IsNullOrWhiteSpace ( PROFITBOUNDS ) ) {
try
{
PROFIT_BOUND = Convert . ToDecimal ( PROFITBOUNDS ) ;
}
catch ( Exception e ) { }
finally { }
}
foreach ( var item in headList )
{
if ( saleinfoList . Exists ( x = > x . SALE = = item . SALE ) )
{
var saleinfo = saleinfoList . FirstOrDefault ( x = > x . SALE = = item . SALE ) ;
if ( saleinfo . TEU > TEU_BOUND | | saleinfo . TTLPROFIT > PROFIT_BOUND ) {
item . TiChengBiLi = item . TiChengBiLi + 0.05 M ;
item . TiChengBiLiStr = ( item . TiChengBiLi * 100 ) . ToString ( ) + "%" ;
item . TiCheng = item . TTLPROFIT * item . TiChengBiLi ;
}
}
}
MsRptZjTotalDAL . MsRptZjTotalDAL . GetZJFee ( ref headList ) ;
return headList ;
}
//20220510 按sale统计teu和合计利润TTLPROFIT
private class sumitem
{
public string SALE { get ; set ; }
public decimal TEU { get ; set ; }
public decimal TTLPROFIT { get ; set ; }
}
# 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 SetFeeCX ( List < MsOpBillProfit > boday , string Month , string expDate_Min , string expDate_Max , 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_tc (GID,BSNO,ISFEE,FCOP,INPUTDATE,INPUTBY,[ACCDATE],[MBLNO],[CUSTNO],[CUSTOMERNAME],[ETD],[OPTYPE]
, [ SETTLETIME ] , [ SALE ] , [ ACTUALDAY ] , [ NODAY ] , [ ACTNODAY ] , [ TiChengQuJian ] , [ COMPR ] , [ ZKTTLPROFIT ] , [ THTTLPROFIT ] , [ TiChengBiLi ] , [ TiCheng ]
, [ KouXi ] , [ PRREMARK ] , [ TiChengBiLiStr ] , [ TTLDR ] , [ TTLCR ] , [ TTLPROFIT ] , [ MONTHTTLPR ] , [ PROFITRATE ] , [ STLTTLDR ] , [ TTLNODR ] , SQLSTR , OPDATE , OPLBNAME , ShiJiTiChengBiLi )
values ( @GID , @BSNO , @ISFEE , @FCOP , @INPUTDATE , @INPUTBY , @ACCDATE , @MBLNO , @CUSTNO , @CUSTOMERNAME , @ETD , @OPTYPE
, @SETTLETIME , @SALE , @ACTUALDAY , @NODAY , @ACTNODAY , @TiChengQuJian , @COMPR , @ZKTTLPROFIT , @THTTLPROFIT , @TiChengBiLi , @TiCheng
, @KouXi , @PRREMARK , @TiChengBiLiStr , @TTLDR , @TTLCR , @TTLPROFIT , @MONTHTTLPR , @PROFITRATE , @STLTTLDR , @TTLNODR , @SQLSTR , @OPDATE , @OPLBNAME , @ShiJiTiChengBiLi ) ");
var cmddelete =
db . GetSqlStringCommand (
@"delete from op_sale_tc 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 . AddInParameter ( cmdInsert , "@ACCDATE" , DbType . String , enumValue . ACCDATE ) ;
db . AddInParameter ( cmdInsert , "@MBLNO" , DbType . String , enumValue . MBLNO ) ;
db . AddInParameter ( cmdInsert , "@CUSTNO" , DbType . String , enumValue . CUSTNO ) ;
db . AddInParameter ( cmdInsert , "@CUSTOMERNAME" , DbType . String , enumValue . CUSTOMERNAME ) ;
db . AddInParameter ( cmdInsert , "@ETD" , DbType . String , enumValue . ETD ) ;
db . AddInParameter ( cmdInsert , "@OPTYPE" , DbType . String , enumValue . OPTYPE ) ;
db . AddInParameter ( cmdInsert , "@SETTLETIME" , DbType . String , enumValue . SETTLETIME ) ;
db . AddInParameter ( cmdInsert , "@SALE" , DbType . String , enumValue . SALE ) ;
db . AddInParameter ( cmdInsert , "@ACTUALDAY" , DbType . String , enumValue . ACTUALDAY ) ;
db . AddInParameter ( cmdInsert , "@NODAY" , DbType . String , enumValue . NODAY ) ;
db . AddInParameter ( cmdInsert , "@ACTNODAY" , DbType . String , enumValue . ACTNODAY ) ;
db . AddInParameter ( cmdInsert , "@TiChengQuJian" , DbType . String , enumValue . TiChengQuJian ) ;
db . AddInParameter ( cmdInsert , "@COMPR" , DbType . String , enumValue . COMPR ) ;
db . AddInParameter ( cmdInsert , "@ZKTTLPROFIT" , DbType . String , enumValue . ZKTTLPROFIT ) ;
db . AddInParameter ( cmdInsert , "@THTTLPROFIT" , DbType . String , enumValue . THTTLPROFIT ) ;
db . AddInParameter ( cmdInsert , "@TiChengBiLi" , DbType . String , enumValue . TiChengBiLi ) ;
db . AddInParameter ( cmdInsert , "@TiCheng" , DbType . String , enumValue . TiCheng ) ;
db . AddInParameter ( cmdInsert , "@KouXi" , DbType . String , enumValue . KouXi ) ;
db . AddInParameter ( cmdInsert , "@PRREMARK" , DbType . String , enumValue . PRREMARK ) ;
db . AddInParameter ( cmdInsert , "@TiChengBiLiStr" , DbType . String , enumValue . TiChengBiLiStr ) ;
db . AddInParameter ( cmdInsert , "@TTLDR" , DbType . String , enumValue . TTLDR ) ;
db . AddInParameter ( cmdInsert , "@TTLCR" , DbType . String , enumValue . TTLCR ) ;
db . AddInParameter ( cmdInsert , "@TTLPROFIT" , DbType . String , enumValue . TTLPROFIT ) ;
db . AddInParameter ( cmdInsert , "@MONTHTTLPR" , DbType . String , enumValue . MONTHTTLPR ) ;
db . AddInParameter ( cmdInsert , "@PROFITRATE" , DbType . String , enumValue . PROFITRATE ) ;
db . AddInParameter ( cmdInsert , "@STLTTLDR" , DbType . String , enumValue . STLTTLDR ) ;
db . AddInParameter ( cmdInsert , "@TTLNODR" , DbType . String , enumValue . TTLNODR ) ;
db . AddInParameter ( cmdInsert , "@SQLSTR" , DbType . String , "结算日期开始:" + expDate_Min + ",结算日期结束:" + expDate_Max ) ;
db . AddInParameter ( cmdInsert , "@OPDATE" , DbType . String , Month ) ;
db . AddInParameter ( cmdInsert , "@OPLBNAME" , DbType . String , enumValue . OPLBNAME ) ;
db . AddInParameter ( cmdInsert , "@ShiJiTiChengBiLi" , DbType . String , enumValue . ShiJiTiChengBiLi ) ;
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,null,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 + "',null,null) 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,CANCELDATE=@CANCELDATE,CANCELBY=@CANCELBY 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 . AddInParameter ( cmdupdate , "@CANCELDATE" , DbType . DateTime , DateTime . Now ) ;
db . AddInParameter ( cmdupdate , "@CANCELBY" , DbType . String , USERID ) ;
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 CancelSetFeeCX ( 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 (
@"delete from op_sale_tc 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.AddInParameter(cmdupdate, "@CANCELDATE", DbType.DateTime, DateTime.Now);
//db.AddInParameter(cmdupdate, "@CANCELBY", DbType.String, USERID);
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 )
{
SqlCommand cmd = new SqlCommand ( ) ;
cmd . CommandText = strSql . ToString ( ) ;
cmd . CommandTimeout = 1200000 ; //要加这一句
var headList = new List < OpSaleTravelFee > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( cmd ) )
{
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 ( ",(CASE WHEN B.OPTYPE='普通货' THEN B.TTLPROFIT ELSE (SELECT TOP 1 (TTLDR-TTLCR) TTLPROFIT FROM v_op_gain_sum WHERE BSNO=B.PARENTID) END) BLTTLPROFIT " ) ;
strSql . Append ( " FROM v_op_bill_gain_tc B " ) ;
if ( isallstl )
{
strSql . Append ( "LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.PARENTID) " ) ;
// 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.PARENTID) " ) ;
}
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 ( ",(CASE WHEN B.OPTYPE='普通货' THEN B.TTLPROFIT ELSE (SELECT TOP 1 (TTLDR-TTLCR) TTLPROFIT FROM v_op_gain_sum WHERE BSNO=B.PARENTID) END) BLTTLPROFIT " ) ;
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) " ) ;
strSql . Append ( "LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR PT ON (PT.BSNO=B.PARENTID) 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 SetRQData ( strSql ) ;
}
private static List < MsOpBillProfit > SetRQData ( 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 . 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" ] ) ;
if ( reader [ "BLTTLPROFIT" ] ! = DBNull . Value )
data . MONTHTTLPR = Convert . ToDecimal ( reader [ "BLTTLPROFIT" ] ) ;
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 . MONTHTTLPR > = 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 . ShiJiTiChengBiLi / 100 ) ;
}
else
{
if ( data . NODAY < = 30 )
{
data . ShiJiTiChengBiLi = data . TiChengBiLi ;
data . TiChengJiShu = data . TTLPROFIT * data . ShiJiTiChengBiLi / 100 ;
}
else
{
var NODAY = data . NODAY - 30 ;
decimal bili = Math . Round ( 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 ;
}
}
}