|
|
@ -0,0 +1,369 @@ |
|
|
|
|
|
using BWP.B3Frameworks.Utils; |
|
|
|
|
|
using BWP.B3Sale.BO; |
|
|
|
|
|
using Forks.EnterpriseServices; |
|
|
|
|
|
using Forks.EnterpriseServices.DataForm; |
|
|
|
|
|
using Forks.EnterpriseServices.DomainObjects2; |
|
|
|
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery; |
|
|
|
|
|
using Forks.Utils; |
|
|
|
|
|
using Forks.Utils.IO; |
|
|
|
|
|
using System; |
|
|
|
|
|
using System.Collections; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.IO; |
|
|
|
|
|
using System.Linq; |
|
|
|
|
|
using System.Text; |
|
|
|
|
|
using System.Web.UI; |
|
|
|
|
|
using System.Web.UI.HtmlControls; |
|
|
|
|
|
using TSingSoft.WebControls2; |
|
|
|
|
|
using TSingSoft.WebControls2.BillReports; |
|
|
|
|
|
using TSingSoft.WebPluginFramework; |
|
|
|
|
|
using WebUnit = System.Web.UI.WebControls.Unit; |
|
|
|
|
|
using StockUpClass = BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse_.SaleOutStockAnalyse.StockUpClass; |
|
|
|
|
|
using Forks.EnterpriseServices.SqlDoms; |
|
|
|
|
|
using BWP.B3Frameworks.BO.NamedValueTemplate; |
|
|
|
|
|
using BWP.B3Sale.Utils; |
|
|
|
|
|
using BWP.B3ButcherManage.BO; |
|
|
|
|
|
|
|
|
|
|
|
namespace BWP.Web.Pages.B3ButcherManageToSale.Reports.SaleOutStockAnalyse2_ |
|
|
|
|
|
{ |
|
|
|
|
|
class SaleOutStockPrint2 : PrintPageBase |
|
|
|
|
|
{ |
|
|
|
|
|
public DateTime? MinDate |
|
|
|
|
|
{ |
|
|
|
|
|
get |
|
|
|
|
|
{ |
|
|
|
|
|
if (string.IsNullOrEmpty(Request.QueryString["MinDate"])) |
|
|
|
|
|
return null; |
|
|
|
|
|
return DateTime.Parse(Request.QueryString["MinDate"]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public DateTime? MaxDate |
|
|
|
|
|
{ |
|
|
|
|
|
get |
|
|
|
|
|
{ |
|
|
|
|
|
if (string.IsNullOrEmpty(Request.QueryString["MaxDate"])) |
|
|
|
|
|
return null; |
|
|
|
|
|
return DateTime.Parse(Request.QueryString["MaxDate"]) + new TimeSpan(23, 59, 29); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<long> Goods_IDs |
|
|
|
|
|
{ |
|
|
|
|
|
get |
|
|
|
|
|
{ |
|
|
|
|
|
if (string.IsNullOrEmpty(Request.QueryString["SaleGoods_ID"])) |
|
|
|
|
|
return new List<long>(); |
|
|
|
|
|
return Request.QueryString["SaleGoods_ID"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<long> DeliverGoodsLine_IDs |
|
|
|
|
|
{ |
|
|
|
|
|
get |
|
|
|
|
|
{ |
|
|
|
|
|
if (string.IsNullOrEmpty(Request.QueryString["DeliverGoodsLine_ID"])) |
|
|
|
|
|
return new List<long>(); |
|
|
|
|
|
return Request.QueryString["DeliverGoodsLine_ID"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public string Sequence |
|
|
|
|
|
{ |
|
|
|
|
|
get |
|
|
|
|
|
{ |
|
|
|
|
|
return Request.QueryString["SequenceNumber"].Trim(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public short TakeGoodsType |
|
|
|
|
|
{ |
|
|
|
|
|
get |
|
|
|
|
|
{ |
|
|
|
|
|
return short.Parse(Request.QueryString["TakeGoodsType"]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string GetTemplateFile() |
|
|
|
|
|
{ |
|
|
|
|
|
return PrintUtil.GetTemplateFile(PluginName, GetType().Name + ".xml"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override void InitForm(System.Web.UI.HtmlControls.HtmlForm form) |
|
|
|
|
|
{ |
|
|
|
|
|
Control pageContainer = CreatePageContainer(CreateReport()); |
|
|
|
|
|
form.Controls.Add(pageContainer); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private int pagesCount; |
|
|
|
|
|
private int slipPages; |
|
|
|
|
|
private WebUnit pageHeight = WebUnit.Empty; |
|
|
|
|
|
private Control CreatePageContainer(Control control) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (Control ctrl in control.Controls) |
|
|
|
|
|
{ |
|
|
|
|
|
BillReport r = ctrl as BillReport; |
|
|
|
|
|
if (r != null) |
|
|
|
|
|
{ |
|
|
|
|
|
pagesCount += r.PagesCount; |
|
|
|
|
|
if (pageHeight == WebUnit.Empty) |
|
|
|
|
|
pageHeight = r.PageHeight; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
HtmlGenericControl result = new HtmlGenericControl("div"); |
|
|
|
|
|
result.Style[HtmlTextWriterStyle.Width] = "100%"; |
|
|
|
|
|
result.Style[HtmlTextWriterStyle.Padding] = "0cm"; |
|
|
|
|
|
result.Style[HtmlTextWriterStyle.BorderWidth] = "0cm"; |
|
|
|
|
|
result.Style[HtmlTextWriterStyle.Margin] = "0cm"; |
|
|
|
|
|
if (!pageHeight.IsEmpty) |
|
|
|
|
|
{ |
|
|
|
|
|
result.Style[HtmlTextWriterStyle.Top] = new WebUnit((pageHeight.Value * slipPages), pageHeight.Type).ToString(); |
|
|
|
|
|
result.Style[HtmlTextWriterStyle.Position] = "absolute"; |
|
|
|
|
|
} |
|
|
|
|
|
result.Controls.Add(control); |
|
|
|
|
|
slipPages = pagesCount; |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Control CreateReport() |
|
|
|
|
|
{ |
|
|
|
|
|
var result = new TemplateBillReport(); |
|
|
|
|
|
var parameters = new Dictionary<string, object>(); |
|
|
|
|
|
AddParameters(parameters); |
|
|
|
|
|
|
|
|
|
|
|
var autoAdd = new Dictionary<string, object>(); |
|
|
|
|
|
foreach (KeyValuePair<string, object> pair in parameters) |
|
|
|
|
|
{ |
|
|
|
|
|
if (pair.Value != null && pair.Value is ICollection) |
|
|
|
|
|
{ |
|
|
|
|
|
string newKey = pair.Key + "_RecordCount"; |
|
|
|
|
|
if (!parameters.ContainsKey(newKey)) |
|
|
|
|
|
autoAdd.Add(newKey, ((ICollection)pair.Value).Count); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
foreach (KeyValuePair<string, object> pair in autoAdd) |
|
|
|
|
|
{ |
|
|
|
|
|
parameters.Add(pair.Key, pair.Value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var printTemplateFile = Path.Combine(Wpf.Settings.ConfigFolder, GetTemplateFile()); |
|
|
|
|
|
result.ParseTemplate(FS.OpenRead(printTemplateFile), parameters); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void AddParameters(IDictionary<string, object> dic) |
|
|
|
|
|
{ |
|
|
|
|
|
dic.Add("$Details", GetList().ToList()); |
|
|
|
|
|
dic.Add("$DetailType", typeof(ProductDiffPrint)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IEnumerable<ProductDiffPrint> GetList() |
|
|
|
|
|
{ |
|
|
|
|
|
long? maxSeque = null; |
|
|
|
|
|
if (!string.IsNullOrEmpty(Sequence)) |
|
|
|
|
|
{ |
|
|
|
|
|
var arr = Sequence.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)); |
|
|
|
|
|
if (arr.Any()) |
|
|
|
|
|
maxSeque = arr.Max(); |
|
|
|
|
|
} |
|
|
|
|
|
IEnumerable<ProductDiffPrint> data; |
|
|
|
|
|
List<MinObj> products; |
|
|
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
|
|
{ |
|
|
|
|
|
if (DeliverGoodsLine_IDs.Any()) |
|
|
|
|
|
{ |
|
|
|
|
|
var m = GetMaxLine(session, DeliverGoodsLine_IDs); |
|
|
|
|
|
if (m.HasValue && maxSeque.HasValue && m > maxSeque) |
|
|
|
|
|
maxSeque = m; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data = GetMainInfo(maxSeque, Goods_IDs, MinDate, MaxDate, session); |
|
|
|
|
|
products = GetInStoreNumber(Goods_IDs, MinDate, MaxDate, session); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in data) |
|
|
|
|
|
{ |
|
|
|
|
|
var first = products.FirstOrDefault(x => x.Goods_ID == item.Goods_ID); |
|
|
|
|
|
if (first != null) |
|
|
|
|
|
{ |
|
|
|
|
|
if (item.TakeGoods_Type == 配送方式.客户自运) |
|
|
|
|
|
{ |
|
|
|
|
|
item.ProductMain = Math.Min((item.OrderMain ?? 0).Value, (first.MainNumber ?? 0).Value); |
|
|
|
|
|
first.MainNumber -= item.ProductMain; |
|
|
|
|
|
|
|
|
|
|
|
item.ProductSecond = Math.Min((item.OrderSecond ?? 0).Value, (first.SecondNumber ?? 0).Value); |
|
|
|
|
|
first.SecondNumber -= item.ProductSecond; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
item.ProductMain = first.MainNumber; |
|
|
|
|
|
item.ProductSecond = first.SecondNumber; |
|
|
|
|
|
} |
|
|
|
|
|
if (item.ProductMain == 0) |
|
|
|
|
|
item.ProductMain = null; |
|
|
|
|
|
if (item.ProductSecond == 0) |
|
|
|
|
|
item.ProductSecond = null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
data = data.Where(x => x.TakeGoods_Type == TakeGoodsType); |
|
|
|
|
|
return data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long? GetMaxLine(IDmoSession session, IEnumerable<long> ids) |
|
|
|
|
|
{ |
|
|
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(DeliverGoodsLine))); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Max("SequenceNumber")); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray())); |
|
|
|
|
|
return query.EExecuteScalar<long?>(session); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<ProductDiffPrint> 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 query = new DQueryDom(main); |
|
|
|
|
|
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.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.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 (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.InList(DQExpression.Field(main, "TakeGoods_Type"), DQExpression.Value(配送方式.公司配送), DQExpression.Value(配送方式.客户自运))); |
|
|
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("TakeGoods_Type", true)); |
|
|
|
|
|
var list = new List<ProductDiffPrint>(); |
|
|
|
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
|
|
|
{ |
|
|
|
|
|
while (reader.Read()) |
|
|
|
|
|
{ |
|
|
|
|
|
var entity = new ProductDiffPrint(); |
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class MinObj |
|
|
|
|
|
{ |
|
|
|
|
|
public long Goods_ID { get; set; } |
|
|
|
|
|
public Money<decimal>? MainNumber { get; set; } |
|
|
|
|
|
public Money<decimal>? SecondNumber { get; set; } |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[DFClass, Serializable] |
|
|
|
|
|
[LogicName("备货打印")] |
|
|
|
|
|
public class ProductDiffPrint |
|
|
|
|
|
{ |
|
|
|
|
|
public long Goods_ID { get; set; } |
|
|
|
|
|
public NamedValue<配送方式>? TakeGoods_Type { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
[LogicName("存货名称")] |
|
|
|
|
|
public string Goods_Name { get; set; } |
|
|
|
|
|
[LogicName("单位")] |
|
|
|
|
|
public string Unit { get; set; } |
|
|
|
|
|
[LogicName("辅单位")] |
|
|
|
|
|
public string SecondUnit { get; set; } |
|
|
|
|
|
[LogicName("订货数量")] |
|
|
|
|
|
public Money<decimal>? OrderMain { get; set; } |
|
|
|
|
|
[LogicName("订货辅数量")] |
|
|
|
|
|
public Money<decimal>? OrderSecond { get; set; } |
|
|
|
|
|
[LogicName("产出数量")] |
|
|
|
|
|
public Money<decimal>? ProductMain { get; set; } |
|
|
|
|
|
[LogicName("产出辅数量")] |
|
|
|
|
|
public Money<decimal>? ProductSecond { get; set; } |
|
|
|
|
|
[LogicName("差异数量")] |
|
|
|
|
|
public Money<decimal>? ProductMainDiff |
|
|
|
|
|
{ |
|
|
|
|
|
get |
|
|
|
|
|
{ |
|
|
|
|
|
if (OrderMain == null) |
|
|
|
|
|
return null; |
|
|
|
|
|
var diff = OrderMain - (ProductMain ?? 0).Value; |
|
|
|
|
|
if (diff > 0) |
|
|
|
|
|
return diff; |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
[LogicName("差异辅数量")] |
|
|
|
|
|
public Money<decimal>? ProductSecondDiff |
|
|
|
|
|
{ |
|
|
|
|
|
get |
|
|
|
|
|
{ |
|
|
|
|
|
if (OrderSecond == null) |
|
|
|
|
|
return null; |
|
|
|
|
|
var diff = OrderSecond - (ProductSecond ?? 0).Value; |
|
|
|
|
|
if (diff > 0) |
|
|
|
|
|
return diff; |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |