|
@@ -18,12 +18,21 @@ namespace PRSDesktop
|
|
|
|
|
|
public RequisitionItemGrid()
|
|
|
{
|
|
|
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.EditRows,
|
|
|
- DynamicGridOption.MultiSelect);
|
|
|
+ Options.BeginUpdate()
|
|
|
+ .Add(DynamicGridOption.RecordCount)
|
|
|
+ .Add(DynamicGridOption.SelectColumns)
|
|
|
+ .Add(DynamicGridOption.AddRows)
|
|
|
+ .Add(DynamicGridOption.EditRows)
|
|
|
+ .Add(DynamicGridOption.DeleteRows)
|
|
|
+ .Add(DynamicGridOption.FilterRows)
|
|
|
+ .Add(DynamicGridOption.MultiSelect)
|
|
|
+ .EndUpdate();
|
|
|
HiddenColumns.Add(x => x.Code);
|
|
|
HiddenColumns.Add(x => x.BarCode);
|
|
|
HiddenColumns.Add(x => x.RequisitionLink.JobLink.ID);
|
|
|
HiddenColumns.Add(x => x.RequisitionLink.ID);
|
|
|
+ HiddenColumns.Add(x => x.RequisitionLink.Filled);
|
|
|
+ HiddenColumns.Add(x => x.RequisitionLink.Archived);
|
|
|
HiddenColumns.Add(x => x.Product.ID);
|
|
|
HiddenColumns.Add(x => x.Product.Deleted);
|
|
|
HiddenColumns.Add(x => x.Product.DefaultStyle.ID);
|
|
@@ -47,8 +56,74 @@ namespace PRSDesktop
|
|
|
HiddenColumns.Add(x => x.Location.Code);
|
|
|
HiddenColumns.Add(x => x.Location.Description);
|
|
|
HiddenColumns.Add(x => x.Location.Deleted);
|
|
|
+ HiddenColumns.Add(x => x.Style.ID);
|
|
|
+ HiddenColumns.Add(x => x.Style.Code);
|
|
|
+ HiddenColumns.Add(x => x.Picked);
|
|
|
+ ActionColumns.Add(new DynamicMenuColumn(SelectHolding,
|
|
|
+ (row) => (row.Get<RequisitionItem,Guid>(c=>c.Product.ID) == Guid.Empty) || row.Get<RequisitionItem, bool>(c => c.Product.NonStock) == true
|
|
|
+ ? DynamicMenuStatus.Hidden
|
|
|
+ : DynamicMenuStatus.Enabled)
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
+ private void SelectHolding(DynamicMenuColumn column, CoreRow? row)
|
|
|
+ {
|
|
|
+ using (new WaitCursor())
|
|
|
+ {
|
|
|
+ var holdings = new Client<StockHolding>().Query(
|
|
|
+ new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(row.Get<RequisitionItem, Guid>(c => c.Product.ID)),
|
|
|
+ new Columns<StockHolding>(x => x.Location.ID)
|
|
|
+ .Add(x => x.Location.Code)
|
|
|
+ .Add(x => x.Style.ID)
|
|
|
+ .Add(x => x.Style.Code)
|
|
|
+ .Add(x => x.Job.ID)
|
|
|
+ .Add(x => x.Job.JobNumber)
|
|
|
+ .Add(x => x.Dimensions.Unit.ID)
|
|
|
+ .Add(x => x.Dimensions.Length)
|
|
|
+ .Add(x => x.Dimensions.Width)
|
|
|
+ .Add(x => x.Dimensions.Height)
|
|
|
+ .Add(x => x.Dimensions.Weight)
|
|
|
+ .Add(x => x.Dimensions.UnitSize)
|
|
|
+ .Add(x => x.Dimensions.Value)
|
|
|
+ .Add(x => x.Dimensions.Unit.HasQuantity)
|
|
|
+ .Add(x => x.Dimensions.Unit.HasLength)
|
|
|
+ .Add(x => x.Dimensions.Unit.HasWidth)
|
|
|
+ .Add(x => x.Dimensions.Unit.HasWeight)
|
|
|
+ .Add(x => x.Dimensions.Unit.HasHeight)
|
|
|
+ .Add(x => x.Dimensions.Unit.Formula)
|
|
|
+ .Add(x => x.Dimensions.Unit.Format)
|
|
|
+ .Add(x => x.Units),
|
|
|
+ new SortOrder<StockHolding>(x => x.Location.Code).ThenBy(x => x.Style.Code).ThenBy(x => x.Dimensions.UnitSize)
|
|
|
+ );
|
|
|
+
|
|
|
+ foreach (var holding in holdings.Rows)
|
|
|
+ {
|
|
|
+ String text =
|
|
|
+ $"{holding.Get<StockHolding, String>(c => c.Location.Code)}: {holding.Get<StockHolding, double>(c => c.Units)} @ {holding.Get<StockHolding, String>(c => c.Dimensions.UnitSize)}";
|
|
|
+ String style = holding.Get<StockHolding, String>(c => c.Style.Code);
|
|
|
+ if (!String.IsNullOrWhiteSpace(style))
|
|
|
+ text = $"{text} ({style})";
|
|
|
+ column.AddItem(text, null, (sel) => SelectLocation(holding,sel));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SelectLocation(CoreRow holdingrow, CoreRow itemrow)
|
|
|
+ {
|
|
|
+ var item = itemrow.ToObject<RequisitionItem>();
|
|
|
+ var holding = holdingrow.ToObject<StockHolding>();
|
|
|
+ item.Location.ID = holding.Location.ID;
|
|
|
+ item.Location.Code = holding.Location.Code;
|
|
|
+ item.Dimensions.CopyFrom(holding.Dimensions, true);
|
|
|
+ item.Style.ID = holding.Style.ID;
|
|
|
+ item.Style.Code = holding.Style.Code;
|
|
|
+ new Client<RequisitionItem>().Save(item, "Changed due to stock holding selection");
|
|
|
+ Data.LoadRow(itemrow, item);
|
|
|
+ InvalidateRow(itemrow);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public Requisition Requisition { get; set; }
|
|
|
|
|
|
protected override void Reload(Filters<RequisitionItem> criteria, Columns<RequisitionItem> columns, ref SortOrder<RequisitionItem>? sort,
|
|
@@ -104,6 +179,15 @@ namespace PRSDesktop
|
|
|
return base.EditItems(items, PageDataHandler, PreloadPages);
|
|
|
}
|
|
|
|
|
|
+ protected override RequisitionItem CreateItem()
|
|
|
+ {
|
|
|
+ var item = base.CreateItem();
|
|
|
+ item.RequisitionLink.ID = Requisition.ID;
|
|
|
+ item.RequisitionLink.Synchronise(Requisition);
|
|
|
+ item.Quantity = 1;
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
protected override void DoAdd()
|
|
|
{
|
|
|
if (Requisition == null || Requisition.ID.Equals(Guid.Empty))
|
|
@@ -118,209 +202,10 @@ namespace PRSDesktop
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- var dialog = new MultiSelectDialog<Product>(
|
|
|
- null, //new Filter<Product>(x=>x.DefaultLocation.ID).IsNotEqualTo(Guid.Empty),
|
|
|
- new Columns<Product>(
|
|
|
- x => x.Code,
|
|
|
- x => x.Name,
|
|
|
- x => x.DefaultStyle.ID,
|
|
|
- x => x.Dimensions.Unit.ID,
|
|
|
- x => x.Dimensions.Length,
|
|
|
- x => x.Dimensions.Width,
|
|
|
- x => x.Dimensions.Height,
|
|
|
- x => x.Dimensions.Weight,
|
|
|
- x => x.Dimensions.UnitSize,
|
|
|
- x => x.Dimensions.Value,
|
|
|
- x => x.Dimensions.Unit.HasQuantity,
|
|
|
- x => x.Dimensions.Unit.HasLength,
|
|
|
- x => x.Dimensions.Unit.HasWidth,
|
|
|
- x => x.Dimensions.Unit.HasWeight,
|
|
|
- x => x.Dimensions.Unit.HasHeight,
|
|
|
- x => x.Dimensions.Unit.Formula,
|
|
|
- x => x.Dimensions.Unit.Format,
|
|
|
- //x => x.Units.ID,
|
|
|
- x => x.DefaultLocation.ID,
|
|
|
- x => x.UnitQty,
|
|
|
- x => x.NonStock
|
|
|
- )
|
|
|
- );
|
|
|
- if (dialog.ShowDialog())
|
|
|
- {
|
|
|
- var products = dialog.Data();
|
|
|
-
|
|
|
- Progress.Show("Adding Products");
|
|
|
-
|
|
|
- var reqitems = new Client<RequisitionItem>().Load(
|
|
|
- new Filter<RequisitionItem>(x => x.RequisitionLink.ID).IsEqualTo(Requisition.ID) /*.And(x => x.BoxNumber).IsEqualTo(Boxes) */
|
|
|
- );
|
|
|
- var ritems = new List<RequisitionItem>();
|
|
|
-
|
|
|
- foreach (var product in products.Rows)
|
|
|
- {
|
|
|
- var p = product.ToObject<Product>();
|
|
|
- // var productid = product.Get<Product, Guid>(x => x.ID);
|
|
|
- // var code = product.Get<Product, string>(c => c.Code);
|
|
|
- // var name = product.Get<Product, string>(c => c.Name);
|
|
|
- // var styleid = product.Get<Product, Guid>(c => c.DefaultStyle.ID);
|
|
|
- // var locationid = product.Get<Product, Guid>(c => c.DefaultLocation.ID);
|
|
|
- // var unitid = product.Get<Product, Guid>(c => c.Units.ID);
|
|
|
- // var unitsize = product.Get<Product, double>(c => c.UnitSize);
|
|
|
- // var unitqty = product.Get<Product, double>(c => c.UnitQty);
|
|
|
- // var nonstock = product.Get<Product, bool>(c => c.NonStock);
|
|
|
-
|
|
|
- var item = reqitems.FirstOrDefault(x => x.Code.Equals(p.Code));
|
|
|
- if (item != null)
|
|
|
- {
|
|
|
- item.Quantity += 1;
|
|
|
- ritems.Add(item);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- item = new RequisitionItem
|
|
|
- {
|
|
|
- //BoxNumber = Boxes,
|
|
|
- Code = p.Code,
|
|
|
- Description = p.Name,
|
|
|
- BarCode = p.Code,
|
|
|
- Quantity = 1
|
|
|
- };
|
|
|
- item.RequisitionLink.ID = Requisition.ID;
|
|
|
- item.RequisitionLink.Number = Requisition.Number;
|
|
|
- item.RequisitionLink.JobLink.ID = Requisition.JobLink.ID;
|
|
|
- item.Product.ID = p.ID;
|
|
|
- item.Product.DefaultStyle.ID = p.DefaultStyle.ID;
|
|
|
- item.Product.Dimensions.CopyFrom(p.Dimensions);
|
|
|
- item.Product.DefaultLocation.ID = p.DefaultLocation.ID;
|
|
|
- item.Product.NonStock = p.NonStock;
|
|
|
- item.Product.DefaultStyle.ID = p.DefaultStyle.ID;
|
|
|
- item.Style.ID = p.DefaultStyle.ID;
|
|
|
-
|
|
|
- if (!p.NonStock)
|
|
|
- FindHolding(p.ID, p.DefaultStyle.ID, Requisition.JobLink.ID, p.Dimensions.UnitSize, p.DefaultLocation.ID, item);
|
|
|
-
|
|
|
-
|
|
|
- ritems.Add(item);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (ritems.Any())
|
|
|
- new Client<RequisitionItem>().Save(ritems, "Manually Added to Requisition");
|
|
|
- Refresh(false, true);
|
|
|
- Progress.Close();
|
|
|
- //MessageBox.Show(String.Format("{0} products added", products.Rows.Count));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void FindHolding(Guid productid, Guid styleid, Guid jobid, String unitsize, Guid defaultlocationid, params RequisitionItem[] items)
|
|
|
- {
|
|
|
- if (Requisition == null)
|
|
|
- return;
|
|
|
-
|
|
|
- // Try and Find a suitable default holding for this item
|
|
|
- var holdings = new Client<StockHolding>().Query(
|
|
|
- new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(productid)
|
|
|
- .And(x => x.Style.ID).IsEqualTo(styleid)
|
|
|
- .And(x => x.Dimensions.UnitSize).IsEqualTo(unitsize),
|
|
|
- new Columns<StockHolding>(x => x.ID)
|
|
|
- .Add(x => x.Job.ID)
|
|
|
- .Add(x => x.Location.ID)
|
|
|
- .Add(x => x.Location.Code)
|
|
|
- );
|
|
|
-
|
|
|
- // Is there a job reserve in the default location?
|
|
|
- var holdingrows = holdings.Rows.Where(r =>
|
|
|
- r.Get<StockHolding, Guid>(c => c.Location.ID).Equals(defaultlocationid) &&
|
|
|
- r.Get<StockHolding, Guid>(c => c.Job.ID).Equals(jobid)).ToArray();
|
|
|
-
|
|
|
- // Is there a job reserve anywhere?
|
|
|
- if (!holdingrows.Any())
|
|
|
- holdingrows = holdings.Rows.Where(r => r.Get<StockHolding, Guid>(c => c.Job.ID).Equals(jobid)).ToArray();
|
|
|
-
|
|
|
- // Is there Free Stock in the Default Location?
|
|
|
- if (!holdingrows.Any())
|
|
|
- holdingrows = holdings.Rows.Where(r =>
|
|
|
- r.Get<StockHolding, Guid>(c => c.Location.ID).Equals(defaultlocationid) &&
|
|
|
- !Entity.IsEntityLinkValid<StockHolding, JobLink>(x => x.Job, r))
|
|
|
- .ToArray();
|
|
|
-
|
|
|
- // Is there Free Stock Anywhere?
|
|
|
- if (!holdingrows.Any())
|
|
|
- holdingrows = holdings.Rows.Where(r => !Entity.IsEntityLinkValid<StockHolding, JobLink>(x => x.Job, r)).ToArray();
|
|
|
-
|
|
|
- // Only Update the Requi Holding if there is a single location
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- item.Location.ID = holdingrows.SingleOrDefault()?.Get<StockHolding, Guid>(c => c.Location.ID) ?? Guid.Empty;
|
|
|
- item.Location.Code = holdingrows.SingleOrDefault()?.Get<StockHolding, String>(c => c.Location.Code) ?? "";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected override Dictionary<string, object?> EditorValueChanged(IDynamicEditorForm editor, RequisitionItem[] items, string name, object value)
|
|
|
- {
|
|
|
- var result = base.EditorValueChanged(editor, items, name, value);
|
|
|
- if (string.Equals(name, "Product.ID"))
|
|
|
- {
|
|
|
- var productid = (Guid)value;
|
|
|
- var code = "";
|
|
|
- var description = "";
|
|
|
- var style = Guid.Empty;
|
|
|
- var location = Guid.Empty;
|
|
|
- var nonstock = true;
|
|
|
- var unitsize = "";
|
|
|
-
|
|
|
- if (productid != Guid.Empty)
|
|
|
- {
|
|
|
- var lookup = new Client<Product>().Query(
|
|
|
- new Filter<Product>(x => x.ID).IsEqualTo(productid),
|
|
|
- new Columns<Product>(x => x.Code, x => x.Name, x => x.DefaultStyle.ID, x => x.DefaultLocation.ID, x => x.NonStock)
|
|
|
- ).Rows.FirstOrDefault();
|
|
|
- code = lookup != null ? lookup.Get<Product, string>(x => x.Code) : "";
|
|
|
- description = lookup != null ? lookup.Get<Product, string>(x => x.Name) : "";
|
|
|
- style = lookup != null ? lookup.Get<Product, Guid>(x => x.DefaultStyle.ID) : Guid.Empty;
|
|
|
- location = lookup != null ? lookup.Get<Product, Guid>(x => x.DefaultLocation.ID) : Guid.Empty;
|
|
|
- unitsize = lookup != null ? lookup.Get<Product, String>(x => x.Dimensions.UnitSize) : "";
|
|
|
- nonstock = lookup != null ? lookup.Get<Product, bool>(x => x.NonStock) : true;
|
|
|
- if (!nonstock)
|
|
|
- {
|
|
|
- location = lookup != null ? lookup.Get<Product, Guid>(x => x.DefaultStyle.ID) : Guid.Empty;
|
|
|
- FindHolding(productid, style, Requisition.JobLink.ID, unitsize, location, items);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- editor.FindEditor("Code").SetValue(code);
|
|
|
- editor.FindEditor("Description").SetValue(description);
|
|
|
- editor.FindEditor("Style.ID").SetValue(style);
|
|
|
- foreach (var item in items)
|
|
|
- item.Location.ID = location;
|
|
|
- editor.FindEditor("Location.ID").Configure();
|
|
|
- }
|
|
|
- else if (string.Equals(name, "Style.ID"))
|
|
|
- {
|
|
|
- var reqi = items.First();
|
|
|
- var productid = reqi.Product.ID;
|
|
|
- var nonstock = reqi.Product.NonStock;
|
|
|
- var styleid = reqi.Style.ID;
|
|
|
- var locationid = reqi.Product.DefaultLocation.ID;
|
|
|
- var unitsize = reqi.Dimensions.UnitSize;
|
|
|
- if (reqi.Product.IsValid() || !nonstock)
|
|
|
- {
|
|
|
- FindHolding(productid, styleid, Requisition.JobLink.ID, unitsize, locationid, items);
|
|
|
- editor.FindEditor("Holding.ID").Configure();
|
|
|
- }
|
|
|
- }
|
|
|
+ base.DoAdd();
|
|
|
|
|
|
- return result;
|
|
|
}
|
|
|
-
|
|
|
- // protected override void LookupsDefined(ILookupEditorControl sender, RequisitionItem[] items)
|
|
|
- // {
|
|
|
- // base.LookupsDefined(sender, items);
|
|
|
- // if (string.Equals(sender.ColumnName, "Holding.ID") && sender.Loaded)
|
|
|
- // {
|
|
|
- // var id = items.Select(x => x.Holding.ID).Distinct().SingleOrDefault();
|
|
|
- // if (!Equals(id, sender.GetValue()))
|
|
|
- // sender.SetValue(id);
|
|
|
- // }
|
|
|
- // }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|