You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

746 lines
42 KiB

using BWP.B3Frameworks;
using BWP.B3Frameworks.BO.NamedValueTemplate;
using BWP.B3Sale.BO;
using BWP.B3Sale.Utils;
using BWP.Web.Layout;
using BWP.Web.Utils;
using BWP.Web.WebControls;
using Forks.EnterpriseServices.DataForm;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using TSingSoft.WebControls2;
using TSingSoft.WebControls2.QBELinks;
using Forks.EnterpriseServices.SqlDoms;
using BWP.B3_YunKen.BO;
using BWP.B3UnitedInfos;
using Forks.Utils;
using TSingSoft.WebPluginFramework;
using BWP.B3Frameworks.BO.MoneyTemplate;
using BWP.B3Frameworks.Utils;
using BWP.B3UnitedInfos.BO;
using BWP.B3SaleInterface.BO;
using System.Web.UI;
namespace BWP.Web.Pages.B3YunKen.Reports
{
public class ToFreightNetPriceReport2 : DFGridReportPage
{
protected override string AccessRoleName
{
get
{
return "B3_YunKen.报表分析.去运费净价表_验收";
}
}
protected override string Caption
{
get { return "去运费净价表_验收"; }
}
CheckBoxListWithReverseSelect checkbox;
DFChoiceBox _goods, _brandItem, _productLine, _goodsBatch;
DFTextBox _saleout;
DFNamedValueInput<> freightBear;
DFDropDownList billTypeBox;
private readonly DFInfo mDFInfo = DFInfo.Get(typeof(CustomerAccept));
private readonly DFInfo _detailInfo = DFInfo.Get(typeof(CustomerAccept_Detail));
protected override void InitQueryPanel(QueryPanel queryPanel)
{
base.InitQueryPanel(queryPanel);
var panel = queryPanel.CreateTab("显示字段");
checkbox = new CheckBoxListWithReverseSelect() { RepeatColumns = 6, RepeatDirection = RepeatDirection.Horizontal };
var list = new List<Tuple<string, string>>();
list.Add(new Tuple<string, string>("YearOfLoadTime", "每年"));
list.Add(new Tuple<string, string>("TenDaysOfLoadTime", "每旬"));
list.Add(new Tuple<string, string>("MonthOfLoadTime", "每月"));
list.Add(new Tuple<string, string>("WeekOfLoadTime", "每周"));
list.Add(new Tuple<string, string>("DayOfLoadTime", "每日"));
list.Add(new Tuple<string, string>("Code", "编号"));
list.Add(new Tuple<string, string>("Remark", "备注"));
list.Add(new Tuple<string, string>("AccountingUnit_Name", "会计单位"));
list.Add(new Tuple<string, string>("Customer_CustomerCatalog_Name", "客户分类"));
list.Add(new Tuple<string, string>("AccountCustomer_Name", "结账客户"));
list.Add(new Tuple<string, string>("Customer_Name", "购货客户"));
list.Add(new Tuple<string, string>("Customer_DeliveryPhone", "联系方式"));
list.Add(new Tuple<string, string>("SaleForecastCreateTime", "订货时间"));
list.Add(new Tuple<string, string>("CheckTime", "验收审核时间"));
list.Add(new Tuple<string, string>("BillType", "业务类型"));
list.Add(new Tuple<string, string>("Department_Name", "部门"));
list.Add(new Tuple<string, string>("CustomerSaleZone_Name", "地区"));
list.Add(new Tuple<string, string>("SaleKind_Name", "销售类型"));
list.Add(new Tuple<string, string>("Employee_Name", "销售人员"));
list.Add(new Tuple<string, string>("CreditPolicy_Name", "信用政策"));
list.Add(new Tuple<string, string>("OutBillID", "出库单号"));
list.Add(new Tuple<string, string>("FreightMoney", "运费"));
list.Add(new Tuple<string, string>("AcceptMoney", "验收金额"));
list.Add(new Tuple<string, string>("Store_Name", "仓库"));
list.Add(new Tuple<string, string>("DeliverAddress", "送货地址"));
list.Add(new Tuple<string, string>("TakeGoods_Type", "配送方式"));
list.Add(new Tuple<string, string>("Driver_Name", "司机"));
list.Add(new Tuple<string, string>("Driver_Telephone", "司机电话"));
list.Add(new Tuple<string, string>("HandcarNumber", "车牌号"));
list.Add(new Tuple<string, string>("GoodsPropertyCatalog_Name", "存货属性分类"));
list.Add(new Tuple<string, string>("Goods_Name", "存货名称"));
list.Add(new Tuple<string, string>("BrandItem_Name", "品牌"));
list.Add(new Tuple<string, string>("Goods_Spec", "规格"));
list.Add(new Tuple<string, string>("ProductLine_Name", "产品线"));
list.Add(new Tuple<string, string>("PackingMoney", "包装费"));
list.Add(new Tuple<string, string>("Goods_SecondUnit", "辅单位"));
list.Add(new Tuple<string, string>("AcceptSecondNumber", "验收辅数量"));
list.Add(new Tuple<string, string>("Unit", "报价单位"));
list.Add(new Tuple<string, string>("AcceptNum", "验收数量"));
list.Add(new Tuple<string, string>("AcceptPrice", "验收单价"));
list.Add(new Tuple<string, string>("NetPrice", "去包装净价"));
list.Add(new Tuple<string, string>("ToFreightNetPrice", "去运费单价"));
list.Add(new Tuple<string, string>("PolicyPrice", "政策价格"));
list.Add(new Tuple<string, string>("OutNum", "出库数量"));
list.Add(new Tuple<string, string>("OutMoney", "出库金额"));
list.Add(new Tuple<string, string>("CustomerDealer_Name", "经销商"));
list.Add(new Tuple<string, string>("FreightBear", "运费承担方"));
list.Add(new Tuple<string, string>("DeliveryTime", "预报提货时间"));
list.Add(new Tuple<string, string>("OrderLoadTime", "订单提货时间"));
list.Add(new Tuple<string, string>("OutCheckTime", "出库时间"));
list.Add(new Tuple<string, string>("AcceptCheckTime", "验收时间"));
var section = mPageLayoutManager.AddSection("显示字段", "显示字段");
section.ApplyLayout(list, mPageLayoutManager);
foreach (var item in list) {
section.SetDisplayName(item.Item1, item.Item2);
checkbox.Items.Add(new ListItem(item.Item2, item.Item1));
}
panel.EAdd(checkbox);
AddOtherQueryOptionControls(panel);
mQueryControls.Add("显示字段", checkbox);
mQueryControls.EnableHoldLastControlNames.Add("显示字段");
}
CheckBox showGoodsPropertyCatalogLevel, showCumPropertyCatalogLevel, showAddressPropertyCatalogLevel;
DropDownList goodsPropertyCatalogLevel, cumPropertyCatalogLevel, addressPropertyCatalogLevel;
bool TryGetGoodsPropertyCatalogLevel(out int level, string type)
{
level = default(int);
if (type == "goods")
{
if (showGoodsPropertyCatalogLevel == null || goodsPropertyCatalogLevel == null
|| !showGoodsPropertyCatalogLevel.Checked || string.IsNullOrEmpty(goodsPropertyCatalogLevel.SelectedValue)
)
{
return false;
}
level = int.Parse(goodsPropertyCatalogLevel.SelectedValue);
}
else if (type == "cum")
{
if (showCumPropertyCatalogLevel == null || cumPropertyCatalogLevel == null || !showCumPropertyCatalogLevel.Checked || string.IsNullOrEmpty(cumPropertyCatalogLevel.SelectedValue))
{
return false;
}
level = int.Parse(cumPropertyCatalogLevel.SelectedValue);
}
else
{
if (showAddressPropertyCatalogLevel == null || addressPropertyCatalogLevel == null || !showAddressPropertyCatalogLevel.Checked || string.IsNullOrEmpty(addressPropertyCatalogLevel.SelectedValue))
{
return false;
}
level = int.Parse(addressPropertyCatalogLevel.SelectedValue);
}
return true;
}
private void AddOtherQueryOptionControls(Panel panel)
{
var maxDepth = TreeUtil.GetMaxDepth<GoodsPropertyCatalog>();
if (maxDepth == null)
{
return;
}
var maxDepth1 = TreeUtil.GetMaxDepth<SaleCustomerCatalog>();
if (maxDepth1 == null)
{
return;
}
var maxDepth2 = TreeUtil.GetMaxDepth<SaleZone>();
if (maxDepth2 == null)
{
return;
}
var placeHolder = new PlaceHolder();
placeHolder.Controls.Add(new SimpleLabel("<br/>其他显示字段"));
placeHolder.EAddLiteral("<br/>");
#region 属性分类等级
showGoodsPropertyCatalogLevel = new CheckBox() { Text = "属性分类等级" };
placeHolder.Controls.Add(showGoodsPropertyCatalogLevel);
mQueryControls.Add("ShowGoodsPropertyCatalogLevel", showGoodsPropertyCatalogLevel);
placeHolder.Controls.Add(new LiteralControl(" 显示到"));
goodsPropertyCatalogLevel = new DropDownList();
for (var i = 1; i <= maxDepth.Value; i++)
{
goodsPropertyCatalogLevel.Items.Add(new ListItem(i.ToString() + "级", i.ToString()));
}
mQueryControls.Add("GoodsPropertyCatalogLevel", goodsPropertyCatalogLevel);
goodsPropertyCatalogLevel.SelectedValue = string.Empty;
placeHolder.Controls.Add(goodsPropertyCatalogLevel);
placeHolder.EAddLiteral("<br/>");
#endregion
#region 客户分类等级
showCumPropertyCatalogLevel = new CheckBox() { Text = "客户分类等级" };
placeHolder.Controls.Add(showCumPropertyCatalogLevel);
mQueryControls.Add("ShowCumPropertyCatalogLevel", showCumPropertyCatalogLevel);
placeHolder.Controls.Add(new LiteralControl(" 显示到"));
cumPropertyCatalogLevel = new DropDownList();
for (var i = 1; i <= maxDepth1.Value; i++)
{
cumPropertyCatalogLevel.Items.Add(new ListItem(i.ToString() + "级", i.ToString()));
}
mQueryControls.Add("CumPropertyCatalogLevel", cumPropertyCatalogLevel);
cumPropertyCatalogLevel.SelectedValue = string.Empty;
placeHolder.Controls.Add(cumPropertyCatalogLevel);
placeHolder.EAddLiteral("<br/>");
#endregion
#region 销售地区等级
showAddressPropertyCatalogLevel = new CheckBox() { Text = "销售地区等级" };
placeHolder.Controls.Add(showAddressPropertyCatalogLevel);
mQueryControls.Add("ShowAddressPropertyCatalogLevel", showAddressPropertyCatalogLevel);
placeHolder.Controls.Add(new LiteralControl(" 显示到"));
addressPropertyCatalogLevel = new DropDownList();
for (var i = 1; i <= maxDepth2.Value; i++)
{
addressPropertyCatalogLevel.Items.Add(new ListItem(i.ToString() + "级", i.ToString()));
}
mQueryControls.Add("AddressPropertyCatalogLevel", addressPropertyCatalogLevel);
addressPropertyCatalogLevel.SelectedValue = string.Empty;
placeHolder.Controls.Add(addressPropertyCatalogLevel);
#endregion
panel.EAdd(placeHolder);
AddOtherOptions(panel);
}
private CheckBoxList _showTypeList;
private void AddOtherOptions(Panel vPanel)
{
var hPanel = new HLayoutPanel();
vPanel.EAdd(hPanel);
_showTypeList = new CheckBoxList {
RepeatColumns = 6,
RepeatDirection = RepeatDirection.Horizontal
};
_showTypeList.Items.Add(new ListItem("合并单元格") {
Selected = true
});
vPanel.EAdd(new HLayoutPanel() { new SimpleLabel("显示格式"), _showTypeList });
mQueryControls.Add("显示格式", _showTypeList);
}
protected override void AddQueryControls(VLayoutPanel vPanel)
{
var layout = new LayoutManager("main", mDFInfo, mQueryContainer);
layout.Add("AccountingUnit_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["AccountingUnit_ID"],
B3FrameworksConsts.DataSources.), s => long.Parse(s)), "AccountingUnit_ID"));
layout["AccountingUnit_ID"].NotAutoAddToContainer = true;
layout.Add("Goods_ID", new SimpleLabel("存货"), mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(_goods = QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["ID"], B3SaleDataSources.), s => long.Parse(s)), "Goods_ID"));
layout["Goods_ID"].NotAutoAddToContainer = true;
layout.Add("GoodsPropertyCatalog_ID", new SimpleLabel("属性分类"), mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(_productLine = QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["ID"], B3UnitedInfosConsts.DataSources.), s => long.Parse(s)), "GoodsPropertyCatalog_ID"));
layout["GoodsPropertyCatalog_ID"].NotAutoAddToContainer = true;
layout.Add("ProductLine_ID", new SimpleLabel("产品线"), mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(_productLine = QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["ID"], B3UnitedInfosConsts.DataSources.线), s => long.Parse(s)), "ProductLine_ID"));
layout["ProductLine_ID"].NotAutoAddToContainer = true;
layout.Add("Customer_CustomerCatalog_ID", new SimpleLabel("客户分类"), mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["Customer_CustomerCatalog_ID"], B3SaleDataSources.), s => long.Parse(s)), "Customer_CustomerCatalog_ID"));
layout["Customer_CustomerCatalog_ID"].NotAutoAddToContainer = true;
layout.Add("Customer_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["Customer_ID"],
B3SaleDataSources.), s => long.Parse(s)), "Customer_ID"));
layout["Customer_ID"].NotAutoAddToContainer = true;
layout.Add("AccountCustomer_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["AccountCustomer_ID"],
B3SaleDataSources.), s => long.Parse(s)), "AccountCustomer_ID"));
layout["AccountCustomer_ID"].NotAutoAddToContainer = true;
layout.Add("Department_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["Department_ID"], B3FrameworksConsts.DataSources.), s => long.Parse(s)), "Department_ID"));
layout["Department_ID"].NotAutoAddToContainer = true;
layout.Add("Employee_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["Employee_ID"], B3FrameworksConsts.DataSources.), s => long.Parse(s)), "Employee_ID"));
layout["Employee_ID"].NotAutoAddToContainer = true;
//layout.Add("CustomerSaleZone_ID", new SimpleLabel("销售地区"), mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["CustomerSaleZone_ID"], B3SaleDataSources.授权销售地区)), "CustomerSaleZone_ID"));
//layout["CustomerSaleZone_ID"].NotAutoAddToContainer = true;
layout.Add("CustomerSaleZone_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["CustomerSaleZone_ID"], B3SaleDataSources.), s => long.Parse(s)), "CustomerSaleZone_ID"));
layout["CustomerSaleZone_ID"].NotAutoAddToContainer = true;
layout.Add("Store_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["Store_ID"], B3FrameworksConsts.DataSources.), s => long.Parse(s)), "Store_ID"));
layout["Store_ID"].NotAutoAddToContainer = true;
layout.Add("SaleKind_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["SaleKind_ID"], B3SaleDataSources.), s => long.Parse(s)), "SaleKind_ID"));
layout["SaleKind_ID"].NotAutoAddToContainer = true;
layout.Add("Car_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["Car_ID"], B3SaleDataSources.), s => long.Parse(s)), "Car_ID"));
layout["Car_ID"].NotAutoAddToContainer = true;
layout.Add("GoodsBatch_ID", new SimpleLabel("存货批次"), mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(_goodsBatch = QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["ID"], B3UnitedInfosConsts.DataSources.), s => long.Parse(s)), "GoodsBatch_ID"));
layout["GoodsBatch_ID"].NotAutoAddToContainer = true;
layout.Add("BrandItem_ID", new SimpleLabel("品牌项"), mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(_brandItem = QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["Car_ID"], B3UnitedInfosConsts.DataSources.), s => long.Parse(s)), "BrandItem_ID"));
layout["BrandItem_ID"].NotAutoAddToContainer = true;
layout.Add("CustomerDealer_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["CustomerDealer_ID"],
B3SaleDataSources.), s => long.Parse(s)), "CustomerDealer_ID"));
layout["CustomerDealer_ID"].NotAutoAddToContainer = true;
layout.Add("SaleOutID", new SimpleLabel("出库单号"), _saleout = QueryCreator.DFTextBox(mDFInfo.Fields["ID"]));
layout["SaleOutID"].NotAutoAddToContainer = true;
layout.Add("FreightBear", new SimpleLabel("运费承担方"), freightBear = QueryCreator.DFNameValueInputEnableMultiSelection<>(mDFInfo.Fields["ID"]));
layout["SaleOutID"].NotAutoAddToContainer = true;
layout["FreightBear"].NotAutoAddToContainer = true;
billTypeBox = new DFDropDownList() { Width = Unit.Pixel(160) };
billTypeBox.Items.Add("");
billTypeBox.Items.Add(new ListItem("销售出库", DmoTypeIDAttribute.GetID(typeof(SaleOutStore)).ToString()));
billTypeBox.Items.Add(new ListItem("退货入库", DmoTypeIDAttribute.GetID(typeof(ReturnInStore)).ToString()));
layout.Add("BillType", new SimpleLabel("业务类型"), billTypeBox);
layout["BillType"].NotAutoAddToContainer = true;
layout.Add("DeliveryTime", new SimpleLabel("预报提货时间"), QueryCreator.DateRange(mDFInfo.Fields["ID"], mQueryContainer, "MinDeliveryTime", "MaxDeliveryTime"));
layout["DeliveryTime"].NotAutoAddToContainer = true;
layout.Add("OrderLoadTime", new SimpleLabel("订单提货时间"), QueryCreator.DateRange(mDFInfo.Fields["ID"], mQueryContainer, "MinOrderLoadTime", "MaxOrderLoadTime"));
layout["OrderLoadTime"].NotAutoAddToContainer = true;
layout.Add("OutCheckTime", new SimpleLabel("出库时间"), QueryCreator.DateRange(mDFInfo.Fields["ID"], mQueryContainer, "MinOutCheckTime", "MaxOutCheckTime"));
layout["OutCheckTime"].NotAutoAddToContainer = true;
layout.Add("AcceptCheckTime", new SimpleLabel("验收时间"), QueryCreator.DateRange(mDFInfo.Fields["ID"], mQueryContainer, "MinAcceptCheckTime", "MaxAcceptCheckTime"));
layout["AcceptCheckTime"].NotAutoAddToContainer = true;
layout.Add("SaleForecastCreateTime", new SimpleLabel("订货时间"), QueryCreator.DateRange(mDFInfo.Fields["ID"], mQueryContainer, "MinSaleForecastCreateTime", "MaxSaleForecastCreateTime"));
layout["SaleForecastCreateTime"].NotAutoAddToContainer = true;
var config = layout.CreateDefaultConfig(4);
config.Expand = false;
config.Add("Code");
//config.Add("SaleOutID");
//config.Add("ArriveTime");
//config.Add("AccountingUnit_ID");
//config.Add("Goods_ID");
//config.Add("GoodsPropertyCatalog_ID");
//config.Add("ProductLine_ID");
//config.Add("CustomerCatalog_ID");
//config.Add("Customer_ID");
//config.Add("AccountCustomer_ID");
//config.Add("Department_ID");
//config.Add("Employee_ID");
//config.Add("SaleZone_ID");
//config.Add("Store_ID");
//config.Add("SaleKind_ID");
//config.Add("Car_ID");
//config.Add("GoodsBatch_ID");
//config.Add("BrandItem_ID");
layout.Config = config;
var section = mPageLayoutManager.AddSection("查询条件", "查询条件");
section.ApplyLayout(layout, config, mPageLayoutManager, mDFInfo);
vPanel.Add(layout.CreateLayout(), new VLayoutOption(HorizontalAlign.Center));
}
class PackageData
{
public long? Goods_ID { get; set; }
public Money<decimal>? Price { get; set; }
public long? AccountingUnit_ID { get; set; }
}
private DQueryDom GetGoods_Package()
{
var goods_Package = new JoinAlias(typeof(Goods_PackagePrice));
var query = new DQueryDom(goods_Package);
query.Columns.Add(DQSelectColumn.Field("Goods_ID"));
query.Columns.Add(DQSelectColumn.Create(DQExpression.Max(DQExpression.Field("Price")),"packagePrice"));
query.Columns.Add(DQSelectColumn.Field("AccountingUnit_ID"));
query.GroupBy.Expressions.Add(DQExpression.Field("Goods_ID"));
query.GroupBy.Expressions.Add(DQExpression.Field("AccountingUnit_ID"));
return query;
}
protected override DQueryDom GetQueryDom()
{
mDFGrid.AllowRowGroup = _showTypeList.Items.FindByText("合并单元格").Selected;
mDFGrid.AllowSorting = true;
var dom = base.GetQueryDom();
var main = JoinAlias.Create("main");
var detail = new JoinAlias(typeof(CustomerAccept_Detail));
var goods = new JoinAlias(typeof(SaleGoods));
var packageData = new JoinAlias(typeof(PackageData));
var outStore = new JoinAlias(typeof(SaleOutStore));
var outDetail = new JoinAlias(typeof(SaleOutStore_Detail));
var catalog = new JoinAlias(typeof(GoodsPropertyCatalog));
var customer = new JoinAlias(typeof(Customer));
var salzone = new JoinAlias("zone",typeof(SaleZone));
var goodsProperty = new JoinAlias(typeof(GoodsProperty));
var customerCatalo = new JoinAlias(typeof(SaleCustomerCatalog));
var customer2 = new JoinAlias("cus2",typeof(Customer));
var order = new JoinAlias(typeof(Order));
var saleForecast = new JoinAlias(typeof(SaleForecast));
//var salzone = JoinAlias.Create("_9");
//var cus = new JoinAlias(typeof(Customer));
dom.RegisterQueryTable(typeof(PackageData), new string[] { "Goods_ID", "Price", "AccountingUnit_ID" }, GetGoods_Package());
dom.From.AddJoin(JoinType.Left, new DQDmoSource(detail),
DQCondition.EQ(main, "ID", detail, "CustomerAccept_ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(outStore), DQCondition.And(DQCondition.EQ(detail, "BillType",DmoTypeIDAttribute.GetID(typeof(SaleOutStore))),
DQCondition.EQ(outStore, "ID", detail, "BillID")));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(outDetail), DQCondition.And(DQCondition.EQ(detail, "BillType", DmoTypeIDAttribute.GetID(typeof(SaleOutStore))),
DQCondition.EQ(outDetail, "ID", detail, "SourceBillDetailID")));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(packageData),
DQCondition.And(DQCondition.EQ(packageData, "Goods_ID", detail, "SaleGoods_ID"), DQCondition.EQ(packageData, "AccountingUnit_ID", main, "AccountingUnit_ID")));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(goods),
DQCondition.EQ(goods, "ID", detail, "SaleGoods_ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(order), DQCondition.EQ(outStore, "Order_ID", order,"ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(saleForecast), DQCondition.EQ(order, "SaleForecast_ID", saleForecast, "ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(customer), DQCondition.EQ(main, "Customer_ID", customer, "ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(customer2), DQCondition.EQ(main, "CustomerDealer_ID", customer2, "ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(salzone), DQCondition.EQ(customer, "SaleZone_ID", salzone, "ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(goodsProperty), DQCondition.EQ(goodsProperty, "ID", goods, "GoodsProperty_ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(catalog), DQCondition.EQ(catalog, "ID", goodsProperty, "GoodsPropertyCatalog_ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(customerCatalo), DQCondition.EQ(customerCatalo, "ID", customer, "CustomerCatalog_ID"));
//dom.From.AddJoin(JoinType.Left, new DQDmoSource(cus), DQCondition.EQ(main, "", cus));
var freightMoney = DQExpression.Multiply(DQExpression.Field(main, "FreightPrice"), DQExpression.Divide(DQExpression.Field(detail, "AcceptNum"), DQExpression.NullIfZero(DQExpression.Field(main, "AcceptNumber"))));
var Exp = DQExpression.Multiply(DQExpression.Field(packageData, "Price"), DQExpression.Field(detail, "AcceptSecondNumber"));
foreach (ListItem item in checkbox.Items) {
if (!item.Selected) { continue; }
var field = item.Value;
switch (field) {
case "YearOfLoadTime":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Snippet<string>("Left(Convert(nvarchar(10),main.LoadTime, 23),4)"), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Snippet<string>("Left(Convert(nvarchar(10),main.LoadTime, 23),4)"));
ColumnNames.Add(item.Text);
break;
case "MonthOfLoadTime":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Snippet<string>("Left(Convert(nvarchar(10),main.LoadTime, 23),7)"), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Snippet<string>("Left(Convert(nvarchar(10),main.LoadTime, 23),7)"));
ColumnNames.Add(item.Text);
break;
case "TenDaysOfLoadTime":
var expression = DQExpression.Snippet<string>(@"CASE WHEN day(main.LoadTime) > 0 AND day(main.LoadTime)<= 10
THEN cast(YEAR(main.LoadTime)as nvarchar)+'年'+cast(MONTH(main.LoadTime)as nvarchar) + '月上旬'
WHEN day(main.LoadTime) > 10 AND day(main.LoadTime)<= 20
THEN cast(YEAR(main.LoadTime)as nvarchar)+'年'+cast(MONTH(main.LoadTime)as nvarchar) + '月中旬'
WHEN day(main.LoadTime) > 20
THEN cast(YEAR(main.LoadTime)as nvarchar)+'年'+cast(MONTH(main.LoadTime)as nvarchar) + '月下旬' END");
dom.Columns.Add(DQSelectColumn.Create(expression, item.Text));
dom.GroupBy.Expressions.Add(expression);
ColumnNames.Add(item.Text);
break;
case "WeekOfLoadTime":
var expression2 = DQExpression.Snippet<string>("convert(nvarchar(10), dateadd(day,1-(datepart(weekday,main.LoadTime)+@@datefirst-1)%7,main.LoadTime),23)+'~'+convert(nvarchar(10),dateadd(day,7-(datepart(weekday,main.LoadTime)+@@datefirst-1)%7,main.LoadTime),23)");
dom.Columns.Add(DQSelectColumn.Create(expression2, item.Text));
dom.GroupBy.Expressions.Add(expression2);
ColumnNames.Add(item.Text);
break;
case "DayOfLoadTime":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Snippet<string>("Convert(nvarchar(10),main.LoadTime, 23)"), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Snippet<string>("Convert(nvarchar(10),main.LoadTime, 23)"));
ColumnNames.Add(item.Text);
break;
case "DeliveryTime":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(saleForecast, field), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(saleForecast, field));
ColumnNames.Add(item.Text);
break;
case "OrderLoadTime":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(order, "LoadTime"), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(order, "LoadTime"));
ColumnNames.Add(item.Text);
break;
case "OutCheckTime":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(outStore, "CheckTime"), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(outStore, "CheckTime"));
ColumnNames.Add(item.Text);
break;
case "AcceptCheckTime":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(main, "CheckTime"), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(main, "CheckTime"));
ColumnNames.Add(item.Text);
break;
case "Code":
case "Remark":
case "AccountingUnit_Name":
case "Customer_CustomerCatalog_Name":
case "AccountCustomer_Name":
case "Customer_DeliveryPhone":
case "Department_Name":
case "SaleKind_Name":
case "Employee_Name":
case "CreditPolicy_Name":
case "DeliverAddress":
case "TakeGoods_Type":
case "Store_Name":
case "CustomerDealer_Name":
case "Customer_Name":
case "BillType":
case "CreateTime":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(main, field), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(main, field));
ColumnNames.Add(item.Text);
break;
case "CustomerSaleZone_Name":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(customer2, "SaleZone_Name"), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(customer2, "SaleZone_Name"));
ColumnNames.Add(item.Text);
break;
case "Driver_Name":
case "Driver_Telephone":
case "HandcarNumber":
case "FreightBear":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(outStore, field), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(outStore, field));
ColumnNames.Add(item.Text);
break;
case "OutBillID":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(outStore, "ID"), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(outStore, "ID"));
ColumnNames.Add(item.Text);
break;
case "OutNum":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(outDetail, "Number")), item.Text));
ColumnNames.Add(item.Text);
SumColumnNames.Add(item.Text);
break;
case "OutMoney":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(outDetail, "Money")), item.Text));
ColumnNames.Add(item.Text);
SumColumnNames.Add(item.Text);
break;
case "GoodsPropertyCatalog_Name":
case "Goods_Name":
case "BrandItem_Name":
case "Goods_SecondUnit":
case "Unit":
case "Goods_Spec":
case "ProductLine_Name":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(detail, field), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(detail, field));
ColumnNames.Add(item.Text);
break;
case "PolicyPrice":
case "AcceptPrice":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Avg(DQExpression.Field(detail, field)).ECastType<Money<>?>(), item.Text));
ColumnNames.Add(item.Text);
break;
case "FreightMoney":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(freightMoney).ECastType<Money<>?>(), item.Text));
ColumnNames.Add(item.Text);
//SumColumnIndexs.Add(dom.Columns.Count - 1);
break;
case "AcceptMoney":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(detail, field)), item.Text));
ColumnNames.Add(item.Text);
SumColumnNames.Add(item.Text);
break;
case "AcceptNum":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(detail, field)), item.Text));
ColumnNames.Add(item.Text);
SumColumnNames.Add(item.Text);
break;
case "AcceptSecondNumber":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(detail, field)), item.Text));
ColumnNames.Add(item.Text);
SumColumnNames.Add(item.Text);
break;
case "PackingMoney":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(Exp).ECastType<Money<>?>(), item.Text));
ColumnNames.Add(item.Text);
//SumColumnIndexs.Add(dom.Columns.Count - 1);
break;
case "NetPrice":
//var 购方netExp = DQExpression.Divide(DQExpression.Sum(DQExpression.Subtract(DQExpression.Field(detail, "AcceptMoney"), DQExpression.IfNull(包装费Exp, DQExpression.Value(0)))) , DQExpression.NullIfZero(DQExpression.Sum(DQExpression.Field(detail, "AcceptNum"))));
//var 供方netExp = DQExpression.Divide(DQExpression.Sum(DQExpression.Subtract(DQExpression.Field(detail, "AcceptMoney"), DQExpression.IfNull(freightMoney, DQExpression.Value(0))).ESubtract(DQExpression.IfNull(包装费Exp, DQExpression.Value(0)))), DQExpression.NullIfZero(DQExpression.Sum(DQExpression.Field(detail, "AcceptNum"))));
//var netExp = DQExpression.LogicCase(DQCondition.EQ(outStore, "FreightBear", 运费承担方.购方), 购方netExp, DQCondition.EQ(outStore, "FreightBear", 运费承担方.供方), 供方netExp, DQExpression.Value(null));
//dom.GroupBy.Expressions.Add(DQExpression.Field(outStore, "FreightBear"));
//dom.Columns.Add(DQSelectColumn.Create(netExp.ECastType<Money<金额>?>(), item.Text));
var netExp = DQExpression.Divide(DQExpression.Sum(DQExpression.Subtract(DQExpression.Field(detail, "AcceptMoney"), DQExpression.IfNull(DQExpression.LogicCase(DQCondition.EQ(outStore, "FreightBear", .), DQExpression.Value(0), freightMoney), DQExpression.Value(0))).ESubtract(DQExpression.IfNull(Exp, DQExpression.Value(0)))), DQExpression.NullIfZero(DQExpression.Sum(DQExpression.Field(detail, "AcceptNum"))));
dom.Columns.Add(DQSelectColumn.Create(netExp.ECastType<Money<>?>(), item.Text));
ColumnNames.Add(item.Text);
break;
case "ToFreightNetPrice":
// 增加逻辑,当运费承担方为‘购方’:
//{去运费单价}= 验收单价
//{去包装净价}=(验收金额 - 包装费用)÷验收报价数量
// 当运费承担方为‘供方’
//{去运费单价}=(验收金额 - 运费费用)÷报价数量
//{去包装净价}=(验收金额 - 包装费用 - 运费)÷验收报价数量
//var 购方priceExp = DQExpression.Sum(DQExpression.Field(detail, "AcceptMoney")).ESafeDivide(DQExpression.Sum(DQExpression.Field(detail, "AcceptNum"))) ;
//var 供方priceExp = DQExpression.Divide(DQExpression.Sum(DQExpression.Subtract(DQExpression.Field(detail, "AcceptMoney"), DQExpression.IfNull(freightMoney, DQExpression.Value(0)))), DQExpression.NullIfZero(DQExpression.Sum(DQExpression.Field(detail, "AcceptNum"))));
//var priceExp = DQExpression.LogicCase(DQCondition.EQ(outStore, "FreightBear", 运费承担方.购方), 购方priceExp, DQCondition.EQ(outStore, "FreightBear", 运费承担方.供方), 供方priceExp, DQExpression.Value(null));
//dom.Columns.Add(DQSelectColumn.Create(priceExp.ECastType<Money<金额>?>(), item.Text));
//dom.GroupBy.Expressions.Add(DQExpression.Field(outStore, "FreightBear"));
var priceExp = DQExpression.Divide(DQExpression.Sum(DQExpression.Subtract(DQExpression.Field(detail, "AcceptMoney"), DQExpression.IfNull(DQExpression.LogicCase(DQCondition.EQ(outStore, "FreightBear", .), DQExpression.Value(0), freightMoney), DQExpression.Value(0)))), DQExpression.NullIfZero(DQExpression.Sum(DQExpression.Field(detail, "AcceptNum"))));
dom.Columns.Add(DQSelectColumn.Create(priceExp.ECastType<Money<>?>(), item.Text));
ColumnNames.Add(item.Text);
break;
case "SaleForecastCreateTime":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(saleForecast, "CreateTime"), item.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(saleForecast, "CreateTime"));
ColumnNames.Add(item.Text);
break;
}
}
int selectedGoodsPropertyCatalogLevel;
if (TryGetGoodsPropertyCatalogLevel(out selectedGoodsPropertyCatalogLevel, "goods"))
{
for (var i = 1; i <= selectedGoodsPropertyCatalogLevel; i++)
{
var p = new JoinAlias("_p" + i, typeof(GoodsPropertyCatalog));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(p), DQCondition.EQ(p, "ID", catalog, "TreeDeep" + i + "ID"));
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(p, "Name"), "存货属性" + i + "级分类"));
dom.GroupBy.Expressions.Add(DQExpression.Field(p, "Name"));
ColumnNames.Add("存货属性" + i + "级分类");
}
}
if (TryGetGoodsPropertyCatalogLevel(out selectedGoodsPropertyCatalogLevel, "cum"))
{
for (var i = 1; i <= selectedGoodsPropertyCatalogLevel; i++)
{
var c = new JoinAlias("_cum" + i, typeof(SaleCustomerCatalog));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(c), DQCondition.EQ(c, "ID", customerCatalo, "TreeDeep" + i + "ID"));
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(c, "Name"), "客户" + i + "级分类"));
dom.GroupBy.Expressions.Add(DQExpression.Field(c, "Name"));
ColumnNames.Add("客户" + i + "级分类");
}
}
if (TryGetGoodsPropertyCatalogLevel(out selectedGoodsPropertyCatalogLevel, "zone"))
{
for (var i = 1; i <= selectedGoodsPropertyCatalogLevel; i++)
{
var z = new JoinAlias("_zone" + i, typeof(SaleZone));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(z), DQCondition.EQ(z, "ID", salzone, "TreeDeep" + i + "ID"));
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(z, "Name"), "地区" + i + "级分类"));
dom.GroupBy.Expressions.Add(DQExpression.Field(z, "Name"));
ColumnNames.Add("地区" + i + "级分类");
}
}
if (!_goods.IsEmpty) {
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "SaleGoods_ID"), _goods.GetValues().Select(x => DQExpression.Value(x)).ToArray()));
}
if (!_brandItem.IsEmpty) {
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "BrandItem_ID"), _brandItem.GetValues().Select(x => DQExpression.Value(x)).ToArray()));
}
//if (!_goodsPropertyCatalog.IsEmpty) {
// dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "GoodsPropertyCatalog_ID"), _goodsPropertyCatalog.GetValues().Select(x => DQExpression.Value(x)).ToArray()));
//}
TreeUtil.AddTreeMultiSelectConditions<GoodsPropertyCatalog>(dom, mQueryContainer, "GoodsPropertyCatalog_ID", catalog);
TreeUtil.AddTreeMultiSelectConditions<SaleZone>(dom, mQueryContainer, "CustomerSaleZone_ID", salzone);
TreeUtil.AddTreeMultiSelectConditions<SaleCustomerCatalog>(dom, mQueryContainer, "Customer_CustomerCatalog_ID", customerCatalo);
if (!_productLine.IsEmpty) {
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(goods, "ProductLine_ID"), _productLine.GetValues().Select(x => DQExpression.Value(x)).ToArray()));
}
if (!_goodsBatch.IsEmpty) {
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "GoodsBatch_ID"), _goodsBatch.GetValues().Select(x => DQExpression.Value(x)).ToArray()));
}
var minDeliveryTime = mQueryContainer.GetControl<DFDateInput>("MinDeliveryTime").Value;
var maxDeliveryTime = mQueryContainer.GetControl<DFDateInput>("MaxDeliveryTime").Value;
if (minDeliveryTime.HasValue) {
dom.Where.Conditions.Add(DQCondition.GreaterThanOrEqual(saleForecast, "DeliveryTime", minDeliveryTime));
}
if (maxDeliveryTime.HasValue) {
dom.Where.Conditions.Add(DQCondition.LessThanOrEqual(saleForecast, "DeliveryTime", maxDeliveryTime));
}
var minSaleForecastCreateTime = mQueryContainer.GetControl<DFDateInput>("MinSaleForecastCreateTime").Value;
var maxSaleForecastCreateTime = mQueryContainer.GetControl<DFDateInput>("MaxSaleForecastCreateTime").Value;
if (minSaleForecastCreateTime.HasValue) {
dom.Where.Conditions.Add(DQCondition.GreaterThanOrEqual(saleForecast, "CreateTime", minSaleForecastCreateTime));
}
if (maxSaleForecastCreateTime.HasValue) {
dom.Where.Conditions.Add(DQCondition.LessThanOrEqual(saleForecast, "CreateTime", maxSaleForecastCreateTime));
}
var minOrderLoadTime = mQueryContainer.GetControl<DFDateInput>("MinOrderLoadTime").Value;
var maxOrderLoadTime = mQueryContainer.GetControl<DFDateInput>("MaxOrderLoadTime").Value;
if (minOrderLoadTime.HasValue) {
dom.Where.Conditions.Add(DQCondition.GreaterThanOrEqual(order, "LoadTime", minOrderLoadTime));
}
if (maxOrderLoadTime.HasValue) {
dom.Where.Conditions.Add(DQCondition.LessThanOrEqual(order, "LoadTime", maxOrderLoadTime));
}
var minOutCheckTime = mQueryContainer.GetControl<DFDateInput>("MinOutCheckTime").Value;
var maxOutCheckTime = mQueryContainer.GetControl<DFDateInput>("MaxOutCheckTime").Value;
if (minOutCheckTime.HasValue) {
dom.Where.Conditions.Add(DQCondition.GreaterThanOrEqual(outStore, "CheckTime", minOutCheckTime));
}
if (maxOutCheckTime.HasValue) {
dom.Where.Conditions.Add(DQCondition.LessThanOrEqual(outStore, "CheckTime", maxOutCheckTime));
}
var minAcceptCheckTime = mQueryContainer.GetControl<DFDateInput>("MinAcceptCheckTime").Value;
var maxAcceptCheckTime = mQueryContainer.GetControl<DFDateInput>("MaxAcceptCheckTime").Value;
if (minAcceptCheckTime.HasValue) {
dom.Where.Conditions.Add(DQCondition.GreaterThanOrEqual(main, "CheckTime", minAcceptCheckTime));
}
if (maxAcceptCheckTime.HasValue) {
dom.Where.Conditions.Add(DQCondition.LessThanOrEqual(main, "CheckTime", maxAcceptCheckTime));
}
if (!_saleout.IsEmpty)
{
dom.Where.Conditions.Add(DQCondition.EQ(outStore, "ID", long.Parse(_saleout.Text)));
}
if (!freightBear.IsEmpty)
{
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(outStore, "FreightBear"), freightBear.GetValues().Select(x=> DQExpression.Value(x)).ToArray()));
}
if (billTypeBox.SelectedIndex > 0){
dom.Where.Conditions.Add(DQCondition.EQ("BillType", billTypeBox.SelectedValue));
}
dom.Where.Conditions.Add(DQCondition.EQ(main, "BillState", .));
return dom;
}
}
}