static async void FindOnEANVariant(DCOrderLineClient rec, QueryAPI api, Uniconta.API.DebtorCreditor.FindPrices PriceLookup) { if (PriceLookup != null && PriceLookup.UseCustomerPrices) { var found = await PriceLookup.GetCustomerPriceFromEAN(rec); if (found) { return; } } var ap = new Uniconta.API.Inventory.ReportAPI(api); var variant = await ap.GetInvVariantDetail(rec._EAN); if (variant != null) { rec.Item = variant._Item; rec.Variant1 = variant._Variant1; rec.Variant2 = variant._Variant2; rec.Variant3 = variant._Variant3; rec.Variant4 = variant._Variant4; rec.Variant5 = variant._Variant5; rec._EAN = variant._EAN; if (variant._CostPrice != 0d) { rec._CostPrice = variant._CostPrice; } } }
void SetupMaster(UnicontaBaseEntity args) { PriceLookup = null; var OrderId = Order?.RowId; dgDebtorOfferLineGrid.UpdateMaster(args); if (Order.RowId != OrderId) { PriceLookup = new Uniconta.API.DebtorCreditor.FindPrices(Order, api); } }
protected override async void LoadCacheInBackGround() { var api = this.api; var Comp = api.CompanyEntity; if (this.items == null) { this.items = Comp.GetCache(typeof(Uniconta.DataModel.InvItem)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.InvItem), api).ConfigureAwait(false); } if (Comp.ItemVariants) { if (this.standardVariants == null) { this.standardVariants = Comp.GetCache(typeof(Uniconta.DataModel.InvStandardVariant)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.InvStandardVariant), api).ConfigureAwait(false); } if (this.variants1 == null) { this.variants1 = Comp.GetCache(typeof(Uniconta.DataModel.InvVariant1)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.InvVariant1), api).ConfigureAwait(false); } if (this.variants2 == null) { this.variants2 = Comp.GetCache(typeof(Uniconta.DataModel.InvVariant2)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.InvVariant2), api).ConfigureAwait(false); } } this.employees = Comp.GetCache(typeof(Uniconta.DataModel.Employee)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.Employee), api).ConfigureAwait(false); PriceLookup = new Uniconta.API.DebtorCreditor.FindPrices(Order, api); if (this.PriceLookup != null) { var t = this.PriceLookup.ExchangeTask; this.exchangeRate = this.PriceLookup.ExchangeRate; if (this.exchangeRate == 0d && t != null) { this.exchangeRate = await t.ConfigureAwait(false); } } Dispatcher.BeginInvoke(new Action(() => { var selectedItem = dgDebtorOfferLineGrid.SelectedItem as DebtorOfferLineClient; if (selectedItem != null) { if (selectedItem.Variant1Source == null) { setVariant(selectedItem, false); } if (selectedItem.Variant2Source == null) { setVariant(selectedItem, true); } } })); }
private void SelectedItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var rec = sender as CreditorOrderLineClient; switch (e.PropertyName) { case "Item": var selectedItem = (InvItem)items?.Get(rec._Item); if (selectedItem != null) { if (selectedItem._AlternativeItem != null && selectedItem._UseAlternative == UseAlternativeItem.Always) { var altItem = (InvItem)items.Get(selectedItem._AlternativeItem); if (altItem != null && altItem._AlternativeItem == null) { rec.Item = selectedItem._AlternativeItem; return; } } var _priceLookup = this.PriceLookup; this.PriceLookup = null; // avoid that we call priceupdated in property change on Qty var Comp = api.CompanyEntity; if (selectedItem._PurchaseQty != 0d) { rec.Qty = selectedItem._PurchaseQty; } else if (Comp._PurchaseLineOne) { rec.Qty = 1d; } rec.SetItemValues(selectedItem, Comp._PurchaseLineStorage); if (_priceLookup != null) { this.PriceLookup = _priceLookup; _priceLookup.SetPriceFromItem(rec, selectedItem); } else if (selectedItem._PurchasePrice != 0 && Comp.SameCurrency(selectedItem._PurchaseCurrency, (byte)this.Order._Currency)) { rec.Price = selectedItem._PurchasePrice; } else { rec.Price = (exchangeRate == 0d) ? selectedItem._CostPrice : Math.Round(selectedItem._CostPrice * exchangeRate, 2); } if (selectedItem._StandardVariant != rec.standardVariant) { rec.Variant1 = null; rec.Variant2 = null; rec.variant2Source = null; rec.NotifyPropertyChanged("Variant2Source"); } setVariant(rec, false); TableField.SetUserFieldsFromRecord(selectedItem, rec); if (selectedItem._Blocked) { UtilDisplay.ShowErrorCode(ErrorCodes.ItemIsOnHold, null); } } break; case "Qty": if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; case "Warehouse": if (warehouse != null) { var selected = (InvWarehouse)warehouse.Get(rec._Warehouse); setLocation(selected, (CreditorOrderLineClient)rec); } break; case "Location": if (string.IsNullOrEmpty(rec._Warehouse)) { rec._Location = null; } break; case "EAN": DebtorOfferLines.FindOnEAN(rec, this.items, api, this.PriceLookup); break; case "Total": RecalculateAmount(); break; case "Variant1": if (rec._Variant1 != null) { setVariant(rec, true); } if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; case "Variant2": case "Variant3": case "Variant4": case "Variant5": if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; case "Project": if (ProjectCache != null) { var selected = (ProjectClient)ProjectCache.Get(rec._Project); setTask(selected, rec); } break; case "Task": if (string.IsNullOrEmpty(rec._Project)) { rec._Task = null; } break; } }
protected override async void LoadCacheInBackGround() { var api = this.api; var Comp = api.CompanyEntity; if (this.creditors == null) { this.creditors = Comp.GetCache(typeof(Uniconta.DataModel.Creditor)) ?? await api.LoadCache(typeof(Uniconta.DataModel.Creditor)).ConfigureAwait(false); } if (this.items == null) { this.items = Comp.GetCache(typeof(Uniconta.DataModel.InvItem)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvItem)).ConfigureAwait(false); } if (Comp.Warehouse && this.warehouse == null) { this.warehouse = await Comp.LoadCache(typeof(Uniconta.DataModel.InvWarehouse), api).ConfigureAwait(false); } if (Comp.ItemVariants) { if (this.standardVariants == null) { this.standardVariants = Comp.GetCache(typeof(Uniconta.DataModel.InvStandardVariant)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvStandardVariant)).ConfigureAwait(false); } if (this.variants1 == null) { this.variants1 = Comp.GetCache(typeof(Uniconta.DataModel.InvVariant1)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvVariant1)).ConfigureAwait(false); } if (this.variants2 == null) { this.variants2 = Comp.GetCache(typeof(Uniconta.DataModel.InvVariant2)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvVariant2)).ConfigureAwait(false); } } if (Comp.ProjectTask) { ProjectCache = Comp.GetCache(typeof(Uniconta.DataModel.Project)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.Project), api).ConfigureAwait(false); } Dispatcher.BeginInvoke(new Action(() => { var selectedItem = dgCreditorOrderLineGrid.SelectedItem as CreditorOrderLineClient; if (selectedItem != null) { if (selectedItem.Variant1Source == null) { setVariant(selectedItem, false); } if (selectedItem.Variant2Source == null) { setVariant(selectedItem, true); } } })); if (Comp.CreditorPrice) { PriceLookup = new Uniconta.API.DebtorCreditor.FindPrices(Order, api); } else if (Order._Currency != 0 && Order._Currency != Comp._CurrencyId) { exchangeRate = await api.session.ExchangeRate(Comp._CurrencyId, (Currencies)Order._Currency, BasePage.GetSystemDefaultDate(), Comp).ConfigureAwait(false); } }
static public void FindOnEAN(DCOrderLineClient rec, SQLCache Items, QueryAPI api, Uniconta.API.DebtorCreditor.FindPrices PriceLookup) { var EAN = rec._EAN; if (string.IsNullOrWhiteSpace(EAN)) { return; } var found = (from item in (InvItem[])Items.GetNotNullArray where string.Compare(item._EAN, EAN, StringComparison.CurrentCultureIgnoreCase) == 0 select item).FirstOrDefault(); if (found != null) { rec._EAN = found._EAN; rec.Item = found._Item; } else { FindOnEANVariant(rec, api, PriceLookup); } }
private void DebtorOfferLineGrid_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var rec = sender as DebtorOfferLineClient; switch (e.PropertyName) { case "Item": var selectedItem = (InvItem)items?.Get(rec._Item); if (selectedItem != null) { if (selectedItem._AlternativeItem != null && selectedItem._UseAlternative == UseAlternativeItem.Always) { var altItem = (InvItem)items.Get(selectedItem._AlternativeItem); if (altItem != null && altItem._AlternativeItem == null) { rec.Item = selectedItem._AlternativeItem; return; } } var _priceLookup = this.PriceLookup; this.PriceLookup = null; // avoid that we call priceupdated in property change on Qty if (selectedItem._SalesQty != 0d) { rec.Qty = selectedItem._SalesQty; } else if (api.CompanyEntity._OrderLineOne) { rec.Qty = 1d; } rec.SetItemValues(selectedItem); this.PriceLookup = _priceLookup; _priceLookup?.SetPriceFromItem(rec, selectedItem); if (selectedItem._StandardVariant != rec.standardVariant) { rec.Variant1 = null; rec.Variant2 = null; rec.variant2Source = null; rec.NotifyPropertyChanged("Variant2Source"); } setVariant(rec, false); TableField.SetUserFieldsFromRecord(selectedItem, rec); if (selectedItem._Blocked) { UtilDisplay.ShowErrorCode(ErrorCodes.ItemIsOnHold, null); } globalEvents?.NotifyRefreshViewer(NameOfControl, selectedItem); } break; case "Qty": if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; case "Subtotal": case "Total": RecalculateAmount(); break; case "Warehouse": if (warehouse != null) { var selected = (InvWarehouse)warehouse.Get(rec._Warehouse); setLocation(selected, rec); } break; case "Location": if (string.IsNullOrEmpty(rec._Warehouse)) { rec._Location = null; } break; case "Employee": if (rec._Employee != null) { var item = (InvItem)items?.Get(rec._Item); if (item == null || item._ItemType == (byte)Uniconta.DataModel.ItemType.Service) { var emp = (Uniconta.DataModel.Employee)employees?.Get(rec._Employee); if (emp != null && emp._CostPrice != 0d) { rec.CostPrice = emp._CostPrice; } } } break; case "EAN": FindOnEAN(rec, this.items, api, this.PriceLookup); break; case "Variant1": if (rec._Variant1 != null) { setVariant(rec, true); } if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; case "Variant2": case "Variant3": case "Variant4": case "Variant5": if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; } }
async void UnfoldBOM(DebtorOfferLineClient selectedItem, bool usePriceFromBOM) { var items = this.items; var item = (InvItem)items.Get(selectedItem._Item); if (item == null || item._ItemType < (byte)ItemType.BOM) { return; } busyIndicator.IsBusy = true; busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("LoadingMsg"); var list = await api.Query <InvBOM>(selectedItem); if (list != null && list.Length > 0) { var pl = this.PriceLookup; if (!usePriceFromBOM) { this.PriceLookup = null; } var type = dgDebtorOfferLineGrid.TableTypeUser; var Qty = selectedItem._Qty; var lst = new List <UnicontaBaseEntity>(list.Length); foreach (var bom in list) { var invJournalLine = Activator.CreateInstance(type) as DebtorOfferLineClient; invJournalLine._Date = selectedItem._Date; invJournalLine._Week = selectedItem._Week; invJournalLine._Dim1 = selectedItem._Dim1; invJournalLine._Dim2 = selectedItem._Dim2; invJournalLine._Dim3 = selectedItem._Dim3; invJournalLine._Dim4 = selectedItem._Dim4; invJournalLine._Dim5 = selectedItem._Dim5; invJournalLine._Item = bom._ItemPart; invJournalLine._Variant1 = bom._Variant1; invJournalLine._Variant2 = bom._Variant2; invJournalLine._Variant3 = bom._Variant3; invJournalLine._Variant4 = bom._Variant4; invJournalLine._Variant5 = bom._Variant5; item = (InvItem)items.Get(bom._ItemPart); if (item != null) { invJournalLine._Warehouse = bom._Warehouse ?? item._Warehouse ?? selectedItem._Warehouse; invJournalLine._Location = bom._Location ?? item._Location ?? selectedItem._Location; invJournalLine._CostPriceLine = item._CostPrice; invJournalLine.SetItemValues(item, selectedItem._Storage); invJournalLine._Qty = Math.Round(bom.GetBOMQty(Qty), item._Decimals); TableField.SetUserFieldsFromRecord(item, invJournalLine); } else { invJournalLine._Qty = Math.Round(bom.GetBOMQty(Qty), 2); } invJournalLine._Price = 0d; TableField.SetUserFieldsFromRecord(bom, invJournalLine); lst.Add(invJournalLine); } dgDebtorOfferLineGrid.PasteRows(lst); DataChaged = true; this.PriceLookup = pl; dgDebtorOfferLineGrid.SetLoadedRow(selectedItem); double _AmountEntered = 0d; if (!usePriceFromBOM) { _AmountEntered = selectedItem._Amount; } selectedItem.Price = 0; // will clear amountEntered if (!usePriceFromBOM) { selectedItem._AmountEntered = _AmountEntered; } selectedItem.Qty = 0; selectedItem.DiscountPct = 0; selectedItem.Discount = 0; selectedItem.CostPrice = 0; dgDebtorOfferLineGrid.SetModifiedRow(selectedItem); } busyIndicator.IsBusy = false; }