public FirstTestClass() { Product p1 = new Product("Classic", 24, new Supplier("s1", "www.tuborg.dk")); Product p2 = new Product("Stolichnaya", 6, new Supplier("s2", "www.Stolichnaya.com")); Product p3 = new Product("Breezer", 24, new Supplier("s3", "www.breezer.dk")); Product p4 = new Product("Mokai", 24, new Supplier("s4", "www.mokaaai.dk")); Product p5 = new Product("Brugal Anejo", 6, new Supplier("s5", "www.BrugalAnejo.dk")); InventoryCount i1 = new InventoryCount(new Location(new Store("Club Retro", "Lortevej 21"), "Bar 1")); InventoryCount i2 = new InventoryCount(new Location(new Store("Club Retro", "Lortevej 22"), "Bar 2")); //InventoryCountProduct ip1 = new InventoryCountProduct(i1.Location.Id, p2.Id, 20); //InventoryCountProduct ip2 = new InventoryCountProduct(i1.Location.Id, p4.Id, 150); //InventoryCountProduct ip3 = new InventoryCountProduct(i2.Location.Id, p1.Id, 2124); _invCount = new ObservableCollection<InventoryCount>() { i1, i2 }; _invCountProduct = new ObservableCollection<InventoryCountProduct>(); _test = new ObservableCollection<Product>() { p1, p2, p3, p4, p5 }; _selectedProduct = _test[0]; _selectedInvCount = _invCount[0]; _showLocation = false; //Catalog<Product> CP = Catalog<Product>.Instance; //List<Product> LP = CP.ReadAll().Result; //int hej = LP.Count; }
/// <summary> /// Returns true if Product instances are equal /// </summary> /// <param name="other">Instance of Product to be compared</param> /// <returns>Boolean</returns> public bool Equals(Product other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Id == other.Id || Id != null && Id.Equals(other.Id) ) && ( Name == other.Name || Name != null && Name.Equals(other.Name) ) && ( InventoryCount == other.InventoryCount || InventoryCount != null && InventoryCount.Equals(other.InventoryCount) ) && ( CostPerUnit == other.CostPerUnit || CostPerUnit != null && CostPerUnit.Equals(other.CostPerUnit) )); }
public IHttpActionResult PutInventoryCount(int id, InventoryCount inventoryCount) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != inventoryCount.Id) { return(BadRequest()); } db.Entry(inventoryCount).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!InventoryCountExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (Id != null) { hashCode = hashCode * 59 + Id.GetHashCode(); } if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (InventoryCount != null) { hashCode = hashCode * 59 + InventoryCount.GetHashCode(); } if (CostPerUnit != null) { hashCode = hashCode * 59 + CostPerUnit.GetHashCode(); } return(hashCode); } }
public static InventoryCountViewModel Create(this InventoryCount inventoryCount) { var viewModel = new InventoryCountViewModel(); foreach (KeyValuePair <string, int> keyValuePair in inventoryCount.inventoryCounts) { viewModel.InventoryCounts.Add(new Tuple <string, int>(keyValuePair.Key, keyValuePair.Value)); } return(viewModel); }
public IHttpActionResult GetInventoryCount(int id) { InventoryCount inventoryCount = db.InventoryCounts.Find(id); if (inventoryCount == null) { return(NotFound()); } return(Ok(inventoryCount)); }
public IHttpActionResult PostInventoryCount(InventoryCount inventoryCount) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.InventoryCounts.Add(inventoryCount); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = inventoryCount.Id }, inventoryCount)); }
public async void CreateInventoryCountMethod() { //we make sure that we have selected a location to count if (SelectedLocation != null) { //now we make a new inventoryCount from that location and we then put it in the database InventoryCount ic = new InventoryCount(SelectedLocation); await _inventoryCountCatalog.Create(ic); //now we take that IC out again, to make sure we are working with the right id's InventoryCount ic2 = Catalog <InventoryCount> .Instance.GetList.FindLast(x => x.Location == SelectedLocation.Id && x.DateCounted >= DateTime.Now.Subtract(TimeSpan.FromSeconds(10))); //here we freeze that inventoryCount in our history class InventoryCountHistory ich = new InventoryCountHistory(ic2); await Catalog <InventoryCountHistory> .Instance.Create(ich); //We go though all the data provided by the user and checking its counted to something above 0 //this bool is for checking that data is inserted relative to the inventoryCount bool gotData = false; foreach (var i in _listForProducts) { int totalAmount = (i.BoxAmount * i.Product.AmountPerBox) + i.Amount; if (totalAmount > 0) { //here we then create a "data" row for that specific product and inventoryCount //and store it in the database InventoryCountProduct icp = new InventoryCountProduct(ic2.Id, i.Product.Id, totalAmount); await Catalog <InventoryCountProduct> .Instance.Create(icp); //we then make a frozen copy of that inventoryCount "data" and throw it in the history database InventoryCountHistoryData ichd = new InventoryCountHistoryData(ich.Id, i.Product.Name, icp.Amount, i.Product.AmountPerBox); ichd.Id = Catalog <InventoryCountProduct> .Instance.GetList. Find(x => x.InventoryCount == ic2.Id && x.Product == icp.Product).Id; await Catalog <InventoryCountHistoryData> .Instance.Create(ichd); gotData = true; } } //if no inventoryCountProduct / inventoryCountHistoryData is provided, both the inventoryCount and the record of it is deleted if (!gotData) { await Catalog <InventoryCount> .Instance.Delete(ic2.Id); await Catalog <InventoryCountHistory> .Instance.Delete(ich.Id); } OnPropertyChanged(nameof(InventoryCountHistoriesCatalog)); } }
public override string ToString() { string result = (string.Format("{0, 5} {1, 25} {2, 8:C}", SlotID, ItemName, Price)); if (InventoryCount == 0) { result += "SOLD OUT".PadLeft(10); } else { result += InventoryCount.ToString().PadLeft(10); } return(result); }
public IHttpActionResult DeleteInventoryCount(int id) { InventoryCount inventoryCount = db.InventoryCounts.Find(id); if (inventoryCount == null) { return(NotFound()); } db.InventoryCounts.Remove(inventoryCount); db.SaveChanges(); return(Ok(inventoryCount)); }
public override void ExecuteNewCommand() { IsEnabled = true; SelectedInventoryCount = null; SelectedInventoryCount = new InventoryCount(); SelectedGroupFromDetail = null; FormTitle = "Nuevo Conteo Fisico"; //ForceDetailsRefresh = true; para no mostar la lista de prod. al cargar el control if (DetailsCount != null) { DetailsCount.Clear(); } ShowDialog(new InventoryCountDetailView(), this); }
public static void AddOrUpdate(InventoryCount selectedInventoryCount) { lock (Extensions.Locker) { var db = ContextFactory.GetDBContext(); if (selectedInventoryCount.IdInventoryCountL == 0) { db.InventoryCount.Add(selectedInventoryCount); } else { db.Entry(selectedInventoryCount).State = EntityState.Modified; } } }
public static List <InventoryCount> GetNewestIc(int productId) { //the purpose is tho get the newest inventoryCount from each location, but only if the specific product was actual counted List <InventoryCount> newestIcOnEachLocation = new List <InventoryCount>(); foreach (var s in Catalog <Store> .Instance.GetList) { //we go though all the stores, and make sure we got the right store if (s.Id == Controller.Instance.StoreId) { foreach (var l in Catalog <Location> .Instance.GetList) { //we then go though all locations that is located in that store if (l.Store == s.Id) { //here we make a dummy inventoryCount, this is to make sure that we only get the newest InventoryCount icDummy = new InventoryCount(); foreach (var ic in Catalog <InventoryCount> .Instance.GetList) { //in all the inventoryCounts(IC's), if ones location, is the one we are checking, and also the date it was counted //is newer than the dummies, we come further in (dummy date when created is day 1, in year 1) if (ic.Location == l.Id && ic.DateCounted > icDummy.DateCounted) { foreach (var icp in Catalog <InventoryCountProduct> .Instance.GetList) { //here we then check if the specific IC-data matches the product, and also it matches the inventoryCounts that got approved if (icp.Product == productId && icp.InventoryCount == ic.Id) { icDummy = ic; } } } } //in the case that no inventoryCount is made, we don't want it to add the dummy to the list. //that's why we check that the dummy we are adding, have been counted after day 2 since the beginning of time if (icDummy.DateCounted > (DateTime.MinValue.Add(TimeSpan.FromDays(2)))) { newestIcOnEachLocation.Add(icDummy); } } } } } return(newestIcOnEachLocation); }
public static void Delete(InventoryCount selectedInventoryCount) { lock (Extensions.Locker) { var db = ContextFactory.GetDBContext(); if (selectedInventoryCount.IdInventoryCountL <= 0) { return; } var sic = db.InventoryCount.FirstOrDefault( ic => ic.IdInventoryCountL == selectedInventoryCount.IdInventoryCountL); if (sic != null) { db.InventoryCount.Remove(sic); } //selectedInventoryCount.ChangeEntityState(EntityState.Deleted); } }
public void TestConstructor_Id() { //Arrange InventoryCount ic1; InventoryCount ic2; InventoryCount ic3; InventoryCount ic4; InventoryCount ic5; //Act ic1 = new InventoryCount((new Location(new Store("store", "adress"), "location"))); ic2 = new InventoryCount((new Location(new Store("store", "adress"), "location"))); ic3 = new InventoryCount((new Location(new Store("store", "adress"), "location"))); ic4 = new InventoryCount((new Location(new Store("store", "adress"), "location"))); ic5 = new InventoryCount((new Location(new Store("store", "adress"), "location"))); //Assert Assert.AreEqual(ic2.Id + 1, ic3.Id, "Id dosent add up automaticly"); }
public static void Process(InventoryCount selectedInventoryCount) { lock (Extensions.Locker) { var db = ContextFactory.GetDBContext(); ContextFactory.SaveChanges(); var diferencias = ( from t0 in db.InventoryCountDetail// selectedInventoryCount.InventoryCountDetail //Conteo fisico join t1 in db.OITW_BranchArticles on t0.ItemCode equals t1.ItemCode join t2 in db.UMovements_Acc on t0.ItemCode equals t2.U_ITEMCODE where t1.WhsCode.Equals(Config.WhsCode) && (t0.Quantity - t1.OnHand1) != 0 && t0.IdInventoryCountL == selectedInventoryCount.IdInventoryCountL && (t2.U_IDMOVIMIENTO.Equals("1") || t2.U_IDMOVIMIENTO.Equals("2")) select new { itemcode = t0.ItemCode, whscode = t1.WhsCode, Acc = t2.U_CUENTA, dif = t0.Quantity - t1.OnHand1, tipo = t2.U_IDMOVIMIENTO } ).ToList(); var entradas = diferencias.Where(c => c.dif > 0 && c.tipo.Equals("1")).ToList(); var salidas = diferencias.Where(c => c.dif < 0 && c.tipo.Equals("2")).ToList(); //Crear entradas y salidas var receipt = new OIGN_GoodsReceipt() { Comments = "Ajuste Entrada por Conteo Fisico - SIGI", IdMovement = "1", ItmsGrpCod = selectedInventoryCount.ItmsGrpCod }; var issue = new OIGE_GoodsIssues() { Comments = "Ajuste de Salida por Conteo Fisico - SIGI", IdMovement = "2", ItmsGrpCod = selectedInventoryCount.ItmsGrpCod }; if (salidas.Any()) { //agregar detalles salidas.ForEach(d => { var article = db.OITM_Articles.FirstOrDefault(c => c.ItemCode == d.itemcode); issue.IGE1_GoodsIssueDetail.Add(new IGE1_GoodsIssueDetail() { ItemCode = article.ItemCode, Dscription = article.ItemName, Quantity = d.dif * -1, UnitMsr = article.InvntryUom, AcctCode = d.Acc ?? Config.DefaultAcc, }); }); db.OIGE_GoodsIssues.Add(issue); ContextFactory.SaveChanges(); } if (entradas.Any()) { //agregar detalles entradas.ForEach(d => { var article = db.OITM_Articles.FirstOrDefault(c => c.ItemCode == d.itemcode); receipt.IGN1_GoodsReceiptDetail.Add(new IGN1_GoodsReceiptDetail() { ItemCode = article.ItemCode, Dscription = article.ItemName, Quantity = d.dif, UnitMsr = article.InvntryUom, AcctCode = d.Acc ?? Config.DefaultAcc, }); }); db.OIGN_GoodsReceipt.Add(receipt); ContextFactory.SaveChanges(); } //Luego de creados lo ajustes marcar como procesado el conteo selectedInventoryCount.StateL = LocalStatus.Procesado; ContextFactory.SaveChanges(); //procesar entradas if (receipt.IGN1_GoodsReceiptDetail.Any()) { Synchronization.Synchronize(receipt); } //Procesar salida if (issue.IGE1_GoodsIssueDetail.Any()) { Synchronization.Synchronize(issue); } ContextFactory.SaveChanges(); } }
public static ObservableCollection <InventoryCountDetail> GetDetalCollection(OITB_Groups selectedGroup, InventoryCount inventory) { lock (Extensions.Locker) { var db = ContextFactory.GetDBContext(); IQueryable <OITM_Articles> dbArticles = db.OITM_Articles .OrderByDescending(p => p.TemplateL); if (selectedGroup != null) { dbArticles = dbArticles.Where(i => i.ItmsGrpCod == selectedGroup.ItmsGrpCod); } var details = ( from br in db.OITW_BranchArticles.Where(b => b.WhsCode == Config.WhsCode) join i in dbArticles on br.ItemCode equals i.ItemCode join cat in db.UCategories on i.U_categoria equals cat.Code into scategorires from scat in scategorires.DefaultIfEmpty() //Validaciones de articulos where i.InvntItem.Contains("Y") && i.validFor.Contains("Y") && br.Locked.Contains("N") // where i.ItmsGrpCod == selectedGroup.ItmsGrpCod select new { ItemCode = i.ItemCode, Dscription = i.ItemName, Quantity = br.OnHand1.HasValue? br.OnHand1.Value:0, Unit = i.InvntryUom, OnHand = br.OnHand1.HasValue? br.OnHand1.Value:0, OITM_Articles = i, Category = (scat == null? string.Empty:scat.Name), template = i.TemplateL, }).OrderByDescending(p => p.template) .ThenByDescending(c => c.Category).ThenBy(e => e.Dscription).ToList(); var branchDetails = details.Select(i => new InventoryCountDetail() { ItemCode = i.ItemCode, Dscription = i.Dscription, Quantity = i.Quantity, Unit = i.Unit, OnHand = i.OnHand, OITM_Articles = i.OITM_Articles, Category = i.Category, } ); //// Add articles with category null //var productsIds = branchDetails.Select(b => b.ItemCode).ToList(); // IQueryable<OITM_Articles> pendingItems = // dbArticles.Where(p => !productsIds.Contains(p.ItemCode) && string.IsNullOrEmpty(p.U_categoria)); //var pendingProducts = ( from br in branch.OITW_BranchArticles // join article in pendingItems on br.ItemCode equals article.ItemCode // select new InventoryCountDetail() // { // ItemCode = article.ItemCode, // Dscription = article.ItemName, // Quantity = br.OnHand1.HasValue ? br.OnHand1.Value : 0, // Unit = article.InvntryUom, // OnHand = br.OnHand1.HasValue ? br.OnHand1.Value : 0, // OITM_Articles = article, // }).ToList(); //branchDetails.AddRange(pendingProducts); inventory.InventoryCountDetail.ForEach(d => { var product = branchDetails.FirstOrDefault(i => i.ItemCode == d.ItemCode); if (product != null) { d.OnHand = product.OnHand; d.Category = product.Category; //d.Quantity = product.Quantity; d.Unit = product.Unit; //branchDetails.Remove(product); //branchDetails.Add(d); } }); if (!inventory.InventoryCountDetail.Any()) { return(new ObservableCollection <InventoryCountDetail>(branchDetails)); } else { return(new ObservableCollection <InventoryCountDetail>(inventory.InventoryCountDetail)); } } }
public static InventoryCountViewModel ConvertToInventoryViewModel(this InventoryCount model) => InventoryFactory.Create(model);