You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

224 lines
12 KiB

using BWP.B3Frameworks;
using BWP.B3Frameworks.BO.NamedValueTemplate;
using BWP.Web.Layout;
using BWP.Web.Utils;
using BWP.Web.WebControls;
using Forks.EnterpriseServices.DataForm;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.EnterpriseServices.SqlDoms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSingSoft.WebControls2;
using BWP.B3Butchery.BO;
using BWP.B3ProduceUnitedInfos;
using BWP.B3UnitedInfos;
using BWP.B3UnitedInfos.BO;
using BWP.B3Sale.Utils;
using BWP.B3Sale.BO;
using BWP.B3Frameworks.BO;
using Forks.Utils;
namespace BWP.Web.Pages.B3YunKen.Reports
{
class DynamicPriceReport : DFBrowseGridReportPage<ProduceFinish>
{
protected override string Caption
{
get { return "变价关系表"; }
}
protected override string QueryOptionsTabName
{
get
{
return "显示字段";
}
}
protected override string AccessRoleName
{
get { return "B3_YunKen.报表分析.变价关系表"; }
}
readonly DFInfo _detailInfo = DFInfo.Get(typeof(ProduceFinish_Detail));
readonly Dictionary<string, DFInfo> _fileInfo = new Dictionary<string, DFInfo>();
readonly List<string> _sumCol = new List<string>();
DFCheckBox checkbox;
protected override void AddQueryControls(VLayoutPanel vPanel)
{
var layout = new LayoutManager("Main", mDFInfo, mQueryContainer);
//layout.Add("ID", mQueryContainer.Add(new DFTextBox(mDFInfo.Fields["ID"]), "ID"));
//layout["ID"].NotAutoAddToContainer = true;
layout.Add("AccountingUnit_ID", new SimpleLabel("会计单位"), QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["AccountingUnit_ID"], mQueryContainer, "AccountingUnit_ID", B3FrameworksConsts.DataSources.));
layout["AccountingUnit_ID"].NotAutoAddToContainer = true;
//layout.Add("StandardGoods_ID", new SimpleLabel("标准件"), QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["ID"], mQueryContainer, "StandardGoods_ID", B3SaleDataSources.标准件));
//layout["StandardGoods_ID"].NotAutoAddToContainer = true;
layout.Add("GoodsProperty_ID", new SimpleLabel("存货属性"), QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["ID"], mQueryContainer, "GoodsProperty_ID", B3UnitedInfosConsts.DataSources.));
layout["GoodsProperty_ID"].NotAutoAddToContainer = true;
//layout.Add("BrandItem_ID", new SimpleLabel("品牌项"), QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["ID"], mQueryContainer, "BrandItem_ID", B3UnitedInfosConsts.DataSources.品牌项));
//layout["BrandItem_ID"].NotAutoAddToContainer = true;
layout.Add("ProductLine_ID", new SimpleLabel("产品线"), QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["ID"], mQueryContainer, "ProductLine_ID", B3UnitedInfosConsts.DataSources.线));
layout["ProductLine_ID"].NotAutoAddToContainer = true;
layout.Add("Goods_ID", new SimpleLabel("存货"), QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["ID"], mQueryContainer, "Goods_ID", B3UnitedInfosConsts.DataSources.));
layout["Goods_ID"].NotAutoAddToContainer = true;
checkbox = new DFCheckBox();
checkbox.Text = "隐藏";
layout.Add("hiddenPrice", new SimpleLabel("隐藏无价格的产品"), checkbox);
layout["hiddenPrice"].NotAutoAddToContainer = true;
//layout.Add("Date", new SimpleLabel("生产日期"), QueryCreator.TimeRange(mDFInfo.Fields["Date"], mQueryContainer, "MinDate", "MaxDate"));
//layout["Date"].NotAutoAddToContainer = true;
//var state = mQueryContainer.Add(B3ButcheryCustomInputCreator.一般单据状态(mDFInfo.Fields["BillState"], true, false, true, true), "BillState");
//((ChoiceBox)state).Value = 单据状态.已审核.Value.ToString() + "|";
//state.DisplayValue = "已审核;";
//state.EnableInputArgument = true;
//layout.Add("BillState", state);
//layout["BillState"].NotAutoAddToContainer = true;
var config = new AutoLayoutConfig { Cols = 2 };
config.Add("AccountingUnit_ID");
config.Add("GoodsProperty_ID");
//config.Add("BrandItem_ID");
config.Add("ProductLine_ID");
//config.Add("StandardGoods_ID");
config.Add("Goods_ID");
config.Add("hiddenPrice");
//config.Add("Date");
//config.Add("BillState");
layout.Config = config;
vPanel.Add(layout.CreateLayout());
}
ReportDisplayOptionHelper mDisplayHelper = new ReportDisplayOptionHelper();
protected override void AddQueryOptions(VLayoutPanel vPanel)
{
mDisplayHelper.AddOptionItem("会计单位", "accountingUnit", "Name", false);
//mDisplayHelper.AddOptionItem("部门", "bill", "Department_Name", false);
//mDisplayHelper.AddOptionItem("经办人", "bill", "Employee_Name", false);
//mDisplayHelper.AddOptionItem("客户", "bill", "Customer_Name", false);
mDisplayHelper.AddOptionItem("存货属性", "goods", "GoodsProperty_Name", false);
//mDisplayHelper.AddOptionItem("品牌项", "detail", "BrandItem_Name", false);
mDisplayHelper.AddOptionItem("产品线", "goods", "ProductLine_Name", false);
mDisplayHelper.AddOptionItem("存货编号", "goods", "Code", false);
mDisplayHelper.AddOptionItem("存货名称", "goods", "Name", false);
mDisplayHelper.AddOptionItem("主单位", "goods", "MainUnit", false);
mDisplayHelper.AddOptionItem("标准件", "detail", "StandardName", false);
mDisplayHelper.AddOptionItem("单价", "detail", "Price", false);
AddQueryOption("选项", mDisplayHelper.GetAllDisplayNames(), mDisplayHelper.GetDefaultSelelectedDisplayNames());
base.AddQueryOptions(vPanel);
}
private DQueryDom GetMaxPriceBillID()
{
var detail = new JoinAlias(typeof(PriceBill_AccountingUnitDetail));
var query = new DQueryDom(new JoinAlias(typeof(PriceBill)));
query.From.AddJoin(JoinType.Left,new DQDmoSource(detail),DQCondition.EQ(detail,"PriceBill_ID",query.From.RootSource.Alias,"ID"));
query.Columns.Add(DQSelectColumn.Field("AccountingUnit_ID",detail));
query.Columns.Add(DQSelectColumn.Max(query.From.RootSource.Alias,"ID"));
query.Where.Conditions.Add(DQCondition.EQ("BillState",.));
query.GroupBy.Expressions.Add(DQExpression.Field(detail,"AccountingUnit_ID"));
return query;
}
class PriceBillID
{
public long? AccountingUnit_ID { get; set; }
public long ID { get; set; }
}
private DQueryDom GetPriceBillPrice()
{
var bill = new JoinAlias("a",typeof(PriceBill));
var detail = new JoinAlias("b",typeof(PriceBill_Detail));
var priceBillID = new JoinAlias("c", typeof(PriceBillID));
var query = new DQueryDom(bill);
query.From.AddJoin(JoinType.Inner, new DQDmoSource(priceBillID), DQCondition.EQ(bill, "ID", priceBillID, "ID"));
query.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.EQ(bill, "ID", detail, "PriceBill_ID"));
query.Columns.Add(DQSelectColumn.Field("AccountingUnit_ID", priceBillID));
query.Columns.Add(DQSelectColumn.Field("SaleGoods_ID",detail));
query.Columns.Add(DQSelectColumn.Create(DQExpression.Value("标准件"), "StandardName"));
query.Columns.Add(DQSelectColumn.Field("Price",detail));
return query;
}
class PriceBillID2
{
public long? AccountingUnit_ID { get; set; }
public long ID { get; set; }
}
private DQueryDom GetPriceBillChildPrice()
{
var detail = new JoinAlias("d",typeof(PriceBill_Detail));
var convert = new JoinAlias("e",typeof(StandardConvert));
var priceBillID = new JoinAlias("f",typeof(PriceBillID2));
var bill = new JoinAlias("g",typeof(PriceBill));
var dom = new DQueryDom(bill);
dom.From.AddJoin(JoinType.Inner, new DQDmoSource(priceBillID), DQCondition.EQ(bill, "ID", priceBillID, "ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.EQ(bill, "ID", detail, "PriceBill_ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(convert), DQCondition.EQ(detail, "SaleGoods_ID", convert, "StandardGoods_ID"));
dom.Columns.Add(DQSelectColumn.Field("AccountingUnit_ID", priceBillID));
dom.Columns.Add(DQSelectColumn.Field("Goods_ID", convert));
dom.Columns.Add(DQSelectColumn.Field("StandardGoods_Name", convert));
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Add(DQExpression.Multiply(DQExpression.Field(detail, "Price"), DQExpression.IfNull(DQExpression.Field(convert, "Multiplier"), DQExpression.Value(1))), DQExpression.IfNull(DQExpression.Field(convert, "Diff"), DQExpression.Value(0))),"GoodsPrice"));
dom.Where.Conditions.Add(DQCondition.IsNotNull(DQExpression.Field(convert, "Goods_ID")));
return dom;
}
class PriceBillData
{
public long? AccountingUnit_ID { get; set; }
public long? Goods_ID { get; set; }
public string StandardName { get; set; }
public Money<decimal>? Price { get; set; }
}
protected override DQueryDom GetQueryDom()
{
var query1 = GetPriceBillChildPrice();
query1.UnionNext.Select = GetPriceBillPrice();
query1.UnionNext.Type = UnionType.All;
var detail = new JoinAlias("detail", typeof(PriceBillData));
mDisplayHelper.AddAlias("detail", JoinAlias.Create("detail"));
var accountingUnit = new JoinAlias("accountingUnit", typeof(AccountingUnit));
mDisplayHelper.AddAlias("accountingUnit", JoinAlias.Create("accountingUnit"));
var goods = new JoinAlias("goods", typeof(SaleGoods));
mDisplayHelper.AddAlias("goods", JoinAlias.Create("goods"));
//var goodsProperty = new JoinAlias("goodsProperty", typeof(GoodsProperty));
//mDisplayHelper.AddAlias("goodsProperty", JoinAlias.Create("goodsProperty"));
var dom = new DQueryDom(detail);
dom.RegisterQueryTable(typeof(PriceBillID), new string[] { "AccountingUnit_ID", "ID" }, GetMaxPriceBillID());
dom.RegisterQueryTable(typeof(PriceBillID2), new string[] { "AccountingUnit_ID", "ID" }, GetMaxPriceBillID());
dom.RegisterQueryTable(typeof(PriceBillData), new string[] { "AccountingUnit_ID", "Goods_ID","StandardName", "Price" }, query1);
dom.From.AddJoin(JoinType.Left, new DQDmoSource(accountingUnit), DQCondition.EQ(detail, "AccountingUnit_ID", accountingUnit, "ID"));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(detail, "Goods_ID", goods, "ID"));
//dom.From.AddJoin(JoinType.Left, new DQDmoSource(goodsProperty), DQCondition.EQ(goodsProperty, "ID", goods, "GoodsProperty_ID"));
var goodsChb = mQueryContainer.GetControl<DFChoiceBox>("Goods_ID");
var lineChb = mQueryContainer.GetControl<DFChoiceBox>("ProductLine_ID");
var accountingUnitChb = mQueryContainer.GetControl<DFChoiceBox>("AccountingUnit_ID");
var goodsPropertyChb = mQueryContainer.GetControl<DFChoiceBox>("GoodsProperty_ID");
if(checkbox.Checked)
dom.Where.Conditions.Add(DQCondition.IsNotNull(DQExpression.Field(detail, "Price")));
if (!goodsChb.IsEmpty) {
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "Goods_ID"), goodsChb.GetValues().Select(x => DQExpression.Value(x)).ToArray()));
}
if (!goodsPropertyChb.IsEmpty) {
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(goods, "GoodsProperty_ID"), goodsPropertyChb.GetValues().Select(x => DQExpression.Value(x)).ToArray()));
}
if (!lineChb.IsEmpty) {
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(goods, "ProductLine_ID"), lineChb.GetValues().Select(x => DQExpression.Value(x)).ToArray()));
}
if (!accountingUnitChb.IsEmpty) {
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "AccountingUnit_ID"), accountingUnitChb.GetValues().Select(x => DQExpression.Value(x)).ToArray()));
}
mDisplayHelper.AddSelectColumns(dom, (name) => OptionIsSelected("选项", name), SumColumnIndexs);
return dom;
}
}
}