|
|
|
@ -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<string, string> fileDic = new Dictionary<string, string>(); |
|
|
|
public override PagedDFDataTable GetPagedDFDataTable(QuerySettings settings) |
|
|
|
{ |
|
|
|
var line = mQueryContainer.GetControl<DFChoiceBox>("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<TempObj> data; |
|
|
|
IEnumerable<TempObj> data; |
|
|
|
List<MinObj> products; |
|
|
|
IEnumerable<MinObj> back = null; |
|
|
|
List<StockUpClass> 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<TempObj>(); |
|
|
|
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<decimal>?))); |
|
|
|
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<decimal>?))); |
|
|
|
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<decimal>?))); |
|
|
|
ColumnNames.Add("产出|数量"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("产出|辅数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("产出|辅数量"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("差异|数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("差异|数量"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("差异|辅数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("差异|辅数量"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("已备|数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("已备|数量"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("已备|辅数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("已备|辅数量"); |
|
|
|
|
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("备货差异|数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("备货差异|数量"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("备货差异|辅数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("备货差异|辅数量"); |
|
|
|
|
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("可用|数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("可用|数量"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("可用|辅数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("可用|辅数量"); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var item in list) |
|
|
|
fileDic.Add("订货|辅单位", "SecondUnit"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("产出|数量", typeof(Money<decimal>?))); |
|
|
|
fileDic.Add("产出|数量", "ProductMain"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("产出|辅数量", typeof(Money<decimal>?))); |
|
|
|
fileDic.Add("产出|辅数量", "ProductSecond"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("差异|数量", typeof(Money<decimal>?))); |
|
|
|
fileDic.Add("差异|数量", "ProductMainDiff"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("差异|辅数量", typeof(Money<decimal>?))); |
|
|
|
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<TempObj> 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<long> ids) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(DeliverGoodsLine))); |
|
|
|
@ -390,102 +347,53 @@ namespace BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse2_ |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
static List<StockUpClass> GetStockInfo(IEnumerable<long> 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<StockUpClass>(); |
|
|
|
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<TempObj> GetMainInfo(long? seque, IEnumerable<long> 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<TempObj>(); |
|
|
|
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<decimal>?)reader[7]; |
|
|
|
entity.OrderSecond = (Money<decimal>?)reader[8]; |
|
|
|
entity.StockNumber = (Money<decimal>?)reader[9]; |
|
|
|
entity.StockSecondNumber = (Money<decimal>?)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<decimal>?)reader[5]; |
|
|
|
entity.OrderSecond = (Money<decimal>?)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<decimal>? StockSecondNumber { get; set; } |
|
|
|
public Money<decimal>? StockNumber { get; set; } |
|
|
|
|
|
|
|
public static void Register(DQueryDom root, long? seque, IEnumerable<long> 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<decimal>? ProductMain { get; set; } |
|
|
|
public Money<decimal>? ProductSecond { get; set; } |
|
|
|
public Money<decimal>? ProductMainDiff { get; set; } |
|
|
|
public Money<decimal>? ProductSecondDiff { get; set; } |
|
|
|
public Money<decimal>? ProductMainDiff |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
if (OrderMain == null) |
|
|
|
return null; |
|
|
|
var diff = OrderMain - (ProductMain ?? 0).Value; |
|
|
|
if (diff > 0) |
|
|
|
return diff; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
public Money<decimal>? ProductSecondDiff |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
if (OrderSecond == null) |
|
|
|
return null; |
|
|
|
var diff = OrderSecond - (ProductSecond ?? 0).Value; |
|
|
|
if (diff > 0) |
|
|
|
return diff; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
public Money<decimal>? OrderMain { get; set; } |
|
|
|
public Money<decimal>? OrderSecond { get; set; } |
|
|
|
public Money<decimal>? StockNumber { get; set; } |
|
|
|
public Money<decimal>? StockSecondNumber { get; set; } |
|
|
|
public Money<decimal> StockDiffNumber { get { return (OrderMain ?? 0) - (StockNumber ?? 0); } } |
|
|
|
public Money<decimal> StockDiffSecondNumber { get { return (OrderSecond ?? 0) - (StockSecondNumber ?? 0); } } |
|
|
|
public Money<decimal>? AvailableMain { get; set; } |
|
|
|
public Money<decimal>? AvailableSecond { get; set; } |
|
|
|
} |
|
|
|
|
|
|
|
class MinObj |
|
|
|
|