|
@@ -9,6 +9,7 @@ using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using InABox.DynamicGrid;
|
|
|
using InABox.WPF;
|
|
|
+using sun.misc;
|
|
|
|
|
|
namespace PRSDesktop
|
|
|
{
|
|
@@ -25,7 +26,7 @@ namespace PRSDesktop
|
|
|
);
|
|
|
|
|
|
OnEditorValueChanged += SupplierPurchaseOrders_OnEditorValueChanged;
|
|
|
-
|
|
|
+
|
|
|
HiddenColumns.Add(x => x.ClosedDate);
|
|
|
HiddenColumns.Add(x => x.Balance);
|
|
|
|
|
@@ -36,139 +37,84 @@ namespace PRSDesktop
|
|
|
private Dictionary<string, object> SupplierPurchaseOrders_OnEditorValueChanged(object sender, string name, object value)
|
|
|
{
|
|
|
Dictionary<string, object> result = new Dictionary<string, object>();
|
|
|
- if (name.Equals("DueDate"))
|
|
|
+ var form = sender as DynamicEditorForm;
|
|
|
+ var itemspage = form?.Pages.FirstOrDefault(x => x is DynamicOneToManyGrid<PurchaseOrder, PurchaseOrderItem>) as DynamicOneToManyGrid<PurchaseOrder, PurchaseOrderItem>;
|
|
|
+ if ((itemspage == null) || (itemspage.Items.Count == 0))
|
|
|
+ return result;
|
|
|
+
|
|
|
+ if (name.Equals("DueDate") && (MessageBox.Show("Update Due Date on existing items?", "Alert", MessageBoxButton.YesNo) == MessageBoxResult.Yes))
|
|
|
{
|
|
|
- var choice = MessageBox.Show("Due Date changed - apply to all Purchase Order Items?", "Alert", MessageBoxButton.YesNo);
|
|
|
- switch (choice)
|
|
|
- {
|
|
|
- case MessageBoxResult.Yes:
|
|
|
- break;
|
|
|
- default:
|
|
|
- return result;
|
|
|
- }
|
|
|
- Progress.Show("Working");
|
|
|
- var form = sender as DynamicEditorForm;
|
|
|
- foreach (var page in form.Pages)
|
|
|
- {
|
|
|
- if (page is DynamicOneToManyGrid<PurchaseOrder, PurchaseOrderItem> poitemgrid)
|
|
|
- {
|
|
|
- if (poitemgrid.Items.Count == 0)
|
|
|
- {
|
|
|
- Dispatcher.Invoke(() =>
|
|
|
- {
|
|
|
- poitemgrid.Load(form.Items[0], null);
|
|
|
- });
|
|
|
- }
|
|
|
- List<PurchaseOrderItem> items = new List<PurchaseOrderItem>();
|
|
|
- foreach (var item in poitemgrid.Items)
|
|
|
- {
|
|
|
- item.DueDate = Convert.ToDateTime(value);
|
|
|
- }
|
|
|
- Dispatcher.Invoke(() =>
|
|
|
- {
|
|
|
- poitemgrid.Refresh(false, true);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- Progress.Close();
|
|
|
+ foreach (var item in itemspage.Items)
|
|
|
+ item.DueDate = Convert.ToDateTime(value);
|
|
|
+ itemspage.Refresh(false, true);
|
|
|
}
|
|
|
- else if (name.Equals("SupplierLink.ID"))
|
|
|
+ else if (name.Equals("SupplierLink.ID") &&
|
|
|
+ (MessageBox.Show("Update Supplier Pricing to existihg items?", "Alert", MessageBoxButton.YesNo) == MessageBoxResult.Yes))
|
|
|
{
|
|
|
- var choice = MessageBox.Show("Supplier changed - change pricing to all Purchase Order Items where Supplier Pricing is found?" +
|
|
|
- " (If not found, product base cost price will be applied", "Alert", MessageBoxButton.YesNo);
|
|
|
- switch (choice)
|
|
|
- {
|
|
|
- case MessageBoxResult.Yes:
|
|
|
- break;
|
|
|
- default:
|
|
|
- return result;
|
|
|
- }
|
|
|
- Progress.Show("Working");
|
|
|
- var form = sender as DynamicEditorForm;
|
|
|
- foreach (var page in form.Pages)
|
|
|
- {
|
|
|
- if (page is DynamicOneToManyGrid<PurchaseOrder, PurchaseOrderItem> poitemgrid)
|
|
|
- {
|
|
|
- if (poitemgrid.Items.Count == 0)
|
|
|
- {
|
|
|
- Dispatcher.Invoke(() =>
|
|
|
- {
|
|
|
- poitemgrid.Load(form.Items[0], null);
|
|
|
- });
|
|
|
- }
|
|
|
- List<SupplierProduct> supplierProducts = GetSupplierProducts(value);
|
|
|
- Filter<Product> filter = new Filter<Product>(x => x.ID).IsEqualTo(poitemgrid.Items[0].Product.ID);
|
|
|
- foreach (var item in poitemgrid.Items)
|
|
|
- {
|
|
|
- SupplierProduct checkProduct = supplierProducts.Find(x => x.ProductLink.ID == item.Product.ID);
|
|
|
- if (checkProduct != null)
|
|
|
- {
|
|
|
- SupplierProduct checkJob = supplierProducts.Find(x => x.ProductLink.ID == item.Product.ID && x.Job.ID == item.Job.ID);
|
|
|
- if (checkJob != null)
|
|
|
- item.Cost = checkJob.TradePrice;
|
|
|
- else
|
|
|
- item.Cost = checkProduct.TradePrice;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- filter = filter.Or(x => x.ID).IsEqualTo(item.Product.ID);
|
|
|
- item.Cost = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- Dictionary<Guid, double> productIDCosts = new Dictionary<Guid, double>();
|
|
|
+ PurchaseOrder.UpdateCosts(itemspage.Items, (Guid)value, null);
|
|
|
+ // var productids = itemspage.Items.Where(x => x.Product.ID != Guid.Empty).Select(x => x.Product.ID).ToArray();
|
|
|
+ // MultiQuery query = new MultiQuery();
|
|
|
+ // query.Add(
|
|
|
+ // new Filter<SupplierProduct>(x=>x.SupplierLink.ID).IsEqualTo(value).And(x=>x.ProductLink.ID).InList(productids),
|
|
|
+ // new Columns<SupplierProduct>(x=>x.ProductLink.ID).Add(x=>x.Job.ID).Add(x=>x.CostPrice)
|
|
|
+ // );
|
|
|
+ // query.Add(
|
|
|
+ // new Filter<Product>(x=>x.ID).InList(productids),
|
|
|
+ // new Columns<Product>(x=>x.ID).Add(x=>x.NettCost)
|
|
|
+ // );
|
|
|
+ // query.Query();
|
|
|
+ //
|
|
|
+ // foreach (var item in itemspage.Items)
|
|
|
+ // {
|
|
|
+ // CoreRow? row = query.Get<SupplierProduct>()?.Rows.FirstOrDefault(r =>
|
|
|
+ // (r.Get<SupplierProduct, Guid>(c => c.ProductLink.ID) == item.Product.ID)
|
|
|
+ // && (r.Get<SupplierProduct, Guid>(c => c.Job.ID) == item.Job.ID)
|
|
|
+ // );
|
|
|
+ // if (row == null)
|
|
|
+ // row = query.Get<SupplierProduct>()?.Rows.FirstOrDefault(r =>
|
|
|
+ // (r.Get<SupplierProduct, Guid>(c => c.ProductLink.ID) == item.Product.ID)
|
|
|
+ // && (r.Get<SupplierProduct, Guid>(c => c.Job.ID) == Guid.Empty)
|
|
|
+ // );
|
|
|
+ // if (row != null)
|
|
|
+ // item.Cost = row.Get<SupplierProduct, double>(c => c.CostPrice);
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // row = query.Get<Product>()?.Rows.FirstOrDefault(r =>
|
|
|
+ // (r.Get<Product, Guid>(c => c.ID) == item.Product.ID)
|
|
|
+ // );
|
|
|
+ // if (row != null)
|
|
|
+ // item.Cost = row.Get<Product, double>(c => c.NettCost);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // }
|
|
|
+
|
|
|
+ itemspage.Refresh(false, true);
|
|
|
|
|
|
- CoreTable productsTable = new Client<Product>().Query(filter,
|
|
|
- new Columns<Product>(x => x.ID, x => x.BaseCost));
|
|
|
- if (productsTable.Rows.Any())
|
|
|
- {
|
|
|
- foreach (CoreRow row in productsTable.Rows)
|
|
|
- {
|
|
|
- List<Object> list = row.Values;
|
|
|
- if (list[1] == null) list[1] = 0;
|
|
|
- productIDCosts.Add(Guid.Parse(list[0].ToString()), double.Parse(list[1].ToString()));
|
|
|
- }
|
|
|
- }
|
|
|
- if (productIDCosts.Count != 0)
|
|
|
- {
|
|
|
- foreach (var item in poitemgrid.Items)
|
|
|
- {
|
|
|
- if (item.Cost == 0 && productIDCosts.ContainsKey(item.Product.ID))
|
|
|
- {
|
|
|
- item.Cost = productIDCosts[item.Product.ID];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Dispatcher.Invoke(() =>
|
|
|
- {
|
|
|
- poitemgrid.Refresh(false, true);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- Progress.Close();
|
|
|
}
|
|
|
return result;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- private List<SupplierProduct> GetSupplierProducts(object value)
|
|
|
- {
|
|
|
- List<SupplierProduct> supplierProducts = new List<SupplierProduct>();
|
|
|
- CoreTable supplierProductstable = new Client<SupplierProduct>().Query(new Filter<SupplierProduct>(x => x.SupplierLink.ID).IsEqualTo(Guid.Parse(value.ToString())),
|
|
|
- new Columns<SupplierProduct>(
|
|
|
- x => x.ID,
|
|
|
- x => x.SupplierLink.ID,
|
|
|
- x => x.ProductLink.ID,
|
|
|
- x => x.Job.ID,
|
|
|
- x => x.TradePrice));
|
|
|
- if (supplierProductstable.Rows.Any())
|
|
|
- {
|
|
|
- foreach (CoreRow row in supplierProductstable.Rows)
|
|
|
- {
|
|
|
- SupplierProduct supplierProduct = row.ToObject<SupplierProduct>();
|
|
|
- supplierProducts.Add(supplierProduct);
|
|
|
- }
|
|
|
- }
|
|
|
- return supplierProducts;
|
|
|
- }
|
|
|
+ // private List<SupplierProduct> GetSupplierProducts(object value)
|
|
|
+ // {
|
|
|
+ // List<SupplierProduct> supplierProducts = new List<SupplierProduct>();
|
|
|
+ // CoreTable supplierProductstable = new Client<SupplierProduct>().Query(new Filter<SupplierProduct>(x => x.SupplierLink.ID).IsEqualTo(Guid.Parse(value.ToString())),
|
|
|
+ // new Columns<SupplierProduct>(
|
|
|
+ // x => x.ID,
|
|
|
+ // x => x.SupplierLink.ID,
|
|
|
+ // x => x.ProductLink.ID,
|
|
|
+ // x => x.Job.ID,
|
|
|
+ // x => x.TradePrice));
|
|
|
+ // if (supplierProductstable.Rows.Any())
|
|
|
+ // {
|
|
|
+ // foreach (CoreRow row in supplierProductstable.Rows)
|
|
|
+ // {
|
|
|
+ // SupplierProduct supplierProduct = row.ToObject<SupplierProduct>();
|
|
|
+ // supplierProducts.Add(supplierProduct);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return supplierProducts;
|
|
|
+ // }
|
|
|
|
|
|
public bool ShowAll { get; set; }
|
|
|
|
|
@@ -183,10 +129,8 @@ namespace PRSDesktop
|
|
|
|
|
|
if (SelectedCategory != CoreUtils.FullGuid)
|
|
|
criteria.Add(new Filter<PurchaseOrder>(x => x.Category.ID).IsEqualTo(SelectedCategory));
|
|
|
-
|
|
|
- var cols = new Columns<PurchaseOrder>().Default(ColumnType.IncludeOptional, ColumnType.IncludeLinked, ColumnType.IncludeAggregates,
|
|
|
- ColumnType.IncludeFormulae);
|
|
|
- base.Reload(criteria, cols, ref sort, action);
|
|
|
+
|
|
|
+ base.Reload(criteria, columns, ref sort, action);
|
|
|
}
|
|
|
|
|
|
protected override void SelectItems(CoreRow[] rows)
|