public bool ObjectExists(ItemQuantityDTO itemQuantity) { var objectExists = false; var iDbContext = DbContextUtil.GetDbContextInstance(); try { var catRepository = new Repository <ItemQuantityDTO>(iDbContext); var catExists = catRepository.Query() .Filter(bp => (bp.WarehouseId == itemQuantity.WarehouseId && bp.ItemId == itemQuantity.ItemId) && bp.Id != itemQuantity.Id) .Get() .FirstOrDefault(); if (catExists != null) { objectExists = true; } } finally { iDbContext.Dispose(); } return(objectExists); }
public IEnumerable <ItemQuantityDTO> UpdateInventoryByTransaction(TransactionHeaderDTO transaction) { var itemsQuantityRepository = new List <ItemQuantityDTO>(); try { foreach (var line in transaction.TransactionLines.Where(t => t.Enabled)) { //var itemQty = new ItemQuantityDTO //{ // WarehouseId = transaction.WarehouseId, // ItemId = line.ItemId, // QuantityOnHand = 0 //}; var iQty = GetByCriteria(transaction.WarehouseId, line.ItemId); if (iQty == null) { iQty = new ItemQuantityDTO() { ItemId = line.ItemId, WarehouseId = transaction.WarehouseId }; } if (transaction.TransactionType == TransactionTypes.Sale) { //if (iQty == null) //if item not found in stock //make sure it should never become null //{ // return null; // "Item not found in store"; //} //if (iQty.QuantityOnHand < line.Unit) //If PostWithLessStock is not allowed //{ // return null; // // "The Store has less than " + itemQty.QuantityOnHand.ToString() + " '" + line.Item.DisplayName + "'"; //} iQty.QuantityOnHand = iQty.QuantityOnHand - line.Unit; iQty.QuantitySold = iQty.QuantitySold + line.Unit; } else if (transaction.TransactionType == TransactionTypes.Purchase) { iQty.QuantityOnHand = iQty.QuantityOnHand + line.Unit; iQty.QuantityPurchased = iQty.QuantityPurchased + line.Unit; } itemsQuantityRepository.Add(iQty); } } catch (Exception exception) { return(null); } finally { //Dispose(true); } return(itemsQuantityRepository); }
public ItemEntry(ItemQuantityDTO itemQtyDto, WarehouseDTO warehouseDto, System.Windows.Visibility itemsQtyVisibility) { ItemEntryViewModel.Errors = 0; InitializeComponent(); //TxtBlockItemsQuantity.Visibility = itemsQtyVisibility; //TxtItemsQuantity.Visibility = itemsQtyVisibility; Messenger.Default.Send <ItemQuantityDTO>(itemQtyDto); Messenger.Default.Send <WarehouseDTO>(warehouseDto); Messenger.Reset(); }
//public ItemDetail(ItemDTO itemDto) //{ // ItemDetailViewModel.Errors = 0; // InitializeComponent(); // Messenger.Default.Send<ItemDTO>(itemDto); // Messenger.Reset(); //} public ItemEntry(ItemQuantityDTO itemQtyDto, WarehouseDTO warehouseDto) { ItemEntryViewModel.Errors = 0; InitializeComponent(); //var itqtyId = itemQtyDto != null ? itemQtyDto.Id : 0; //int[] ids = { itqtyId, warehouseDto.Id }; //Messenger.Default.Send<int[]>(ids); Messenger.Default.Send <ItemQuantityDTO>(itemQtyDto); Messenger.Default.Send <WarehouseDTO>(warehouseDto); Messenger.Reset(); }
public ItemQuantityDTO GetByIq(ItemQuantityDTO itemQuantity) { var iq = GetByCriteria(itemQuantity.WarehouseId, itemQuantity.ItemId); if (iq == null) { iq = itemQuantity; iq.Item = _unitOfWork.Repository <ItemDTO>().FindById(iq.ItemId); iq.Warehouse = _unitOfWork.Repository <WarehouseDTO>().FindById(iq.WarehouseId); } else { iq.QuantityOnHand = itemQuantity.QuantityOnHand; } return(iq); }
public string Validate(ItemQuantityDTO itemQuantity) { if (null == itemQuantity) { return(GenericMessages.ObjectIsNull); } if (itemQuantity.WarehouseId == 0) { return("Warehouse Id " + GenericMessages.ObjectIsNull); } if (itemQuantity.ItemId == 0) { return("Item Id " + GenericMessages.ObjectIsNull); } return(string.Empty); }
public ItemQuantityDTO InsertOrUpdate(ItemQuantityDTO itemQuantity) { try { var itemQty = GetByIq(itemQuantity); //var validate = Validate(itemQty); //if (!string.IsNullOrEmpty(validate)) // return null; //if (ObjectExists(itemQty)) // return null; return(itemQuantity); } catch { return(null); } }
public string Disable(ItemQuantityDTO itemQuantity) { if (itemQuantity == null) { return(GenericMessages.ObjectIsNull); } string stat; try { _itemQuantityRepository.Update(itemQuantity); _unitOfWork.Commit(); stat = string.Empty; } catch (Exception exception) { stat = exception.Message; } return(stat); }
public string InsertOrUpdate(ItemQuantityDTO itemQuantity, bool insertPiLine) { try { var itemQty = GetByIq(itemQuantity); var validate = Validate(itemQty); if (!string.IsNullOrEmpty(validate)) { return(validate); } if (ObjectExists(itemQty)) { return(GenericMessages.DatabaseErrorRecordAlreadyExists); } _itemQuantityRepository.InsertUpdate(itemQty); //if (insertPiLine) //{ // var line = new PiHeaderService().GetNewPiLine(itemQty.WarehouseId, itemQty.ItemId, // itemQty.QuantityOnHand, PhysicalInventoryLineTypes.ItemEntry); // _piRepository.InsertUpdate(line); //} _unitOfWork.Commit(); return(string.Empty); } catch (Exception exception) { return(exception.Message); } }
private void ExecuteSaveItemViewCommand(object obj) { try { SelectedItem.CategoryId = SelectedCategory.Id; SelectedItem.UnitOfMeasureId = SelectedUnitOfMeasure.Id; var stat = _itemService.InsertOrUpdate(SelectedItem); if (stat == string.Empty) { SelectedItem.Number = _itemService.GetItemNumber(SelectedItem.Id); stat = _itemService.InsertOrUpdate(SelectedItem); if (stat != string.Empty) { MessageBox.Show("Can't save Number" + Environment.NewLine + stat, "Can't save", MessageBoxButton.OK, MessageBoxImage.Error); } #region Change Item Qty after adding a new PI if (QuantityEditVisibility != null && QuantityEditVisibility == "Visible" && CurrentQuantity != null && _itemPreviousQty != CurrentQuantity && SelectedWarehouse != null && SelectedWarehouse.Id != -1) { var itemQty = new ItemQuantityDTO { WarehouseId = SelectedWarehouse.Id, ItemId = SelectedItem.Id, QuantityOnHand = CurrentQuantity }; var stat2 = _itemQuantityService.InsertOrUpdate(itemQty, true); if (stat2 == string.Empty) { CloseWindow(obj); } else { MessageBox.Show( "item detail saved successfully but updating quantity failed, try again..." + Environment.NewLine + stat2, "save error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { CloseWindow(obj); } #endregion } else { MessageBox.Show("Got Problem while saving item, try again..." + Environment.NewLine + stat, "save error", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception exception) { MessageBox.Show("Problem saving Item..." + Environment.NewLine + exception.Message + Environment.NewLine + exception.InnerException); } }
public Reservations(ItemQuantityDTO itemQty) { ReservationsViewModel.Errors = 0; InitializeComponent(); Messenger.Default.Send <ItemQuantityDTO>(itemQty); }
public IEnumerable <ItemQuantityDTO> UpdateInventoryByTransaction(TransactionHeaderDTO transaction) { var itemsQuantityRepository = new List <ItemQuantityDTO>(); try { foreach (var line in transaction.TransactionLines.Where(t => t.Enabled)) { var iQty = GetByCriteria(transaction.WarehouseId, line.ItemId); if (transaction.TransactionType == TransactionTypes.SellStock || transaction.TransactionType == TransactionTypes.UseStock) { if (iQty == null) //if item not found in stock //make sure it should never become null { return(null); // "Item not found in store"; } if (iQty.QuantityOnHand < line.Unit) //If PostWithLessStock is not allowed { return(null); // "The Store has less than " + itemQty.QuantityOnHand.ToString() + " '" + line.Item.DisplayName + "'"; } iQty.QuantityOnHand = iQty.QuantityOnHand - line.Unit; itemsQuantityRepository.Add(iQty); } else if (transaction.TransactionType == TransactionTypes.RecieveStock) { if (iQty == null) { iQty = new ItemQuantityDTO() { ItemId = line.ItemId, WarehouseId = transaction.WarehouseId, QuantityOnHand = 0 }; } iQty.QuantityOnHand = iQty.QuantityOnHand + line.Unit; itemsQuantityRepository.Add(iQty); } else if (transaction.TransactionType == TransactionTypes.TransferStock) { if (transaction.ToWarehouseId == null) { return(null); } if (transaction.Status == TransactionStatus.Requested) { if (iQty == null) { iQty = new ItemQuantityDTO() { ItemId = line.ItemId, WarehouseId = transaction.WarehouseId, QuantityOnHand = 0 }; } if (iQty.QuantityOnHand < line.Unit) //If PostWithLessStock is not allowed { return(null); } iQty.QuantityOnHand = iQty.QuantityOnHand - line.Unit; itemsQuantityRepository.Add(iQty); } else if (transaction.Status == TransactionStatus.Sent) { var destWarehouse = (int)transaction.ToWarehouseId; var iQtyDest = GetByCriteria(destWarehouse, line.ItemId); if (iQtyDest == null) { iQtyDest = new ItemQuantityDTO() { ItemId = line.ItemId, WarehouseId = destWarehouse, QuantityOnHand = 0 }; } iQtyDest.QuantityOnHand = iQtyDest.QuantityOnHand + line.Unit; itemsQuantityRepository.Add(iQtyDest); } } } } catch (Exception exception) { return(null); } finally { //Dispose(true); } return(itemsQuantityRepository); }