From da8d8ea1ecc2315ecb7d7ed6afecddc7256cacd5 Mon Sep 17 00:00:00 2001
From: yibo <361071264@qq.com>
Date: Fri, 9 Nov 2018 21:06:35 +0800
Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E6=B1=82=E5=8D=95No.141724=20?=
=?UTF-8?q?=E4=B8=87=E7=A6=8F=E6=A8=A1=E5=9D=97=E6=96=B0=E5=A2=9E=E5=AE=9A?=
=?UTF-8?q?=E5=88=B6=E6=8A=A5=E8=A1=A8=E3=80=90=E9=94=80=E5=94=AE=E7=BB=9F?=
=?UTF-8?q?=E8=AE=A1=E8=A1=A8=E3=80=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
B3QingDaoWanFu.Web/B3QingDaoWanFu.Web.csproj | 7 +
.../SaleSummaryReport_/SaleSummaryReport.cs | 293 ++++++++++++++++++
.../config/plugins/B3QingDaoWanFu.plugin | 2 +
3 files changed, 302 insertions(+)
create mode 100644 B3QingDaoWanFu.Web/Pages/B3QingDaoWanFu/Reports/SaleSummaryReport_/SaleSummaryReport.cs
diff --git a/B3QingDaoWanFu.Web/B3QingDaoWanFu.Web.csproj b/B3QingDaoWanFu.Web/B3QingDaoWanFu.Web.csproj
index de5cc0d..5a3616f 100644
--- a/B3QingDaoWanFu.Web/B3QingDaoWanFu.Web.csproj
+++ b/B3QingDaoWanFu.Web/B3QingDaoWanFu.Web.csproj
@@ -84,6 +84,10 @@
..\..\..\tsref\Debug\B3Sale.Web.dll
False
+
+ False
+ ..\..\..\tsref\Debug\B3SaleInterface.dll
+
False
D:\BwpB3Project\tsref\Debug\B3UnitedInfos.dll
@@ -201,6 +205,9 @@
ASPXCodeBehind
+
+ ASPXCodeBehind
+
ASPXCodeBehind
diff --git a/B3QingDaoWanFu.Web/Pages/B3QingDaoWanFu/Reports/SaleSummaryReport_/SaleSummaryReport.cs b/B3QingDaoWanFu.Web/Pages/B3QingDaoWanFu/Reports/SaleSummaryReport_/SaleSummaryReport.cs
new file mode 100644
index 0000000..ad9b6c4
--- /dev/null
+++ b/B3QingDaoWanFu.Web/Pages/B3QingDaoWanFu/Reports/SaleSummaryReport_/SaleSummaryReport.cs
@@ -0,0 +1,293 @@
+using BWP.B3Frameworks;
+using BWP.B3Frameworks.BO;
+using BWP.B3Frameworks.BO.NamedValueTemplate;
+using BWP.B3Sale.BO;
+using BWP.Web.Utils;
+using Forks.EnterpriseServices.DomainObjects2;
+using Forks.EnterpriseServices.DomainObjects2.DQuery;
+using Forks.EnterpriseServices.SqlDoms;
+using Forks.Utils;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Web.UI;
+using TSingSoft.WebControls2;
+using TSingSoft.WebPluginFramework;
+
+namespace BWP.Web.Pages.B3QingDaoWanFu.Reports.SaleSummaryReport_
+{
+ class SaleSummaryReport : ClickQueryReportPage
+ {
+ protected override string AccessRoleName
+ {
+ get { return "B3QingDaoWanFu.报表.销售统计表"; }
+ }
+
+ protected override string Caption
+ {
+ get { return "销售统计表"; }
+ }
+
+ protected override void InitDFGrid(DFGrid mDfGrid)
+ {
+ base.InitDFGrid(mDfGrid);
+ mDfGrid.AllowRowGroup = true;
+ mDfGrid.AllowColGroup = true;
+ mDfGrid.AllowSorting = true;
+ mDfGrid.HeaderPagerLock = true;
+ }
+
+ protected override void CreateQueryPanel(VLayoutPanel vPanel)
+ {
+ var list = new List>();
+ list.Add(new Tuple("First", "一级部门"));
+ list.Add(new Tuple("Second", "二级部门"));
+
+
+ var dic = list.Select((item) => item.Item1).EToHashSet();
+
+ var tablePanel = vPanel.Add(new TableLayoutPanel(1, 2), new VLayoutOption(System.Web.UI.WebControls.HorizontalAlign.Justify));
+
+ tablePanel.Add(0, 1, 0, 1, CreateFirstDept());
+ tablePanel.Add(0, 1, 1, 2, CreateSecondDept());
+ }
+
+ List> FirstDepts
+ {
+ get
+ {
+ if (ViewState["FirstDepts"] == null)
+ ViewState["FirstDepts"] = GetFirstDepts();
+ return (List>)ViewState["FirstDepts"];
+ }
+ set { ViewState["FirstDepts"] = value; }
+ }
+
+ List> GetFirstDepts()
+ {
+ var dept = SaleDepartmentInfo;
+ var query = new DQueryDom(new JoinAlias(typeof(Department)));
+ query.Columns.Add(DQSelectColumn.Field("ID"));
+ query.Columns.Add(DQSelectColumn.Field("Name"));
+ query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Domain_ID", DomainContext.Current.ID), DQCondition.EQ("Stopped", false), DQCondition.EQ("Depth", dept.Item2 + 1)));
+ query.Where.Conditions.Add(DQCondition.EQ(string.Format("TreeDeep{0}ID", dept.Item2), dept.Item1));
+ query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID"));
+ return query.EExecuteList();
+ }
+
+ Tuple SaleDepartmentInfo
+ {
+ get
+ {
+ if (ViewState["SaleDepartmentInfo"] == null)
+ {
+ var dept = WebBLUtil.GetSingleDmo("Name", "销售部", "ID", "Depth");
+ if (dept == null)
+ throw new Exception("没有名称为销售部的部门");
+ ViewState["SaleDepartmentInfo"] = new Tuple(dept.ID, dept.Depth);
+ }
+ return (Tuple)ViewState["SaleDepartmentInfo"];
+ }
+ }
+
+ List> SecondDepts
+ {
+ get
+ {
+ if (ViewState["SecondDepts"] == null)
+ ViewState["SecondDepts"] = GetSecondDepts();
+ return (List>)ViewState["SecondDepts"];
+ }
+ set { ViewState["SecondDepts"] = value; }
+ }
+
+ List> GetSecondDepts()
+ {
+ var depth = SaleDepartmentInfo.Item2;
+ var selectedItem = firstFilterTree.GetSelecteItem();
+ if (!selectedItem.Selected || string.IsNullOrEmpty(selectedItem.Value))
+ return new List>();
+ var query = new DQueryDom(new JoinAlias(typeof(Department)));
+ query.Columns.Add(DQSelectColumn.Field("ID"));
+ query.Columns.Add(DQSelectColumn.Field("Name"));
+ query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Domain_ID", DomainContext.Current.ID), DQCondition.EQ("Stopped", false), DQCondition.EQ("Depth", depth + 2)));
+ query.Where.Conditions.Add(DQCondition.EQ(string.Format("TreeDeep{0}ID", depth + 1), long.Parse(firstFilterTree.GetSelecteItem().Value)));
+ query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID"));
+ return query.EExecuteList();
+ }
+
+ static FilterTree firstFilterTree;
+ private Control CreateFirstDept()
+ {
+ firstFilterTree = new FilterTree() { AllLinkOnFirst = true };
+ firstFilterTree.HorizontalRepeatColumns = 10;
+ this.Load += delegate
+ {
+ if (!IsPostBack)
+ {
+ firstFilterTree.DataSource.Childs.Clear();
+ foreach (var item in FirstDepts)
+ {
+ var node = new FilterTreeNode(item.Item2, item.Item1.ToString());
+ firstFilterTree.DataSource.Childs.Add(node);
+ }
+ }
+ };
+
+ mTreeContainer.Add("First", firstFilterTree);
+ firstFilterTree.Select += (sender, e) =>
+ {
+ SecondDepts = GetSecondDepts();
+ BuildSecond();
+ };
+ firstFilterTree.FilterAction = (query, node) =>
+ {
+ if (!string.IsNullOrEmpty(node.Value))
+ {
+ query.Where.Conditions.Add(DQCondition.EQ(JoinAlias.Create("dept"), "TreeDeep1ID", long.Parse(node.Value)));
+ }
+ };
+
+ return firstFilterTree;
+ }
+
+ void BuildSecond()
+ {
+ secondFilterTree.DataSource.Childs.Clear();
+ foreach (var item in SecondDepts)
+ {
+ var node = new FilterTreeNode(item.Item2, item.Item1.ToString());
+ secondFilterTree.DataSource.Childs.Add(node);
+ }
+ }
+
+ static FilterTree secondFilterTree;
+ private Control CreateSecondDept()
+ {
+ secondFilterTree = new FilterTree() { AllLinkOnFirst = true };
+ secondFilterTree.HorizontalRepeatColumns = 10;
+ this.Load += delegate
+ {
+ if (!IsPostBack)
+ BuildSecond();
+ };
+
+ mTreeContainer.Add("Second", secondFilterTree);
+ secondFilterTree.FilterAction = (query, node) =>
+ {
+ if (!string.IsNullOrEmpty(node.Value))
+ {
+ query.Where.Conditions.Add(DQCondition.EQ(JoinAlias.Create("dept"), "TreeDeep2ID", long.Parse(node.Value)));
+ }
+ };
+
+ return secondFilterTree;
+ }
+
+ readonly string[] goodsBrand = new string[] { "条类", "分割品", "副产品", "冻品" };
+
+ protected override DQueryDom GetQueryDom()
+ {
+ var main = new JoinAlias(typeof(TempClass));
+ var dept = new JoinAlias("dept", typeof(Department));
+ var _3Dept = new JoinAlias("_3Dept", typeof(Department));
+ var customer = new JoinAlias(typeof(Customer));
+ var goods = new JoinAlias(typeof(SaleGoods));
+ var query = new DQueryDom(main);
+ TempClass.Register(query);
+ query.From.AddJoin(JoinType.Left, new DQDmoSource(dept), DQCondition.EQ(main, "Department_ID", dept, "ID"));
+ query.From.AddJoin(JoinType.Left, new DQDmoSource(_3Dept), DQCondition.EQ(dept, "TreeDeep3ID", _3Dept, "ID"));
+ query.From.AddJoin(JoinType.Left, new DQDmoSource(customer), DQCondition.EQ(main, "Customer_ID", customer, "ID"));
+ query.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(main, "Goods_ID", goods, "ID"));
+
+ query.Columns.Add(DQSelectColumn.Field("Name", _3Dept, "销售部门"));
+ query.GroupBy.Expressions.Add(DQExpression.Field(_3Dept, "Name"));
+ query.Columns.Add(DQSelectColumn.Field("CustomerCatalog_Name", customer));
+ query.GroupBy.Expressions.Add(DQExpression.Field(customer, "CustomerCatalog_Name"));
+ query.GroupBy.Expressions.Add(DQExpression.Field(customer, "CustomerCatalog_ID"));
+ query.OrderBy.Expressions.Add(DQOrderByExpression.Create(customer, "CustomerCatalog_ID"));
+ foreach (var item in goodsBrand)
+ {
+ if (item == "条类")
+ {
+ query.Columns.Add(DQSelectColumn.Create(DQExpression.Divide(DQExpression.Sum(DQExpression.LogicCase(DQCondition.And(DQCondition.EQ(goods, "Brand", item), DQCondition.EQ("Type", 2)), DQExpression.Field("SecondNumber"), DQExpression.NULL)), DQExpression.Value(7)), item + "|上周日均头数"));
+ query.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.LogicCase(DQCondition.And(DQCondition.EQ(goods, "Brand", item), DQCondition.EQ("Type", 1)), DQExpression.Field("SecondNumber"), DQExpression.NULL)), item + "|头数"));
+ }
+
+ query.Columns.Add(DQSelectColumn.Create(DQExpression.Divide(DQExpression.Sum(DQExpression.LogicCase(DQCondition.And(DQCondition.EQ(goods, "Brand", item), DQCondition.EQ("Type", 2)), DQExpression.Field("MainNumber"), DQExpression.NULL)), DQExpression.Value(7)), item + "|上周日均重量"));
+ query.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.LogicCase(DQCondition.And(DQCondition.EQ(goods, "Brand", item), DQCondition.EQ("Type", 1)), DQExpression.Field("MainNumber"), DQExpression.NULL)), item + "|重量"));
+ }
+
+ query.Columns.Add(DQSelectColumn.Create(DQExpression.Divide(DQExpression.Sum(DQExpression.LogicCase(DQCondition.EQ("Type", 2), DQExpression.Field("MainNumber"), DQExpression.NULL)), DQExpression.Value(7)), "上周日均重量"));
+ query.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.LogicCase(DQCondition.EQ("Type", 1), DQExpression.Field("MainNumber"), DQExpression.NULL)), "当日重量合计"));
+
+ var idx = 0;
+ foreach (var col in query.Columns)
+ {
+ ColumnNames.Add(col.Name);
+ if (idx > 1)
+ {
+ SumColumnNames.Add(col.Name);
+ GroupSumColumnNamnes.Add(col.Name);
+ }
+ idx++;
+ }
+
+ return query;
+ }
+
+ class TempClass
+ {
+ public long? Department_ID { get; set; }
+
+ public long? Customer_ID { get; set; }
+
+ public long? Goods_ID { get; set; }
+
+ public int Type { get; set; }
+
+ public Money? MainNumber { get; set; }
+
+ public Money? SecondNumber { get; set; }
+
+ public static void Register(DQueryDom root)
+ {
+ var q1 = GetSaleOutStore(true);
+ q1.UnionNext.Select = GetSaleOutStore(false);
+
+ root.RegisterQueryTable(typeof(TempClass), new string[] { "Department_ID", "Customer_ID", "Goods_ID", "Type", "MainNumber", "SecondNumber" }, q1);
+ }
+
+ static DQueryDom GetSaleOutStore(bool today)
+ {
+ var main = new JoinAlias(today + "M", typeof(SaleOutStore));
+ var detail = new JoinAlias(today + "D", typeof(SaleOutStore_Detail));
+ //var dept = new JoinAlias("dept", typeof(Department));
+ var query = new DQueryDom(main);
+ query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "SaleOutStore_ID"));
+ // query.From.AddJoin(JoinType.Left, new DQDmoSource(dept), DQCondition.EQ(main, "Department_ID", dept, "ID"));
+ query.Columns.Add(DQSelectColumn.Field("Department_ID", main));
+ query.Columns.Add(DQSelectColumn.Field("Customer_ID", main));
+ query.Columns.Add(DQSelectColumn.Field("SaleGoods_ID", detail));
+ query.Columns.Add(DQSelectColumn.Create(DQExpression.Value(today ? 1 : 2), "Type"));
+ query.Columns.Add(DQSelectColumn.Field("UnitNum", detail));
+ query.Columns.Add(DQSelectColumn.Field("SecondNumber", detail));
+ var timeRange = GetDateRange(today);
+ query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Domain_ID", DomainContext.Current.ID), DQCondition.GreaterThanOrEqual("BillState", 单据状态.已审核), DQCondition.Between("LoadTime", timeRange.Item1, timeRange.Item2)));
+ return query;
+ }
+
+ static Tuple GetDateRange(bool today)
+ {
+ if (today)
+ return new Tuple(DateTime.Today, DateTime.Today + new TimeSpan(23, 59, 59));
+ var d = (int)DateTime.Today.DayOfWeek;
+ if (DateTime.Today.DayOfWeek == DayOfWeek.Sunday)
+ d = 7;
+ var date = DateTime.Today.AddDays(-d);
+ return new Tuple(date.AddDays(-6), date);
+ }
+ }
+ }
+}
diff --git a/WebFolder/config/plugins/B3QingDaoWanFu.plugin b/WebFolder/config/plugins/B3QingDaoWanFu.plugin
index ed44383..f93629d 100644
--- a/WebFolder/config/plugins/B3QingDaoWanFu.plugin
+++ b/WebFolder/config/plugins/B3QingDaoWanFu.plugin
@@ -29,6 +29,7 @@
+
@@ -82,6 +83,7 @@
+