From 1580952c51097ca10f039f3b2e8186fb51b78723 Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Fri, 19 Oct 2018 14:03:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E5=B7=AE=E5=BC=82=E5=88=86?= =?UTF-8?q?=E6=9E=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SaleOutStockAnalyse2.cs | 428 +++++++----------- 1 file changed, 157 insertions(+), 271 deletions(-) diff --git a/B3ButcherManageToSale.Web/Pages/B3ButcherManageToSale/Reports/SaleOutStockAnalyse2_/SaleOutStockAnalyse2.cs b/B3ButcherManageToSale.Web/Pages/B3ButcherManageToSale/Reports/SaleOutStockAnalyse2_/SaleOutStockAnalyse2.cs index ef762af..346d89c 100644 --- a/B3ButcherManageToSale.Web/Pages/B3ButcherManageToSale/Reports/SaleOutStockAnalyse2_/SaleOutStockAnalyse2.cs +++ b/B3ButcherManageToSale.Web/Pages/B3ButcherManageToSale/Reports/SaleOutStockAnalyse2_/SaleOutStockAnalyse2.cs @@ -99,13 +99,42 @@ namespace BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse2_ protected override void InitQueryPanel(WebControls.QueryPanel queryPanel) { //base.InitQueryPanel(queryPanel); + //queryPanel.ConditonPanel.EAdd(AddQueryBtn()); + queryPanel.ButtonsPanel.Controls.Clear(); + queryPanel.ButtonsPanel.Controls.Add(new RedirectTSButton("清除条件")); queryPanel.ConditonPanel.EAdd(CreateDataRangePanel()); } - DFCheckBox onlyGoodsCheck; + void AddQueryBtn(HLayoutPanel hPanel) + { + hPanel.Add(new TSButton("客户自提", delegate + { + StartQuery(配送方式.客户自运.Value); + })); + + hPanel.Add(new TSButton("公司配送", delegate + { + StartQuery(配送方式.公司配送.Value); + })).Style.Add("margin", "0px 50px 0px 10px"); + } + + int TakeGoodsType + { + get + { + return (int)ViewState["TakeGoodsType"]; + } + set + { + ViewState["TakeGoodsType"] = value; + } + } + + //DFCheckBox onlyGoodsCheck; HLayoutPanel CreateDataRangePanel() { var hPanel = new HLayoutPanel(); + AddQueryBtn(hPanel); hPanel.Add(new LiteralControl("发货日期:")); hPanel.Add(QueryCreator.DateRange(mDFInfo.Fields["LoadTime"], mQueryContainer, "MinLoadTime", "MaxLoadTime", DateTime.Today, DateTime.Today + new TimeSpan(23, 59, 29))); hPanel.Add(new LiteralControl("送货线路:")); @@ -114,9 +143,6 @@ namespace BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse2_ hPanel.Add(mQueryContainer.Add(QueryCreator.DFTextBox(mDFInfo.Fields["Remark"]), "SequenceNumber")); hPanel.Add(new LiteralControl("存货:")); hPanel.Add(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["AccountingUnit_ID"], mQueryContainer, "SaleGoods_ID", B3SaleDataSources.可销售存货)); - - onlyGoodsCheck = hPanel.Add(new DFCheckBox() { TextAlign = TextAlign.Left, Text = "按存货" }); - onlyGoodsCheck.InputAttributes.Add("style", "width:15px;height:15px;"); return hPanel; } @@ -131,6 +157,30 @@ namespace BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse2_ // AddExcelExport(hbox); //} + void AddQueryButtons(VLayoutPanel vbox) + { + Panel buttonPanel = vbox.Add(new Panel()); + buttonPanel.Controls.Add(new RedirectTSButton("清除条件")); + } + + + //protected override void AddQueryButtons(VLayoutPanel vbox) + //{ + // Panel buttonPanel = vbox.Add(new Panel(), new VLayoutOption(HorizontalAlign.Left)); + // buttonPanel.Controls.Add(new RedirectTSButton("清除条件")); + //} + + void StartQuery(int type) + { + TakeGoodsType = type; + mDFGrid.SortField = null; + mDFGrid.SortDirection = SortDirection.Ascending; + mDFGrid.CurrentPage = 0; + mDFGrid.DataBind(); + mQueryControls.SaveLast(); + } + + Dictionary fileDic = new Dictionary(); public override PagedDFDataTable GetPagedDFDataTable(QuerySettings settings) { var line = mQueryContainer.GetControl("DeliverGoodsLine_ID").GetValues().Select(x => long.Parse(x)); @@ -146,10 +196,8 @@ namespace BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse2_ if (arr.Any()) maxSeque = arr.Max(); } - List data; + IEnumerable data; List products; - IEnumerable back = null; - List stockInfo = null; using (var session = Dmo.NewSession()) { if (line.Any()) @@ -161,189 +209,98 @@ namespace BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse2_ data = GetMainInfo(maxSeque, goodsIds, minDate, maxDate, session); products = GetInStoreNumber(goodsIds, minDate, maxDate, session); - if (!onlyGoodsCheck.Checked) - stockInfo = GetStockInfo(goodsIds, minDate, maxDate, session); - }; - if (onlyGoodsCheck.Checked) - back = products.Select(item => new MinObj { Goods_ID = item.Goods_ID, MainNumber = item.MainNumber, SecondNumber = item.SecondNumber }); - else - { - foreach (var g in stockInfo.GroupBy(x => x.Goods_ID)) - { - var first = products.FirstOrDefault(x => x.Goods_ID == g.Key); - if (first != null) - { - first.MainNumber = (first.MainNumber ?? 0) - g.Sum(x => (x.StockNumber ?? 0).Value); - first.SecondNumber = (first.SecondNumber ?? 0) - g.Sum(x => (x.StockSecondNumber ?? 0).Value); - } - } - } - - var list = new List(); - if (onlyGoodsCheck.Checked) - { - foreach (var g in data.GroupBy(x => x.Goods_ID)) - { - var first = g.First(); - var bkFirst = back.FirstOrDefault(x => x.Goods_ID == g.Key); - var entity = new TempObj(); - entity.Goods_ID = first.Goods_ID; - entity.Goods_Name = first.Goods_Name; - entity.Unit = first.Unit; - entity.SecondUnit = first.SecondUnit; - entity.OrderMain = g.Sum(x => (x.OrderMain ?? 0).Value); - entity.OrderSecond = g.Sum(x => (x.OrderSecond ?? 0).Value); - entity.StockNumber = g.Sum(x => (x.StockNumber ?? 0).Value); - entity.StockSecondNumber = g.Sum(x => (x.StockSecondNumber ?? 0).Value); - if (bkFirst != null) - { - entity.ProductMain = bkFirst.MainNumber; - entity.ProductSecond = bkFirst.SecondNumber; - } - list.Add(entity); - var arr = list.Where(x => x.Goods_ID == g.Key); - entity.ProductMainDiff = arr.Sum(x => (x.OrderMain ?? 0).Value) - (entity.ProductMain ?? 0); - if (entity.ProductMainDiff <= 0) - entity.ProductMainDiff = null; - entity.ProductSecondDiff = arr.Sum(x => (x.OrderSecond ?? 0).Value) - (entity.ProductSecond ?? 0); - if (entity.ProductSecondDiff <= 0) - entity.ProductSecondDiff = null; - } } - else - list = data; - foreach (var item in list) + foreach (var item in data) { var first = products.FirstOrDefault(x => x.Goods_ID == item.Goods_ID); - if (first == null) + if (first != null) { - item.AvailableMain = 0; - item.AvailableSecond = 0; - } - else - { - if (item.StockDiffNumber > 0) + if (item.TakeGoods_Type == 配送方式.客户自运) { - item.AvailableMain = Math.Min(item.StockDiffNumber.Value, (first.MainNumber ?? 0).Value); - first.MainNumber -= item.AvailableMain; - } + item.ProductMain = Math.Min((item.OrderMain ?? 0).Value, (first.MainNumber ?? 0).Value); + first.MainNumber -= item.ProductMain; - if (item.StockDiffSecondNumber > 0) + item.ProductSecond = Math.Min((item.OrderSecond ?? 0).Value, (first.SecondNumber ?? 0).Value); + first.SecondNumber -= item.ProductSecond; + } + else { - item.AvailableSecond = Math.Min(item.StockDiffSecondNumber.Value, (first.SecondNumber ?? 0).Value); - first.SecondNumber -= item.AvailableSecond; + item.ProductMain = first.MainNumber; + item.ProductSecond = first.SecondNumber; } + if (item.ProductMain == 0) + item.ProductMain = null; + if (item.ProductSecond == 0) + item.ProductSecond = null; } } - - var table = new PagedDFDataTable(list.Count, new DFDataTable()); - if (!onlyGoodsCheck.Checked) - { - table.Data.Columns.Add(new DFCustomDataColumn("顺序号", typeof(long?))); - ColumnNames.Add("顺序号"); - table.Data.Columns.Add(new DFCustomDataColumn("线路", typeof(string))); - ColumnNames.Add("线路"); - } + data = data.Where(x => x.TakeGoods_Type == TakeGoodsType); + var table = new PagedDFDataTable(data.Count(), new DFDataTable()); table.Data.Columns.Add(new DFCustomDataColumn("存货", typeof(string))); - ColumnNames.Add("存货"); - table.Data.Columns.Add(new DFCustomDataColumn("Goods_ID", typeof(long))); - table.Data.Columns.Add(new DFCustomDataColumn("DeliverGoodsLine_ID", typeof(long?))); + fileDic.Add("存货", "Goods_Name"); + //table.Data.Columns.Add(new DFCustomDataColumn("Goods_ID", typeof(long))); table.Data.Columns.Add(new DFCustomDataColumn("订货|数量", typeof(Money?))); - ColumnNames.Add("订货|数量"); + fileDic.Add("订货|数量", "OrderMain"); table.Data.Columns.Add(new DFCustomDataColumn("订货|单位", typeof(string))); - ColumnNames.Add("订货|单位"); + fileDic.Add("订货|单位", "Unit"); table.Data.Columns.Add(new DFCustomDataColumn("订货|辅数量", typeof(Money?))); - ColumnNames.Add("订货|辅数量"); + fileDic.Add("订货|辅数量", "OrderSecond"); table.Data.Columns.Add(new DFCustomDataColumn("订货|辅单位", typeof(string))); - ColumnNames.Add("订货|辅单位"); - - if (onlyGoodsCheck.Checked) - { - table.Data.Columns.Add(new DFCustomDataColumn("产出|数量", typeof(Money?))); - ColumnNames.Add("产出|数量"); - table.Data.Columns.Add(new DFCustomDataColumn("产出|辅数量", typeof(Money?))); - ColumnNames.Add("产出|辅数量"); - table.Data.Columns.Add(new DFCustomDataColumn("差异|数量", typeof(Money?))); - ColumnNames.Add("差异|数量"); - table.Data.Columns.Add(new DFCustomDataColumn("差异|辅数量", typeof(Money?))); - ColumnNames.Add("差异|辅数量"); - } - else - { - table.Data.Columns.Add(new DFCustomDataColumn("已备|数量", typeof(Money?))); - ColumnNames.Add("已备|数量"); - table.Data.Columns.Add(new DFCustomDataColumn("已备|辅数量", typeof(Money?))); - ColumnNames.Add("已备|辅数量"); - - table.Data.Columns.Add(new DFCustomDataColumn("备货差异|数量", typeof(Money?))); - ColumnNames.Add("备货差异|数量"); - table.Data.Columns.Add(new DFCustomDataColumn("备货差异|辅数量", typeof(Money?))); - ColumnNames.Add("备货差异|辅数量"); - - table.Data.Columns.Add(new DFCustomDataColumn("可用|数量", typeof(Money?))); - ColumnNames.Add("可用|数量"); - table.Data.Columns.Add(new DFCustomDataColumn("可用|辅数量", typeof(Money?))); - ColumnNames.Add("可用|辅数量"); - } - - foreach (var item in list) + fileDic.Add("订货|辅单位", "SecondUnit"); + table.Data.Columns.Add(new DFCustomDataColumn("产出|数量", typeof(Money?))); + fileDic.Add("产出|数量", "ProductMain"); + table.Data.Columns.Add(new DFCustomDataColumn("产出|辅数量", typeof(Money?))); + fileDic.Add("产出|辅数量", "ProductSecond"); + table.Data.Columns.Add(new DFCustomDataColumn("差异|数量", typeof(Money?))); + fileDic.Add("差异|数量", "ProductMainDiff"); + table.Data.Columns.Add(new DFCustomDataColumn("差异|辅数量", typeof(Money?))); + fileDic.Add("差异|辅数量", "ProductSecondDiff"); + + SortGrid(ref data); + + foreach (var item in fileDic) + ColumnNames.Add(item.Key); + var type = typeof(TempObj); + foreach (var item in data) { var row = table.Data.Rows.NewRow(); - - if (!onlyGoodsCheck.Checked) - { - row["顺序号"] = item.SequenceNumber; - row["线路"] = item.DeliverGoodsLine_Name; - } - row["Goods_ID"] = item.Goods_ID; - row["DeliverGoodsLine_ID"] = item.DeliverGoodsLine_ID; - row["存货"] = item.Goods_Name; - row["订货|数量"] = item.OrderMain; - row["订货|单位"] = item.Unit; - row["订货|辅数量"] = item.OrderSecond; - row["订货|辅单位"] = item.SecondUnit; - if (onlyGoodsCheck.Checked) - { - row["产出|数量"] = item.ProductMain; - row["产出|辅数量"] = item.ProductSecond; - row["差异|数量"] = item.ProductMainDiff; - row["差异|辅数量"] = item.ProductSecondDiff; - } - else - { - row["已备|数量"] = item.StockNumber; - row["已备|辅数量"] = item.StockSecondNumber; - row["备货差异|数量"] = item.StockDiffNumber; - row["备货差异|辅数量"] = item.StockDiffSecondNumber; - row["可用|数量"] = item.AvailableMain; - row["可用|辅数量"] = item.AvailableSecond; - } + //row["Goods_ID"] = item.Goods_ID; + foreach (var pair in fileDic) + row[pair.Key] = type.GetProperty(pair.Value).GetValue(item, null); + //row["存货"] = item.Goods_Name; + //row["订货|数量"] = item.OrderMain; + //row["订货|单位"] = item.Unit; + //row["订货|辅数量"] = item.OrderSecond; + //row["订货|辅单位"] = item.SecondUnit; + //row["产出|数量"] = item.ProductMain; + //row["产出|辅数量"] = item.ProductSecond; + //row["差异|数量"] = item.ProductMainDiff; + //row["差异|辅数量"] = item.ProductSecondDiff; } SumColumnNames.Add("订货|数量"); - table.Data.SumRow["订货|数量"] = list.Sum(x => (x.OrderMain ?? 0).Value); - table.Data.SumRow["订货|辅数量"] = list.Sum(x => (x.OrderSecond ?? 0).Value); - if (onlyGoodsCheck.Checked) - { - table.Data.SumRow["产出|数量"] = list.Sum(x => (x.ProductMain ?? 0).Value); - table.Data.SumRow["产出|辅数量"] = list.Sum(x => (x.ProductSecond ?? 0).Value); - table.Data.SumRow["差异|数量"] = list.Sum(x => (x.ProductMainDiff ?? 0).Value); - table.Data.SumRow["差异|辅数量"] = list.Sum(x => (x.ProductSecondDiff ?? 0).Value); - } - else - { - table.Data.SumRow["已备|数量"] = list.Sum(x => (x.StockNumber ?? 0).Value); - table.Data.SumRow["已备|辅数量"] = list.Sum(x => (x.StockSecondNumber ?? 0).Value); - table.Data.SumRow["备货差异|数量"] = list.Sum(x => x.StockDiffNumber.Value); - table.Data.SumRow["备货差异|辅数量"] = list.Sum(x => x.StockDiffSecondNumber.Value); - table.Data.SumRow["可用|数量"] = list.Sum(x => (x.AvailableMain ?? 0).Value); - table.Data.SumRow["可用|辅数量"] = list.Sum(x => (x.AvailableSecond ?? 0).Value); - } + table.Data.SumRow["订货|数量"] = data.Sum(x => (x.OrderMain ?? 0).Value); + table.Data.SumRow["订货|辅数量"] = data.Sum(x => (x.OrderSecond ?? 0).Value); + table.Data.SumRow["产出|数量"] = data.Sum(x => (x.ProductMain ?? 0).Value); + table.Data.SumRow["产出|辅数量"] = data.Sum(x => (x.ProductSecond ?? 0).Value); + table.Data.SumRow["差异|数量"] = data.Sum(x => (x.ProductMainDiff ?? 0).Value); + table.Data.SumRow["差异|辅数量"] = data.Sum(x => (x.ProductSecondDiff ?? 0).Value); return table; } + private void SortGrid(ref IEnumerable data) + { + if (string.IsNullOrEmpty(mDFGrid.SortField)) + return; + var t = typeof(TempObj); + if (mDFGrid.SortDirection == SortDirection.Ascending) + data = data.OrderBy(x => t.GetProperty(fileDic[mDFGrid.SortField]).GetValue(x, null)); + else + data = data.OrderByDescending(x => t.GetProperty(fileDic[mDFGrid.SortField]).GetValue(x, null)); + } + long? GetMaxLine(IDmoSession session, IEnumerable ids) { var query = new DQueryDom(new JoinAlias(typeof(DeliverGoodsLine))); @@ -390,102 +347,53 @@ namespace BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse2_ return list; } - static List GetStockInfo(IEnumerable goodsIDs, DateTime? minDate, DateTime? maxDate, IDmoSession session) - { - var main = new JoinAlias("_tMain", typeof(SaleOutStore)); - var detail = new JoinAlias("_tDetail", typeof(SaleOutStore_Detail)); - var stockUp = new JoinAlias(typeof(StockUpDetail)); - var query = new DQueryDom(stockUp); - query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(detail, "ID", stockUp, "DetailID")); - query.From.AddJoin(JoinType.Left, new DQDmoSource(main), DQCondition.EQ(main, "ID", detail, "SaleOutStore_ID")); - query.Columns.Add(DQSelectColumn.Field("SaleGoods_ID", detail)); - query.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(stockUp, "SecondNumber")), "备货辅数量")); - query.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(stockUp, "UnitNumber")), "备货报价数量")); - - query.GroupBy.Expressions.Add(DQExpression.Field(detail, "SaleGoods_ID")); - if (minDate.HasValue) - query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual(main, "LoadTime", minDate.Value)); - if (maxDate.HasValue) - query.Where.Conditions.Add(DQCondition.LessThanOrEqual(main, "LoadTime", maxDate.Value)); - if (goodsIDs.Any()) - query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "SaleGoods_ID"), goodsIDs.Select(x => DQExpression.Value(x)).ToArray())); - query.Where.Conditions.Add(DQCondition.InEQ(main, "BillState", 单据状态.已作废)); - var list = new List(); - using (var reader = session.ExecuteReader(query)) - { - while (reader.Read()) - { - var entity = new StockUpClass(); - entity.Goods_ID = (long)reader[0]; - entity.StockSecondNumber = (decimal?)reader[1]; - entity.StockNumber = (decimal?)reader[2]; - list.Add(entity); - } - } - return list; - } - List GetMainInfo(long? seque, IEnumerable goodsIDs, DateTime? minDate, DateTime? maxDate, IDmoSession session) { var main = new JoinAlias("_m", typeof(SaleOutStore)); var detail = new JoinAlias("_d", typeof(SaleOutStore_Detail)); var config = new JoinAlias("_g1", typeof(GoodsViewConfig)); var customer = new JoinAlias("_c1", typeof(CustomerViewConfig)); - var temp = new JoinAlias(typeof(StockUpClass)); var query = new DQueryDom(main); - StockUpClass.Register(query, seque, goodsIDs, minDate, maxDate); query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "SaleOutStore_ID")); query.From.AddJoin(JoinType.Inner, new DQDmoSource(config), DQCondition.EQ(config, "Goods_ID", detail, "SaleGoods_ID")); query.From.AddJoin(JoinType.Left, new DQDmoSource(customer), DQCondition.EQ(main, "Customer_ID", customer, "Customer_ID")); - query.From.AddJoin(JoinType.Left, new DQDmoSource(temp), DQCondition.EQ(detail, "ID", temp, "DetailID")); - query.Columns.Add(DQSelectColumn.Field("SequenceNumber")); - query.Columns.Add(DQSelectColumn.Field("DeliverGoodsLine_ID")); - query.Columns.Add(DQSelectColumn.Field("DeliverGoodsLine_Name")); query.Columns.Add(DQSelectColumn.Field("SaleGoods_ID", detail)); query.Columns.Add(DQSelectColumn.Field("Goods_Name", detail)); query.Columns.Add(DQSelectColumn.Field("Unit", detail)); query.Columns.Add(DQSelectColumn.Field("Goods_SecondUnit", detail)); + query.Columns.Add(DQSelectColumn.Field("TakeGoods_Type")); foreach (var c in query.Columns) query.GroupBy.Expressions.Add(c.Expression); query.Columns.Add(DQSelectColumn.Sum(detail, "UnitNum")); query.Columns.Add(DQSelectColumn.Sum(detail, "SecondNumber")); - query.Columns.Add(DQSelectColumn.Sum(temp, "StockNumber")); - query.Columns.Add(DQSelectColumn.Sum(temp, "StockSecondNumber")); - - query.OrderBy.Expressions.Add(DQOrderByExpression.Create("SequenceNumber")); query.Where.Conditions.Add(DQCondition.IsNull(DQExpression.Field(customer, "Customer_ID"))); if (minDate.HasValue) query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual(main, "LoadTime", minDate.Value)); if (maxDate.HasValue) query.Where.Conditions.Add(DQCondition.LessThanOrEqual(main, "LoadTime", maxDate.Value)); - query.Where.Conditions.Add(DQCondition.IsNotNull(DQExpression.Field(main, "DeliverGoodsLine_ID"))); if (goodsIDs.Any()) query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "SaleGoods_ID"), goodsIDs.Select(x => DQExpression.Value(x)).ToArray())); query.Where.Conditions.Add(DQCondition.InEQ(main, "BillState", 单据状态.已作废)); if (seque.HasValue) query.Where.Conditions.Add(DQCondition.LessThanOrEqual(main, "SequenceNumber", seque)); - query.Where.Conditions.Add(DQCondition.EQ(main, "TakeGoods_Type", 配送方式.公司配送)); - + query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(main, "TakeGoods_Type"), DQExpression.Value(配送方式.公司配送), DQExpression.Value(配送方式.客户自运))); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("TakeGoods_Type", true)); var list = new List(); using (var reader = session.ExecuteReader(query)) { while (reader.Read()) { var entity = new TempObj(); - entity.SequenceNumber = (long?)reader[0]; - entity.DeliverGoodsLine_ID = (long?)reader[1]; - entity.DeliverGoodsLine_Name = (string)reader[2]; - entity.Goods_ID = (long)reader[3]; - entity.Goods_Name = (string)reader[4]; - entity.Unit = (string)reader[5]; - entity.SecondUnit = (string)reader[6]; - entity.OrderMain = (Money?)reader[7]; - entity.OrderSecond = (Money?)reader[8]; - entity.StockNumber = (Money?)reader[9]; - entity.StockSecondNumber = (Money?)reader[10]; + entity.Goods_ID = (long)reader[0]; + entity.Goods_Name = (string)reader[1]; + entity.Unit = (string)reader[2]; + entity.SecondUnit = (string)reader[3]; + entity.TakeGoods_Type = (NamedValue<配送方式>)reader[4]; + entity.OrderMain = (Money?)reader[5]; + entity.OrderSecond = (Money?)reader[6]; list.Add(entity); } @@ -493,63 +401,41 @@ namespace BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse2_ return list; } - public class StockUpClass - { - public long Goods_ID { get; set; } - public long DetailID { get; set; } - public Money? StockSecondNumber { get; set; } - public Money? StockNumber { get; set; } - - public static void Register(DQueryDom root, long? seque, IEnumerable goodsIDs, DateTime? minDate, DateTime? maxDate) - { - var main = new JoinAlias("_tMain", typeof(SaleOutStore)); - var detail = new JoinAlias("_tDetail", typeof(SaleOutStore_Detail)); - var stockUp = new JoinAlias(typeof(StockUpDetail)); - var query = new DQueryDom(stockUp); - query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(detail, "ID", stockUp, "DetailID")); - query.From.AddJoin(JoinType.Left, new DQDmoSource(main), DQCondition.EQ(main, "ID", detail, "SaleOutStore_ID")); - query.Columns.Add(DQSelectColumn.Field("ID", detail)); - query.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(stockUp, "SecondNumber")), "StockSecondNumber")); - query.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(stockUp, "UnitNumber")), "StockNumber")); - - query.GroupBy.Expressions.Add(DQExpression.Field(detail, "ID")); - if (minDate.HasValue) - query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual(main, "LoadTime", minDate.Value)); - if (maxDate.HasValue) - query.Where.Conditions.Add(DQCondition.LessThanOrEqual(main, "LoadTime", maxDate.Value)); - query.Where.Conditions.Add(DQCondition.IsNotNull(DQExpression.Field(main, "DeliverGoodsLine_ID"))); - if (goodsIDs.Any()) - query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "SaleGoods_ID"), goodsIDs.Select(x => DQExpression.Value(x)).ToArray())); - query.Where.Conditions.Add(DQCondition.InEQ(main, "BillState", 单据状态.已作废)); - if (seque.HasValue) - query.Where.Conditions.Add(DQCondition.LessThanOrEqual(main, "SequenceNumber", seque)); - query.Where.Conditions.Add(DQCondition.EQ(main, "TakeGoods_Type", 配送方式.公司配送)); - - root.RegisterQueryTable(typeof(StockUpClass), new string[] { "DetailID", "StockSecondNumber", "StockNumber" }, query); - } - } - class TempObj { - public long? SequenceNumber { get; set; } - public long? DeliverGoodsLine_ID { get; set; } - public string DeliverGoodsLine_Name { get; set; } public long Goods_ID { get; set; } public string Goods_Name { get; set; } public string Unit { get; set; } public string SecondUnit { get; set; } + public NamedValue<配送方式>? TakeGoods_Type { get; set; } public Money? ProductMain { get; set; } public Money? ProductSecond { get; set; } - public Money? ProductMainDiff { get; set; } - public Money? ProductSecondDiff { get; set; } + public Money? ProductMainDiff + { + get + { + if (OrderMain == null) + return null; + var diff = OrderMain - (ProductMain ?? 0).Value; + if (diff > 0) + return diff; + return null; + } + } + public Money? ProductSecondDiff + { + get + { + if (OrderSecond == null) + return null; + var diff = OrderSecond - (ProductSecond ?? 0).Value; + if (diff > 0) + return diff; + return null; + } + } public Money? OrderMain { get; set; } public Money? OrderSecond { get; set; } - public Money? StockNumber { get; set; } - public Money? StockSecondNumber { get; set; } - public Money StockDiffNumber { get { return (OrderMain ?? 0) - (StockNumber ?? 0); } } - public Money StockDiffSecondNumber { get { return (OrderSecond ?? 0) - (StockSecondNumber ?? 0); } } - public Money? AvailableMain { get; set; } - public Money? AvailableSecond { get; set; } } class MinObj