|
|
|
@ -0,0 +1,537 @@ |
|
|
|
using BWP.B3ButcherManage.BO; |
|
|
|
using BWP.B3Frameworks.BO.NamedValueTemplate; |
|
|
|
using BWP.B3Sale.BO; |
|
|
|
using BWP.B3Sale.Utils; |
|
|
|
using BWP.Web.Pages.B3Sale.Reports; |
|
|
|
using BWP.Web.Utils; |
|
|
|
using Forks.EnterpriseServices.DataForm; |
|
|
|
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 System.Web.UI.HtmlControls; |
|
|
|
using System.Web.UI.WebControls; |
|
|
|
using TSingSoft.WebControls2; |
|
|
|
using TSingSoft.WebControls2.DFGrids; |
|
|
|
using TSingSoft.WebPluginFramework; |
|
|
|
|
|
|
|
namespace BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse2_ |
|
|
|
{ |
|
|
|
class SaleOutStockAnalyse2 : B3SaleDFGridReportPage |
|
|
|
{ |
|
|
|
protected override string AccessRoleName |
|
|
|
{ |
|
|
|
get { return "B3ButcherManageToSale.报表分析.销售备货分析"; } |
|
|
|
} |
|
|
|
|
|
|
|
protected override string Caption |
|
|
|
{ |
|
|
|
get { return "销售备货分析(按产出)"; } |
|
|
|
} |
|
|
|
|
|
|
|
protected override string QueryOptionsTabName |
|
|
|
{ |
|
|
|
get { return string.Empty; } |
|
|
|
} |
|
|
|
|
|
|
|
readonly DFInfo mDFInfo = DFInfo.Get(typeof(SaleOutStore)); |
|
|
|
protected override void InitForm(System.Web.UI.HtmlControls.HtmlForm form) |
|
|
|
{ |
|
|
|
base.InitForm(form); |
|
|
|
mDFGrid.AllowRowGroup = true; |
|
|
|
mDFGrid.AllowColGroup = true; |
|
|
|
//mDFGrid.AfterFillDetailRow += (htmlRow, dataRow) =>
|
|
|
|
//{
|
|
|
|
// var row = (DFDataRow)dataRow;
|
|
|
|
// BuildCell(htmlRow, row);
|
|
|
|
// var diff = Convert.ToDecimal(row["备货差异|数量"] ?? 0);
|
|
|
|
// var ava = Convert.ToDecimal(row["可用|数量"] ?? 0);
|
|
|
|
// var color = string.Empty;
|
|
|
|
// if (onlyGoodsCheck.Checked)
|
|
|
|
// {
|
|
|
|
// if (ava < diff)
|
|
|
|
// color = "pink";
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// if (diff <= 0)
|
|
|
|
// color = "lightgreen";
|
|
|
|
// else if (ava >= diff)
|
|
|
|
// color = "lightblue";
|
|
|
|
// else if (ava < diff)
|
|
|
|
// color = "#FFA07A";
|
|
|
|
// }
|
|
|
|
// if (!string.IsNullOrEmpty(color))
|
|
|
|
// {
|
|
|
|
// var cIdx = onlyGoodsCheck.Checked ? 0 : 2;
|
|
|
|
// for (var i = cIdx; i < htmlRow.Cells.Count; i++)
|
|
|
|
// htmlRow.Cells[i].Style.Add("background-color", color);
|
|
|
|
// }
|
|
|
|
//};
|
|
|
|
} |
|
|
|
|
|
|
|
//private void BuildCell(HtmlTableRow htmlRow, DFDataRow dataRow)
|
|
|
|
//{
|
|
|
|
// var url = "~/B3ButcherManageToSale/Reports/SaleOutStockAnalyse_/ShowGoodsCustomer.aspx";
|
|
|
|
// url = AspUtil.AddParamToUrl(url, "minDate", mQueryContainer.GetControl<DFDateInput>("MinLoadTime").Text);
|
|
|
|
// url = AspUtil.AddParamToUrl(url, "maxDate", mQueryContainer.GetControl<DFDateInput>("MaxLoadTime").Text);
|
|
|
|
// url = AspUtil.AddParamToUrl(url, "Goods_ID", dataRow["Goods_ID"].ToString());
|
|
|
|
// if (dataRow["DeliverGoodsLine_ID"] != null)
|
|
|
|
// url = AspUtil.AddParamToUrl(url, "DeliverGoodsLine_ID", dataRow["DeliverGoodsLine_ID"].ToString());
|
|
|
|
// else
|
|
|
|
// url = AspUtil.AddParamToUrl(url, "DeliverGoodsLine_ID", mQueryContainer.GetControl<DFChoiceBox>("DeliverGoodsLine_ID").Value);
|
|
|
|
// url = AspUtil.AddParamToUrl(url, "BillState", billStateDp.SelectedValue);
|
|
|
|
// url = AspUtil.AddParamToUrl(url, "Sequence", mQueryContainer.GetControl<DFTextBox>("SequenceNumber").Text.Trim());
|
|
|
|
// url = WpfPageUrl.ToGlobal(url);
|
|
|
|
// var cIdx = onlyGoodsCheck.Checked ? 0 : 2;
|
|
|
|
// var cell = htmlRow.Cells[cIdx];
|
|
|
|
// cell.Attributes["onclick"] = "OpenUrlInTopTab('" + url + "','订单详情');";
|
|
|
|
// cell.Style.Add("color", "blue");
|
|
|
|
// cell.Style.Add("text-decoration", "underline");
|
|
|
|
// cell.Style.Add("cursor", "pointer");
|
|
|
|
//}
|
|
|
|
|
|
|
|
protected override void InitQueryPanel(WebControls.QueryPanel queryPanel) |
|
|
|
{ |
|
|
|
//base.InitQueryPanel(queryPanel);
|
|
|
|
queryPanel.ConditonPanel.EAdd(CreateDataRangePanel()); |
|
|
|
} |
|
|
|
|
|
|
|
DFDropDownList billStateDp; |
|
|
|
DFCheckBox onlyGoodsCheck; |
|
|
|
HLayoutPanel CreateDataRangePanel() |
|
|
|
{ |
|
|
|
var hPanel = new HLayoutPanel(); |
|
|
|
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("送货线路:")); |
|
|
|
hPanel.Add(QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["DeliverGoodsLine_ID"], mQueryContainer, "DeliverGoodsLine_ID", B3SaleDataSources.送货线路)); |
|
|
|
hPanel.Add(new LiteralControl("顺序:")); |
|
|
|
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.可销售存货)); |
|
|
|
|
|
|
|
hPanel.Add(new LiteralControl("单据状态:")); |
|
|
|
billStateDp = mQueryContainer.Add(hPanel.Add(new DFDropDownList() { Width = Unit.Pixel(80) }), "BillState"); |
|
|
|
billStateDp.Items.Add(""); |
|
|
|
billStateDp.Items.Add(new ListItem("未审核", "0")); |
|
|
|
billStateDp.Items.Add(new ListItem("已审核", "20")); |
|
|
|
billStateDp.SelectedIndex = 1; |
|
|
|
|
|
|
|
onlyGoodsCheck = hPanel.Add(new DFCheckBox() { TextAlign = TextAlign.Left, Text = "按存货" }); |
|
|
|
onlyGoodsCheck.InputAttributes.Add("style", "width:15px;height:15px;"); |
|
|
|
return hPanel; |
|
|
|
} |
|
|
|
|
|
|
|
//protected override void AddToolboxPanel(HLayoutPanel hbox)
|
|
|
|
//{
|
|
|
|
// if (EnablePrint)
|
|
|
|
// {
|
|
|
|
// var printPage = "SaleOutStockPrint.aspx?MinDate=" + "'+__QueryContainer.getControl('MinLoadTime').value+'&MaxDate=" + "'+__QueryContainer.getControl('MaxLoadTime').value+'&" + "'+__QueryContainer.getQueryString(['DeliverGoodsLine_ID','SequenceNumber','SaleGoods_ID','BillState'])+'";
|
|
|
|
// hbox.Add(new TSButton("预览")).OnClientClick = "preventEventDefault(event);Preview('" + printPage + "')";
|
|
|
|
// hbox.Add(new TSButton("打印")).OnClientClick = "preventEventDefault(event);Print('" + printPage + "')";
|
|
|
|
// }
|
|
|
|
// AddExcelExport(hbox);
|
|
|
|
//}
|
|
|
|
|
|
|
|
public override PagedDFDataTable GetPagedDFDataTable(QuerySettings settings) |
|
|
|
{ |
|
|
|
var line = mQueryContainer.GetControl<DFChoiceBox>("DeliverGoodsLine_ID").GetValues().Select(x => long.Parse(x)); |
|
|
|
var goodsIds = mQueryContainer.GetControl<DFChoiceBox>("SaleGoods_ID").GetValues().Select(x => long.Parse(x)); |
|
|
|
var minDate = mQueryContainer.GetControl<DFDateInput>("MinLoadTime").Value; |
|
|
|
var maxDate = mQueryContainer.GetControl<DFDateInput>("MaxLoadTime").Value; |
|
|
|
var sequenceInput = mQueryContainer.GetControl<DFTextBox>("SequenceNumber").Text.Trim(); |
|
|
|
short? billState = null; |
|
|
|
if (!string.IsNullOrEmpty(billStateDp.SelectedValue)) |
|
|
|
billState = short.Parse(billStateDp.SelectedValue); |
|
|
|
IEnumerable<long> seques = new List<long>(); |
|
|
|
if (!string.IsNullOrEmpty(sequenceInput)) |
|
|
|
seques = sequenceInput.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)); |
|
|
|
List<TempObj> data; |
|
|
|
List<MinObj> products; |
|
|
|
IEnumerable<MinObj> back = null; |
|
|
|
List<StockUpClass> stockInfo; |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
data = GetMainInfo(line, seques, goodsIds, minDate, maxDate, billState, session); |
|
|
|
products = GetInStoreNumber(goodsIds, minDate, maxDate, session); |
|
|
|
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 }); |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
list = data; |
|
|
|
|
|
|
|
foreach (var item in list) |
|
|
|
{ |
|
|
|
var first = products.FirstOrDefault(x => x.Goods_ID == item.Goods_ID); |
|
|
|
if (first == null) |
|
|
|
{ |
|
|
|
item.AvailableMain = 0; |
|
|
|
item.AvailableSecond = 0; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (item.StockDiffNumber > 0) |
|
|
|
{ |
|
|
|
item.AvailableMain = Math.Min(item.StockDiffNumber.Value, (first.MainNumber ?? 0).Value); |
|
|
|
first.MainNumber -= item.AvailableMain; |
|
|
|
} |
|
|
|
|
|
|
|
if (item.StockDiffSecondNumber > 0) |
|
|
|
{ |
|
|
|
item.AvailableSecond = Math.Min(item.StockDiffSecondNumber.Value, (first.SecondNumber ?? 0).Value); |
|
|
|
first.SecondNumber -= item.AvailableSecond; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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("线路"); |
|
|
|
} |
|
|
|
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?))); |
|
|
|
|
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("订货|数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("订货|数量"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("订货|单位", typeof(string))); |
|
|
|
ColumnNames.Add("订货|单位"); |
|
|
|
table.Data.Columns.Add(new DFCustomDataColumn("订货|辅数量", typeof(Money<decimal>?))); |
|
|
|
ColumnNames.Add("订货|辅数量"); |
|
|
|
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("已备|辅数量"); |
|
|
|
|
|
|
|
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) |
|
|
|
{ |
|
|
|
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.StockNumber; |
|
|
|
row["已备|辅数量"] = item.StockSecondNumber; |
|
|
|
row["备货差异|数量"] = item.StockDiffNumber; |
|
|
|
row["备货差异|辅数量"] = item.StockDiffSecondNumber; |
|
|
|
row["可用|数量"] = item.AvailableMain; |
|
|
|
row["可用|辅数量"] = item.AvailableSecond; |
|
|
|
} |
|
|
|
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.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); |
|
|
|
|
|
|
|
return table; |
|
|
|
} |
|
|
|
|
|
|
|
List<MinObj> GetInStoreNumber(IEnumerable<long> goodsIDs, DateTime? start, DateTime? end, IDmoSession session) |
|
|
|
{ |
|
|
|
var main = new JoinAlias(typeof(Output)); |
|
|
|
var detail = new JoinAlias(typeof(Output_Detail)); |
|
|
|
var config = new JoinAlias(typeof(GoodsViewConfig)); |
|
|
|
var query = new DQueryDom(main); |
|
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "Output_ID")); |
|
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(config), DQCondition.EQ(detail, "Goods_ID", config, "Goods_ID")); |
|
|
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_ID", detail)); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum(detail, "Number")); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum(detail, "SecondNumber")); |
|
|
|
query.GroupBy.Expressions.Add(DQExpression.Field(detail, "Goods_ID")); |
|
|
|
|
|
|
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.InEQ("BillState", 单据状态.已作废)); |
|
|
|
if (start.HasValue) |
|
|
|
query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual("Date", start)); |
|
|
|
if (start.HasValue) |
|
|
|
query.Where.Conditions.Add(DQCondition.LessThanOrEqual("Date", end)); |
|
|
|
if (goodsIDs.Any()) |
|
|
|
query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "Goods_ID"), goodsIDs.Select(x => DQExpression.Value(x)).ToArray())); |
|
|
|
var list = new List<MinObj>(); |
|
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
list.Add(new MinObj |
|
|
|
{ |
|
|
|
Goods_ID = (long)reader[0], |
|
|
|
MainNumber = (Money<decimal>?)reader[1], |
|
|
|
SecondNumber = (Money<decimal>?)reader[2] |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
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(IEnumerable<long> line, IEnumerable<long> seques, IEnumerable<long> goodsIDs, DateTime? minDate, DateTime? maxDate, short? billStateDp, 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, line, seques, goodsIDs, minDate, maxDate, billStateDp); |
|
|
|
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)); |
|
|
|
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)); |
|
|
|
if (line.Any()) |
|
|
|
query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(main, "DeliverGoodsLine_ID"), line.Select(x => DQExpression.Value(x)).ToArray())); |
|
|
|
else |
|
|
|
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())); |
|
|
|
|
|
|
|
if (billStateDp.HasValue) |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ(main, "BillState", billStateDp)); |
|
|
|
else |
|
|
|
query.Where.Conditions.Add(DQCondition.InEQ(main, "BillState", 单据状态.已作废)); |
|
|
|
if (seques.Any()) |
|
|
|
query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(main, "SequenceNumber"), seques.Select(x => DQExpression.Value(x)).ToArray())); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ(main, "TakeGoods_Type", 配送方式.公司配送)); |
|
|
|
|
|
|
|
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]; |
|
|
|
|
|
|
|
list.Add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
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, IEnumerable<long> line, IEnumerable<long> seques, IEnumerable<long> goodsIDs, DateTime? minDate, DateTime? maxDate, short? billStateDp) |
|
|
|
{ |
|
|
|
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)); |
|
|
|
if (line.Any()) |
|
|
|
query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(main, "DeliverGoodsLine_ID"), line.Select(x => DQExpression.Value(x)).ToArray())); |
|
|
|
else |
|
|
|
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())); |
|
|
|
if (billStateDp.HasValue) |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ(main, "BillState", billStateDp)); |
|
|
|
else |
|
|
|
query.Where.Conditions.Add(DQCondition.InEQ(main, "BillState", 单据状态.已作废)); |
|
|
|
if (seques.Any()) |
|
|
|
query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(main, "SequenceNumber"), seques.Select(x => DQExpression.Value(x)).ToArray())); |
|
|
|
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 Money<decimal>? ProductMain { get; set; } |
|
|
|
public Money<decimal>? ProductSecond { get; set; } |
|
|
|
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 |
|
|
|
{ |
|
|
|
public long Goods_ID { get; set; } |
|
|
|
public Money<decimal>? MainNumber { get; set; } |
|
|
|
public Money<decimal>? SecondNumber { get; set; } |
|
|
|
} |
|
|
|
} |
|
|
|
} |