DS7/DSWeb/Areas/MvcShipping/Controllers/MsRptOpProfitController.cs

5092 lines
385 KiB
C#

This file contains ambiguous Unicode characters!

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

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.RptMng.Comm;
using HcUtility.Comm;
using HcUtility.Core;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.MvcShipping.Controllers
{
/// <summary>
/// 利润报表查询
/// </summary>
[JsonRequestBehavior]
public class MsRptOpProfitController : Controller
{
private static string PROFITBLCOUNTNOTFEN = MsSysParamSetDAL.GetData("PARAMNAME='PROFITBLCOUNTNOTFEN'").PARAMVALUE;
public const string BLTYPE = "(isnull(A.BLTYPE,'')<>'' and A.BLTYPE<>'拼箱' OR A.BLTYPE<>'拼箱单票')"; //(A .BLTYPE='整箱' OR A.BLTYPE='拼箱主票')
public const string BLTYPE_B = "(isnull(B.BLTYPE,'')<>'' and B.BLTYPE<>'拼箱' OR B.BLTYPE<>'拼箱单票')";
//
// GET: /MvcShipping/MsRptOpProfit
public ActionResult Index()
{
return View();
}
public ActionResult DsIndex()
{
return View();
}
public ActionResult LHIndex()
{
return View();
}
public ActionResult ZJIndex()
{
return View();
}
//
// GET/RptMng/MsRptPcHeadQry/QryData
public ContentResult ZjZyListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
strDa = strDa.Replace("B.","");
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT * FROM V_ZJZY_FEE ");
strSql.Append(" WHERE 1=1 ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
//strSql.Append("SELECT *,(CASE WHEN ZYDAY<=20 THEN 0 ELSE CASE WHEN ZYDAY<=40 THEN 0 ELSE END END) FROM (");
//strSql.Append("SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
//strSql.Append("C.[DESCRIPTION] AS CUSTFULLNAME, ");
//strSql.Append("B.ETD,B.PKGS,B.CBM");
//strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID,B.ETA,B.SALEDEPT,B.ISSUETYPE,B.ISCANCEL,B.ATD,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.BSSOURCEDETAIL");
//strSql.Append(",case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
//strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.CNTRTOTAL,B.CORPID");
//strSql.Append(",B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
//strSql.Append(",SUM(G.RMBDR) RMBDR,SUM(G.RMBCR) RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) USDDR,SUM(G.USDCR) USDCR,");
//strSql.Append("SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) OTDR,SUM(G.OTCR) OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(ISNULL(G.TTLDR,0)) TTLDR,");
//strSql.Append("SUM(ISNULL(G.TTLCR,0)) TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
//strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
//strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
//strSql.Append(",T.SETTLETIME STLDRDATE,CT.SETTLETIME STLCRDATE,CASE WHEN ISNULL(CT.SETTLETIME,'')='' OR ISNULL(T.SETTLETIME,GETDATE())<=ISNULL(CT.SETTLETIME,GETDATE()) THEN 0 ELSE (DATEDIFF([day],ISNULL(CT.SETTLETIME,GETDATE()),ISNULL(T.SETTLETIME,GETDATE()))) END ZYDAY");
//strSql.Append(" FROM V_OP_BILL B ");
//strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
//strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
//strSql.Append("LEFT JOIN V_MAX_SETTLEMENTTIME_BSDR T ON (T.BSNO=B.BSNO) ");
//strSql.Append("LEFT JOIN V_MIN_SETTLEMENTTIME_CR CT ON (T.BSNO=B.BSNO) ");
//strSql.Append(" WHERE 1=1 ");
//if (!string.IsNullOrEmpty(condition))
//{
// strSql.Append(" and " + condition);
//}
//strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
//strSql.Append("C.[DESCRIPTION] , ");
//strSql.Append("B.ETD,B.PKGS,B.CBM");
//strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID,B.ETA,B.SALEDEPT,B.ISSUETYPE,B.ISCANCEL,B.ATD,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.BSSOURCEDETAIL");
//strSql.Append(",B.CUSTOMDATE");
//strSql.Append(",B.FEESTATUS,B.SALECORPID");
//strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, 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.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
//strSql.Append(",T.SETTLETIME,CT.SETTLETIME");
//strSql.Append(") AS V");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by ETD DESC,MBLNO");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = condition,
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ETD DESC,MBLNO");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult BsListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
if (amendstr == "true")
{
strSql.Append("SELECT B.BSNO, B.OPLB,B.OPLBNAME,'普通货' OPTYPE, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append("C.[DESCRIPTION] AS CUSTFULLNAME, ");
strSql.Append("B.ETD,B.PKGS,B.CBM,B.CNTRSEALNO,B.TRUCKER,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.BSSOURCEDETAIL");
strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID,B.ETA,B.SALEDEPT,B.ISSUETYPE,B.ISCANCEL,B.ATD");
strSql.Append(",case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE");
strSql.Append(",case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, 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(",SUM(ISNULL(G.RMBDR,0)) RMBDR,SUM(ISNULL(G.RMBCR,0)) RMBCR,SUM(ISNULL(G.STLRMBDR,0)) STLRMBDR,SUM(ISNULL(G.STLRMBCR,0)) STLRMBCR,SUM(ISNULL(G.USDDR,0)) USDDR,SUM(ISNULL(G.USDCR,0)) USDCR,");
strSql.Append("SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) OTDR,SUM(G.OTCR) OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(ISNULL(G.TTLDR,0)) TTLDR,");
strSql.Append("SUM(ISNULL(G.TTLCR,0)) TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.RMBDR-G.STLRMBDR) AS RMBNODR,SUM(G.USDDR-G.STLUSDDR) AS USDNODR,SUM(G.OTDR-G.STLOTDR) AS OTNODR,SUM(G.TTLDR-G.STLTTLDR) AS TTLNODR");
strSql.Append(",SUM(G.RMBCR-G.STLRMBCR) AS RMBNOCR,SUM(G.USDCR-G.STLUSDCR) AS USDNOCR,SUM(G.OTCR-G.STLOTCR) AS OTNOCR,SUM(G.TTLCR-G.STLTTLCR) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) NOTAXRMBDR,SUM(G.NOTAXRMBCR) NOTAXRMBCR,SUM(G.NOTAXUSDDR) NOTAXUSDDR,SUM(G.NOTAXUSDCR) NOTAXUSDCR,SUM(G.NOTAXOTDR) NOTAXOTDR");
strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" ,cd.COUNTRY,cd.CHAU ");
strSql.Append(" FROM V_OP_BS B ");
//strSql.Append("left join code_disport cd on cd.EDICODE=b.DESTINATIONID ");
strSql.Append(" left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append("C.[DESCRIPTION] , ");
strSql.Append("B.ETD,B.PKGS,B.CBM,B.CNTRSEALNO,B.TRUCKER");
strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID,B.ETA,B.SALEDEPT,B.ISSUETYPE,B.ISCANCEL,B.ATD,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.BSSOURCEDETAIL");
strSql.Append(",B.CUSTOMDATE");
strSql.Append(",B.FEESTATUS,B.SALECORPID");
strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, 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(",CD.COUNTRY,CD.CHAU");
}
else
{
strSql.Append("SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append("C.[DESCRIPTION] AS CUSTFULLNAME, ");
strSql.Append("B.ETD,B.PKGS,B.CBM,B.CNTRSEALNO,B.TRUCKER");
strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID,B.ETA,B.SALEDEPT,B.ISSUETYPE,B.ISCANCEL,B.ATD,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.BSSOURCEDETAIL");
strSql.Append(",case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE");
strSql.Append(",case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.CNTRTOTAL,B.CORPID");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",SUM(G.RMBDR) RMBDR,SUM(G.RMBCR) RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) USDDR,SUM(G.USDCR) USDCR,");
strSql.Append("SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) OTDR,SUM(G.OTCR) OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(ISNULL(G.TTLDR,0)) TTLDR,");
strSql.Append("SUM(ISNULL(G.TTLCR,0)) TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) NOTAXRMBDR,SUM(G.NOTAXRMBCR) NOTAXRMBCR,SUM(G.NOTAXUSDDR) NOTAXUSDDR,SUM(G.NOTAXUSDCR) NOTAXUSDCR,SUM(G.NOTAXOTDR) NOTAXOTDR");
strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" ,cd.COUNTRY,cd.CHAU ");
strSql.Append(" FROM V_OP_BILL B left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append("C.[DESCRIPTION] , ");
strSql.Append("B.ETD,B.PKGS,B.CBM,B.CNTRSEALNO,B.TRUCKER");
strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID,B.ETA,B.SALEDEPT,B.ISSUETYPE,B.ISCANCEL,B.ATD,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.BSSOURCEDETAIL");
strSql.Append(",B.CUSTOMDATE");
strSql.Append(",B.FEESTATUS,B.SALECORPID");
strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, 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(",CD.COUNTRY,CD.CHAU");
}
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.ETD DESC,B.MBLNO");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = condition,
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.ETD DESC,B.MBLNO");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult BsLHListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
if (amendstr == "true")
{
strSql.Append("SELECT B.BSNO, B.OPLB,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append("C.[DESCRIPTION] AS CUSTFULLNAME,(SELECT SHIPPER FROM OP_SEAE WHERE BSNO=B.BSNO) SHIPPER, ");
strSql.Append("B.ETD,B.PKGS,B.CBM,B.CNTRSEALNO,B.TRUCKER,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.BSSOURCEDETAIL");
strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID,B.ETA,B.SALEDEPT,B.ISSUETYPE,B.ISCANCEL,B.ATD");
strSql.Append(",case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE");
strSql.Append(",case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF");
strSql.Append(",case B.BSSTATUS when 1 then '锁定' else '未锁定' end as BSSTATUSREF");
strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, 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(",SUM(ISNULL(G.RMBDR,0)) RMBDR,SUM(ISNULL(G.RMBCR,0)) RMBCR,SUM(ISNULL(G.STLRMBDR,0)) STLRMBDR,SUM(ISNULL(G.STLRMBCR,0)) STLRMBCR,SUM(ISNULL(G.USDDR,0)) USDDR,SUM(ISNULL(G.USDCR,0)) USDCR,");
strSql.Append("SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) OTDR,SUM(G.OTCR) OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(ISNULL(G.TTLDR,0)) TTLDR,");
strSql.Append("SUM(ISNULL(G.TTLCR,0)) TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(G.RMBDR-G.STLRMBDR) AS RMBNODR,SUM(G.USDDR-G.STLUSDDR) AS USDNODR,SUM(G.OTDR-G.STLOTDR) AS OTNODR,SUM(G.TTLDR-G.STLTTLDR) AS TTLNODR");
strSql.Append(",SUM(G.RMBCR-G.STLRMBCR) AS RMBNOCR,SUM(G.USDCR-G.STLUSDCR) AS USDNOCR,SUM(G.OTCR-G.STLOTCR) AS OTNOCR,SUM(G.TTLCR-G.STLTTLCR) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) NOTAXRMBDR,SUM(G.NOTAXRMBCR) NOTAXRMBCR,SUM(G.NOTAXUSDDR) NOTAXUSDDR,SUM(G.NOTAXUSDCR) NOTAXUSDCR,SUM(G.NOTAXOTDR) NOTAXOTDR");
strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append("C.[DESCRIPTION] , ");
strSql.Append("B.ETD,B.PKGS,B.CBM,B.CNTRSEALNO,B.TRUCKER");
strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID,B.ETA,B.SALEDEPT,B.ISSUETYPE,B.ISCANCEL,B.ATD,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.BSSOURCEDETAIL");
strSql.Append(",B.CUSTOMDATE");
strSql.Append(",B.FEESTATUS");
strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, 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");
}
else
{
strSql.Append("SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append("C.[DESCRIPTION] AS CUSTFULLNAME,(SELECT SHIPPER FROM OP_SEAE WHERE BSNO=B.PARENTID) SHIPPER, ");
strSql.Append("B.ETD,B.PKGS,B.CBM,B.CNTRSEALNO,B.TRUCKER");
strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID,B.ETA,B.SALEDEPT,B.ISSUETYPE,B.ISCANCEL,B.ATD,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.BSSOURCEDETAIL");
strSql.Append(",case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE");
strSql.Append(",case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF");
strSql.Append(",case B.BSSTATUS when 1 then '锁定' else '未锁定' end as BSSTATUSREF");
strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.CNTRTOTAL,B.CORPID");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",SUM(G.RMBDR) RMBDR,SUM(G.RMBCR) RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) USDDR,SUM(G.USDCR) USDCR,");
strSql.Append("SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) OTDR,SUM(G.OTCR) OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(ISNULL(G.TTLDR,0)) TTLDR,");
strSql.Append("SUM(ISNULL(G.TTLCR,0)) TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) NOTAXRMBDR,SUM(G.NOTAXRMBCR) NOTAXRMBCR,SUM(G.NOTAXUSDDR) NOTAXUSDDR,SUM(G.NOTAXUSDCR) NOTAXUSDCR,SUM(G.NOTAXOTDR) NOTAXOTDR");
strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
// strSql.Append("LEFT JOIN OP_CLOSE CL ON (CL.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,B.BLFRT,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,B.YARD,B.CONTRACTNO,B.ORDERNO,");
strSql.Append("C.[DESCRIPTION] , B.PARENTID,");
strSql.Append("B.ETD,B.PKGS,B.CBM,B.CNTRSEALNO,B.TRUCKER");
strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.AGENTID,B.ETA,B.SALEDEPT,B.ISSUETYPE,B.ISCANCEL,B.ATD,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.BSSOURCEDETAIL");
strSql.Append(",B.CUSTOMDATE");
strSql.Append(",B.FEESTATUS");
strSql.Append(",B.CUSTSERVICE,B.FRCUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE,B.DESTINATION, 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");
}
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.ETD DESC,B.MBLNO");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = condition,
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.ETD DESC,B.MBLNO");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult CustListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var bstype = "";
var RPTPROFITBYBSTYPE = MsSysParamSetDAL.GetData("PARAMNAME='RPTPROFITBYBSTYPE'");
if (RPTPROFITBYBSTYPE.PARAMVALUE == "1")
{
bstype = ",B.BSTYPE";
}
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var strSql = new StringBuilder();
if (amendstr == "true")
{
strSql.Append("SELECT B.CUSTOMERNAME" + bstype);
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append($",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" Group by B.CUSTOMERNAME,C.[DESCRIPTION] " + bstype);
}
else
{
strSql.Append("SELECT B.CUSTOMERNAME" + bstype);
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",ISNULL(SUM(G.RMBDR),0) AS RMBDR,ISNULL(SUM(G.RMBCR),0) AS RMBCR,ISNULL(SUM(G.STLRMBDR),0) AS STLRMBDR,ISNULL(SUM(G.STLRMBCR),0) AS STLRMBCR,ISNULL(SUM(G.USDDR),0) AS USDDR,ISNULL(SUM(G.USDCR),0) AS USDCR,ISNULL(SUM(G.STLUSDDR),0) AS STLUSDDR,ISNULL(SUM(G.STLUSDCR),0) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" Group by B.CUSTOMERNAME,C.[DESCRIPTION] " + bstype);
}
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.CUSTOMERNAME");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.CUSTOMERNAME");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult CarrierListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var bstype = "";
var RPTPROFITBYBSTYPE = MsSysParamSetDAL.GetData("PARAMNAME='RPTPROFITBYBSTYPE'");
if (RPTPROFITBYBSTYPE.PARAMVALUE == "1")
{
bstype = ",B.BSTYPE";
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
if (amendstr == "true")
{
strSql.Append("SELECT B.CARRIER" + bstype);
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append("SELECT B.CARRIER" + bstype);
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by B.CARRIER " + bstype);
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.CARRIER");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.CARRIER");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult SaleListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var SALERPTONLYSALE = MsSysParamSetDAL.GetData("PARAMNAME='SALERPTONLYSALE'");
var strSql = new StringBuilder();
if (SALERPTONLYSALE.PARAMVALUE == "1")
{
strSql.Append("SELECT B.SALE");
}
else
{
strSql.Append("SELECT B.SALE, B.BSSOURCE");
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
if (amendstr == "true")
{
strSql.Append(",B.SALE SALEGROUP,SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",B.SALE SALEGROUP,sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
if (SALERPTONLYSALE.PARAMVALUE == "1")
{
strSql.Append(" Group by B.SALE ");
}
else
strSql.Append(" Group by B.SALE, B.BSSOURCE ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by B.SALE," + sortstr);
}
else
{
if (SALERPTONLYSALE.PARAMVALUE == "1")
{
strSql.Append(" order by B.SALE ");
}
else
strSql.Append(" order by B.SALE, B.BSSOURCE");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
if (SALERPTONLYSALE.PARAMVALUE == "1")
{
strSql.Append(" order by B.SALE ");
}
else
strSql.Append(" order by B.SALE, B.BSSOURCE");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult DeptListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
if (amendstr == "true")
{
strSql.Append("SELECT * FROM (SELECT U.DEPTNAME SALEDEPT ");
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append($",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
strSql.Append(" LEFT JOIN VW_user U ON (U.SHOWNAME=B.SALE) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" Group by U.DEPTNAME ");
strSql.Append(") as t ");
}
else
{
strSql.Append("SELECT * FROM (SELECT U.DEPTNAME SALEDEPT ");
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append(" LEFT JOIN VW_user U ON (U.SHOWNAME=B.SALE) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" Group by U.DEPTNAME ");
strSql.Append(") as t ");
}
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by SALEDEPT");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
// sortstring = sortstring.Replace("SALEDEPT", "U.DEPTNAME");
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by SALEDEPT");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult OpListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var OPRPTONLYOP = MsSysParamSetDAL.GetData("PARAMNAME='OPRPTONLYOP'");
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
if (OPRPTONLYOP.PARAMVALUE == "1")
{
strSql.Append("SELECT B.OP");
}
else
{
strSql.Append("SELECT B.OP, B.BSTYPE");
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
if (OPRPTONLYOP.PARAMVALUE == "1")
{
strSql.Append(" Group by B.OP ");
}
else
{
strSql.Append(" Group by B.OP, B.BSTYPE ");
}
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
if (OPRPTONLYOP.PARAMVALUE == "1")
{
strSql.Append(" order by B.OP");
}
else {
strSql.Append(" order by B.OP, B.BSTYPE");
}
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
if (OPRPTONLYOP.PARAMVALUE == "1")
{
strSql.Append(" order by B.OP");
}
else
{
strSql.Append(" order by B.OP, B.BSTYPE");
}
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult OpDeptListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var strSql = new StringBuilder();
strSql.Append("SELECT * FROM (SELECT U.DEPTNAME OPDEPT");
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append($",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append(" LEFT JOIN VW_user U ON (U.SHOWNAME=B.OP) ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" Group by U.DEPTNAME ");
strSql.Append(") as t ");
}
else
{
strSql.Append(",sum(case when B.OPTYPE='更改单' then 0 else 1 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append(" LEFT JOIN VW_user U ON (U.SHOWNAME=B.OP) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" Group by U.DEPTNAME ");
strSql.Append(") as t ");
}
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by OPDEPT ");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by OPDEPT ");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult BsSourceListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
strSql.Append("SELECT B.BSSOURCE");
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by B.BSSOURCE ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.BSSOURCE");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.BSSOURCE");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult BsSourceDetailListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var strSql = new StringBuilder();
strSql.Append("SELECT B.BSSOURCE,B.BSSOURCEDETAIL");
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append($",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by B.BSSOURCE,B.BSSOURCEDETAIL ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.BSSOURCE,B.BSSOURCEDETAIL");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.BSSOURCE,B.BSSOURCEDETAIL");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult LaneListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
if (amendstr == "true")
{
strSql.Append("SELECT B.LANE,SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" Group by B.LANE ");
}
else
{
strSql.Append("SELECT B.LANE");
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" Group by B.LANE ");
}
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.LANE");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.LANE");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult PortListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
strSql.Append("SELECT B.PORTDISCHARGE");
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by B.PORTDISCHARGE ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.PORTDISCHARGE");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.PORTDISCHARGE");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult PortLoadListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
strSql.Append("SELECT B.PORTLOAD");
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by B.PORTLOAD ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.PORTLOAD");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.PORTLOAD");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult DocListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
strSql.Append("SELECT B.DOC");
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by B.DOC ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.DOC");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.DOC");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult CustServiceListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
strSql.Append("SELECT B.CUSTSERVICE");
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by B.CUSTSERVICE ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.CUSTSERVICE");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.CUSTSERVICE");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult ForwarderListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var bstype = "";
var RPTPROFITBYBSTYPE = MsSysParamSetDAL.GetData("PARAMNAME='RPTPROFITBYBSTYPE'");
if (RPTPROFITBYBSTYPE.PARAMVALUE == "1")
{
bstype = ",B.BSTYPE";
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
strSql.Append("SELECT B.FORWARDER" + bstype);
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by B.FORWARDER " + bstype);
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.FORWARDER");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.FORWARDER");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
/// <summary>
/// 装运方式
/// </summary>
/// <param name="start"></param>
/// <param name="limit"></param>
/// <param name="condition"></param>
/// <param name="feecondition"></param>
/// <param name="sort"></param>
/// <param name="printstr"></param>
/// <param name="sortstr"></param>
/// <param name="amendstr"></param>
/// <returns></returns>
public ContentResult BltypeListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
strSql.Append("SELECT B.BLTYPE");
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append($",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by B.BLTYPE ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.BLTYPE");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.BLTYPE");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
/// <summary>
/// 国家
/// </summary>
/// <param name="start"></param>
/// <param name="limit"></param>
/// <param name="condition"></param>
/// <param name="feecondition"></param>
/// <param name="sort"></param>
/// <param name="printstr"></param>
/// <param name="sortstr"></param>
/// <param name="amendstr"></param>
/// <returns></returns>
public ContentResult CountryData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
strSql.Append("SELECT isnull(cd.COUNTRY,'') COUNTRY ");
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by isnull(cd.COUNTRY,'') ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by COUNTRY");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by COUNTRY");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
/// <summary>
/// 区域
/// </summary>
/// <param name="start"></param>
/// <param name="limit"></param>
/// <param name="condition"></param>
/// <param name="feecondition"></param>
/// <param name="sort"></param>
/// <param name="printstr"></param>
/// <param name="sortstr"></param>
/// <param name="amendstr"></param>
/// <returns></returns>
public ContentResult CHAUData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
strSql.Append("SELECT isnull(cd.CHAU,'') CHAU ");
if (amendstr == "true")
{
strSql.Append(",SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append(",sum(case when B.OPTYPE='普通货' " + nofensql + " then 1 else 0 end) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU");
strSql.Append(",SUM(G.RMBDR) AS RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) AS STLRMBDR,SUM(G.STLRMBCR) AS STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) AS STLUSDDR,SUM(G.STLUSDCR) AS STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) AS STLOTDR,SUM(G.STLOTCR) AS STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) AS STLTTLDR,SUM(G.STLTTLCR) AS STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B left join (select * from( select *,row_number() over (partition by EDICODE order by CHAU desc) as rownum from (select EDICODE,COUNTRY,CHAU from code_disport union all select PORTENAME EDICODE,COUNTRY,'' CHAU from code_air_port)t4) t3 where t3.rownum = 1) cd on B.DESTINATIONID = cd.EDICODE ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
strSql.Append(" Group by isnull(cd.CHAU,'') ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by CHAU");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CHAU");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult SumListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var nofensql = "";
if (PROFITBLCOUNTNOTFEN == "1") nofensql = " AND B.BLTYPE<>'拼箱分票' and B.BLTYPE<>'合票分票' ";
var strSql = new StringBuilder();
//strSql.Append(" ");
//if (amendstr == "true")
//{
// strSql.Append("SELECT SUM(case WHEN A.OPTYPE='普通货' THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN A.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN A.CBM ELSE 0 END) CBM");
// strSql.Append(",SUM(ISNULL(G.RMBDR,0)) RMBDR,SUM(ISNULL(G.RMBCR,0)) RMBCR,SUM(ISNULL(G.STLRMBDR,0)) STLRMBDR,SUM(ISNULL(G.STLRMBCR,0)) STLRMBCR,SUM(ISNULL(G.USDDR,0)) USDDR,SUM(ISNULL(G.USDCR,0)) USDCR,");
// strSql.Append("SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) OTDR,SUM(G.OTCR) OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(ISNULL(G.TTLDR,0)) TTLDR,");
// strSql.Append("SUM(ISNULL(G.TTLCR,0)) TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
// strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
// if (PROFITRATEDR.PARAMVALUE != "1")
// {
// strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
// }
// else
// strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
// strSql.Append(",SUM(G.RMBDR-G.STLRMBDR) AS RMBNODR,SUM(G.USDDR-G.STLUSDDR) AS USDNODR,SUM(G.OTDR-G.STLOTDR) AS OTNODR,SUM(G.TTLDR-G.STLTTLDR) AS TTLNODR");
// strSql.Append(",SUM(G.RMBCR-G.STLRMBCR) AS RMBNOCR,SUM(G.USDCR-G.STLUSDCR) AS USDNOCR,SUM(G.OTCR-G.STLOTCR) AS OTNOCR,SUM(G.TTLCR-G.STLTTLCR) AS TTLNOCR");
// strSql.Append(",SUM(G.NOTAXRMBDR) NOTAXRMBDR,SUM(G.NOTAXRMBCR) NOTAXRMBCR,SUM(G.NOTAXUSDDR) NOTAXUSDDR,SUM(G.NOTAXUSDCR) NOTAXUSDCR,SUM(G.NOTAXOTDR) NOTAXOTDR");
// strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
// strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
// strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
// strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
// strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
// strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// // strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
// strSql.Append(" FROM V_OP_BS B ");
// strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
// if (!string.IsNullOrEmpty(feecondition))
// {
// strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
// strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
// strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
// strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
// strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
// strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
// strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
// strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
// strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// // strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
// strSql.Append(" FROM v_op_gain_sum_INV G");
// strSql.Append(" Where " + feecondition);
// strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
// strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
// }
// else
// {
// strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
// strSql.Append(" WHERE 1=1 ");
// }
// if (!string.IsNullOrEmpty(condition))
// {
// strSql.Append(" and " + condition);
// }
//}
//else
//{
if (amendstr == "true")
{
strSql.Append("SELECT SUM(case WHEN A.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN A.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN A.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN A.OPTYPE='普通货' THEN A.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN A.OPTYPE='普通货' AND {BLTYPE子句} THEN A.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BS B ");
strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=A.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
}
else
{
strSql.Append("SELECT SUM(case WHEN B.OPTYPE='普通货' " + nofensql + " THEN 1 ELSE 0 END) AS BLCOUNT,SUM(case WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,SUM(case WHEN B.OPTYPE='普通货' THEN B.CBM ELSE 0 END) CBM,");
strSql.Append("SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
//else
// strSql.Append("COUNT(DISTINCT B.BSNO) AS BLCOUNT,SUM(G.RMBDR) as RMBDR,SUM(G.RMBCR) AS RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) AS USDDR,SUM(G.USDCR) AS USDCR,SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) AS OTDR,SUM(G.OTCR) AS OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) AS TTLDR,SUM(G.TTLCR) AS TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append($",SUM(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) AS NETWEIGHT,SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.TEU ELSE 0 END) AS TEU,SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.CNTR1 ELSE 0 END) AS CNTR1,SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.CNTR2 ELSE 0 END) AS CNTR2,");
strSql.Append($"SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.CNTR3 ELSE 0 END) AS CNTR3,SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.CNTR4 ELSE 0 END) AS CNTR4,SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.CNTR5 ELSE 0 END) AS CNTR5,");
strSql.Append($"SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.CNTR6 ELSE 0 END) AS CNTR6,SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.CNTR7 ELSE 0 END) AS CNTR7,SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.CNTR8 ELSE 0 END) AS CNTR8,");
strSql.Append($"SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.CNTR9 ELSE 0 END) AS CNTR9,SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.CNTR10 ELSE 0 END) AS CNTR10,SUM(CASE WHEN B.OPTYPE='普通货' AND {BLTYPE子句_B} THEN B.OTCNTR ELSE 0 END) AS OTCNTR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) AS NOTAXRMBDR,SUM(G.NOTAXRMBCR) AS NOTAXRMBCR,SUM(G.NOTAXUSDDR) AS NOTAXUSDDR,SUM(G.NOTAXUSDCR) AS NOTAXUSDCR,SUM(G.NOTAXOTDR) AS NOTAXOTDR,SUM(G.NOTAXOTCR) AS NOTAXOTCR,SUM(G.NOTAXTTLDR) AS NOTAXTTLDR,SUM(G.NOTAXTTLCR) AS NOTAXTTLCR");
strSql.Append(",SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT,SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
if (PROFITRATEDR.PARAMVALUE != "1")
{
strSql.Append(", (CASE WHEN (SUM(G.TTLDR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLDR)) * 100, 10, 2))) END) AS PROFITRATE");
}
else
strSql.Append(", (CASE WHEN (SUM(G.TTLCR))= 0 THEN 0 ELSE CONVERT(NUMERIC(18,2),ltrim(str((SUM(G.TTLDR-G.TTLCR)) / (SUM(G.TTLCR)) * 100, 10, 2))) END) AS PROFITRATE");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(feecondition))
{
strSql.Append("LEFT JOIN (SELECT BSNO, sum(RMBDR) RMBDR,SUM(RMBCR) RMBCR,SUM(STLRMBDR) STLRMBDR,SUM(STLRMBCR) STLRMBCR,SUM(USDDR) USDDR");
strSql.Append(",SUM(USDCR) USDCR,SUM(STLUSDDR) STLUSDDR,SUM(STLUSDCR) STLUSDCR,SUM(OTDR) OTDR");
strSql.Append(",SUM(OTCR) OTCR,SUM(STLOTDR) STLOTDR,SUM(STLOTCR) STLOTCR,SUM(TTLTAXDR) TTLTAXDR,SUM(TTLTAXCR) TTLTAXCR");
strSql.Append(",SUM(TTLDR) TTLDR,SUM(TTLCR) TTLCR,SUM(STLTTLDR) STLTTLDR,SUM(STLTTLCR) STLTTLCR");
strSql.Append(",SUM(NOTAXRMBDR) NOTAXRMBDR,SUM(NOTAXRMBCR) NOTAXRMBCR,SUM(NOTAXUSDDR) NOTAXUSDDR ");
strSql.Append(",SUM(NOTAXUSDCR) NOTAXUSDCR,SUM(NOTAXOTDR) NOTAXOTDR,SUM(NOTAXOTCR) NOTAXOTCR,SUM(NOTAXTTLDR) NOTAXTTLDR,SUM(NOTAXTTLCR) NOTAXTTLCR");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM v_op_gain_sum_INV G");
strSql.Append(" Where " + feecondition);
strSql.Append("GROUP BY BSNO) G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE ISNULL(G.BSNO,'')<>'' ");
}
else
{
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" AND " + condition);
}
}
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult DsBsListData(int start, int limit, string condition, string feecondition, string sort, string printstr, string sortstr, string amendstr = "false")
{
var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (!string.IsNullOrEmpty(strDa))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + strDa;
}
else
{
condition = strDa;
}
}
var RPTPRNOCANCEL = MsSysParamSetDAL.GetData("PARAMNAME='RPTPRNOCANCEL'");
if (RPTPRNOCANCEL.PARAMVALUE == "1")
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and B.ISCANCEL<>'1' ";
}
else
{
condition = " B.ISCANCEL<>'1' ";
}
}
var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'");
var strSql = new StringBuilder();
strSql.Append("SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,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("C.[DESCRIPTION] AS CUSTFULLNAME, ");
strSql.Append("B.ETD,B.PKGS,B.CBM,B.NETWEIGHT");
strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK");
strSql.Append(",case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF");
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.CNTRTOTAL,B.CORPID");
strSql.Append(",B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
strSql.Append(",SUM(G.RMBDR) RMBDR,SUM(G.RMBCR) RMBCR,SUM(G.STLRMBDR) STLRMBDR,SUM(G.STLRMBCR) STLRMBCR,SUM(G.USDDR) USDDR,SUM(G.USDCR) USDCR,");
strSql.Append("SUM(G.STLUSDDR) STLUSDDR,SUM(G.STLUSDCR) STLUSDCR,SUM(G.OTDR) OTDR,SUM(G.OTCR) OTCR,SUM(G.STLOTDR) STLOTDR,SUM(G.STLOTCR) STLOTCR,SUM(G.TTLDR) TTLDR,");
strSql.Append("SUM(G.TTLCR) TTLCR,SUM(G.STLTTLDR) STLTTLDR,SUM(G.STLTTLCR) STLTTLCR");
strSql.Append(",SUM(ISNULL(G.USDDR-G.USDCR,0)) AS USDPROFIT,SUM(ISNULL(G.RMBDR-G.RMBCR,0)) AS RMBPROFIT,SUM(ISNULL(G.OTDR-G.OTCR,0)) AS OTPROFIT,SUM(ISNULL(G.TTLDR-G.TTLCR,0)) AS TTLPROFIT ");
strSql.Append(",SUM(ISNULL(G.RMBDR-G.STLRMBDR,0)) AS RMBNODR,SUM(ISNULL(G.USDDR-G.STLUSDDR,0)) AS USDNODR,SUM(ISNULL(G.OTDR-G.STLOTDR,0)) AS OTNODR,SUM(ISNULL(G.TTLDR-G.STLTTLDR,0)) AS TTLNODR");
strSql.Append(",SUM(ISNULL(G.RMBCR-G.STLRMBCR,0)) AS RMBNOCR,SUM(ISNULL(G.USDCR-G.STLUSDCR,0)) AS USDNOCR,SUM(ISNULL(G.OTCR-G.STLOTCR,0)) AS OTNOCR,SUM(ISNULL(G.TTLCR-G.STLTTLCR,0)) AS TTLNOCR");
strSql.Append(",SUM(G.NOTAXRMBDR) NOTAXRMBDR,SUM(G.NOTAXRMBCR) NOTAXRMBCR,SUM(G.NOTAXUSDDR) NOTAXUSDDR,SUM(G.NOTAXUSDCR) NOTAXUSDCR,SUM(G.NOTAXOTDR) NOTAXOTDR");
strSql.Append(",SUM(G.NOTAXOTCR) NOTAXOTCR,SUM(G.NOTAXTTLDR) NOTAXTTLDR,SUM(G.NOTAXTTLCR) NOTAXTTLCR,SUM(G.NOTAXUSDDR-G.NOTAXUSDCR) AS NOTAXUSDPROFIT");
strSql.Append(",SUM(G.NOTAXRMBDR-G.NOTAXRMBCR) AS NOTAXRMBPROFIT,SUM(G.NOTAXOTDR-G.NOTAXOTCR) AS NOTAXOTPROFIT,SUM(G.NOTAXTTLDR-G.NOTAXTTLCR) AS NOTAXTTLPROFIT ");
strSql.Append(",SUM(G.TTLDR-G.NOACCTAXTTLDR) AS TTLTAXDR,SUM(G.TTLCR-G.NOACCTAXTTLCR) AS TTLTAXCR,SUM(G.TTLDR-G.NOACCTAXTTLDR-(G.TTLCR-G.NOACCTAXTTLCR)) AS TTLTAXPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR) NOACCTAXRMBDR,SUM(G.NOACCTAXRMBCR) NOACCTAXRMBCR,SUM(G.NOACCTAXUSDDR) NOACCTAXUSDDR,SUM(G.NOACCTAXUSDCR) NOACCTAXUSDCR,SUM(G.NOACCTAXOTDR) NOACCTAXOTDR");
strSql.Append(",SUM(G.NOACCTAXOTCR) NOACCTAXOTCR,SUM(G.NOACCTAXTTLDR) NOACCTAXTTLDR,SUM(G.NOACCTAXTTLCR) NOACCTAXTTLCR,SUM(G.NOACCTAXUSDDR-G.NOACCTAXUSDCR) AS NOACCTAXUSDPROFIT");
strSql.Append(",SUM(G.NOACCTAXRMBDR-G.NOACCTAXRMBCR) AS NOACCTAXRMBPROFIT,SUM(G.NOACCTAXOTDR-G.NOACCTAXOTCR) AS NOACCTAXOTPROFIT,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS NOACCTAXTTLPROFIT ");
// strSql.Append(",SUM(G.NOACCTAXTTLDR) AS TTLACCTAXDR,SUM(G.NOACCTAXTTLCR) AS TTLACCTAXCR,SUM(G.NOACCTAXTTLDR-G.NOACCTAXTTLCR) AS TTLACCTAXPROFIT");
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=B.CUSTOMERNAME) ");
strSql.Append(" WHERE 1=1 ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(" GROUP BY B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.BLTYPE,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("C.[DESCRIPTION] , ");
strSql.Append("B.ETD,B.PKGS,B.CBM,B.NETWEIGHT");
strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK");
strSql.Append(",B.CUSTOMDATE");
strSql.Append(",B.FEESTATUS");
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");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.CUSTOMERNAME,B.OPLB,B.CREATETIME DESC");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = condition,
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.CUSTOMERNAME,B.OPLB,B.CREATETIME DESC");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult BsParentListData( string condition, string sort)
{
var strSql = new StringBuilder();
strSql.Append("SELECT B.BSNO,B.MBLNO,B.OPTYPE, B.CUSTNO,B.ACCDATE,G.TTLDR-G.TTLCR TTLPROFIT");
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
strSql.Append(" WHERE 1=1 ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.ETD DESC,B.MBLNO");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(0, 50, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
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,AUTHORITYID,VSSQL ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modProfitreportRange' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
string VSSQL = "";
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"]);
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
VSSQL = Convert.ToString(reader["VSSQL"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = "1=2";
}
else if (visiblerange == "3")
{
str = " (B.OP='" + usercode + "' OR B.SALE='" + usercode + "' OR B.CUSTSERVICE='" + usercode + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptid = rangeDa.GetDEPTGID(userid);
//str = " (B.OP in (select showname from vw_user where deptgid='" + deptid + "') OR B.SALE in (select showname from vw_user where deptgid='" + deptid + "') OR B.CUSTSERVICE in (select showname from vw_user where deptgid='" + deptid + "') "
//+ " OR B.DOC in (select showname from vw_user where deptgid='" + deptid + "') OR B.FRCUSTSERVICE in (select showname from vw_user where deptgid='" + deptid + "') )";
str = " exists( select 1 from vw_user where deptgid='" + deptid + "' and(showname=B.OP OR showname=B.SALE OR showname=B.CUSTSERVICE OR showname=B.FRCUSTSERVICE OR showname=B.DOC )) ";
}
else if (visiblerange == "5")
{
var userstr = new StringBuilder();
userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " (B.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' or B.SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "' ";
}
else
{
str = str + " or B.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' or B.SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "'";
};
}
str = str + ")";
reader.Close();
}
}
else if (visiblerange == "6")
{
str = " EXISTS (select 1 from user_authority_range_op P left join [user] u on (u.GID=P.OPID) where (B.OP=U.SHOWNAME OR B.SALE=U.SHOWNAME OR B.CUSTSERVICE=U.SHOWNAME) AND P.userid='" + userid + "' and P.AUTHORITYID='" + AUTHORITYID + "' and P.VISIBLERANGE=1) ";
}
else if (visiblerange == "1")
{
str = " (UPPER(B.Corpid)='" + companyid + "' or B.SALECORPID='" + companyid + "') ";
}
VSSQL = VSSQL.Trim();
if (!string.IsNullOrEmpty(VSSQL))
{
if (!string.IsNullOrEmpty(str))
{
str = str + " and (" + VSSQL + ") ";
}
else
{
str = " (" + VSSQL + ") ";
}
}
return str;
}
#region 参照部分
#endregion
}
}