async void setLocation(InvWarehouse master, DebtorOfferLineClient rec) { if (api.CompanyEntity.Location) { if (master != null) { rec.locationSource = master.Locations ?? await master.LoadLocations(api); } else { rec.locationSource = null; rec.Location = null; } rec.NotifyPropertyChanged("LocationSource"); } }
async void setSerieBatchSource(DebtorOfferLineClient row) { var cache = api.CompanyEntity.GetCache(typeof(InvItem)); var invItemMaster = cache.Get(row._Item) as InvItem; if (invItemMaster == null) { return; } if (row.SerieBatches != null && row.SerieBatches.First()._Item == row._Item)/*Bind if Item changed*/ { return; } List <UnicontaBaseEntity> masters = null; if (row._Qty < 0) { masters = new List <UnicontaBaseEntity>() { invItemMaster }; } else { // We only select opens var mast = new InvSerieBatchOpen(); mast.SetMaster(invItemMaster); masters = new List <UnicontaBaseEntity>() { mast }; } var res = await api.Query <SerialToOrderLineClient>(masters, null); if (res != null && res.Length > 0) { row.SerieBatches = res; row.NotifyPropertyChanged("SerieBatches"); } }
async void setVariant(DebtorOfferLineClient rec, bool SetVariant2) { if (items == null || variants1 == null || variants2 == null) { return; } //Check for Variant2 Exist if (string.IsNullOrEmpty(api.CompanyEntity?._Variant2)) { SetVariant2 = false; } var item = (InvItem)items.Get(rec._Item); if (item != null && item._StandardVariant != null) { rec.standardVariant = item._StandardVariant; var master = (InvStandardVariant)standardVariants?.Get(item._StandardVariant); if (master == null) { return; } if (master._AllowAllCombinations) { rec.Variant1Source = (IEnumerable <InvVariant1>) this.variants1?.GetKeyStrRecords; rec.Variant2Source = (IEnumerable <InvVariant2>) this.variants2?.GetKeyStrRecords; } else { var Combinations = master.Combinations ?? await master.LoadCombinations(api); if (Combinations == null) { return; } List <InvVariant1> invs1 = null; List <InvVariant2> invs2 = null; string vr1 = null; if (SetVariant2) { vr1 = rec._Variant1; invs2 = new List <InvVariant2>(); } else { invs1 = new List <InvVariant1>(); } string LastVariant = null; var var2Value = rec._Variant2; bool hasVariantValue = (var2Value == null); foreach (var cmb in Combinations) { if (SetVariant2) { if (cmb._Variant1 == vr1 && cmb._Variant2 != null) { var v2 = (InvVariant2)variants2.Get(cmb._Variant2); invs2.Add(v2); if (var2Value == v2._Variant) { hasVariantValue = true; } } } else if (LastVariant != cmb._Variant1) { LastVariant = cmb._Variant1; var v1 = (InvVariant1)variants1.Get(cmb._Variant1); invs1.Add(v1); } } if (SetVariant2) { rec.variant2Source = invs2; if (!hasVariantValue) { rec.Variant2 = null; } } else { rec.variant1Source = invs1; } } } else { rec.variant1Source = null; rec.variant2Source = null; } if (SetVariant2) { rec.NotifyPropertyChanged("Variant2Source"); } else { rec.NotifyPropertyChanged("Variant1Source"); } }