public string UnPost(PhysicalInventoryHeaderDTO piHeader) { try { var itemsQuantityRepository = new Repository <ItemQuantityDTO>(_iDbContext); if (piHeader.PhysicalInventoryLines.Count == 0) { return("No Items To Post, Add Item First...."); } var validate = Validate(piHeader); if (!string.IsNullOrEmpty(validate)) { return(validate); } foreach (var line in piHeader.PhysicalInventoryLines.Where(p => p.Enabled)) { var itQty = new ItemQuantityService(_iDbContext).GetByCriteria(piHeader.WarehouseId, line.ItemId); if (line.CountedQty >= itQty.QuantityOnHand) { //donothing } if (line.CountedQty < itQty.QuantityOnHand) { itemsQuantityRepository = new Repository <ItemQuantityDTO>(_iDbContext); return("Can't Unpost"); } itQty.QuantityOnHand = line.ExpectedQty; itemsQuantityRepository.InsertUpdate(itQty); } piHeader.Status = PhysicalInventoryStatus.Draft; _piHeaderRepository.Update(piHeader); _unitOfWork.Commit(); return(string.Empty); } catch (Exception exception) { return(exception.Message); } }
public string Disable(PhysicalInventoryHeaderDTO piHeader) { if (piHeader == null) { return(GenericMessages.ObjectIsNull); } string stat; try { _piHeaderRepository.Update(piHeader); _unitOfWork.Commit(); stat = string.Empty; } catch (Exception exception) { stat = exception.Message; } return(stat); }
private void AddNewPiHeader() { if (SelectedWarehouse != null && SelectedWarehouse.Id == -1) { return; } SelectedPi = null; if (SelectedWarehouse != null) { SelectedPi = new PhysicalInventoryHeaderDTO { PhysicalInventoryDate = DateTime.Now, Status = PhysicalInventoryStatus.Draft, WarehouseId = SelectedWarehouse.Id, PhysicalInventoryNumber = _piHeaderService.GetNewPhysicalInventoryNumber(SelectedWarehouse.Id, false) }; PhysicalInventoryLines = new ObservableCollection <PhysicalInventoryLineDTO>(); } }
public PhysicalInventoryLineDTO GetNewPiLine(int warehouseId, int itemId, decimal countedQty, PhysicalInventoryLineTypes lineType) { var line = new PhysicalInventoryLineDTO(); try { var selectedItemQuantity = new ItemQuantityService(false).GetByCriteria(warehouseId, itemId); //var selectedPhysicalInventory = GetListOf(false) //.FirstOrDefault(pi => pi.WarehouseId == warehouseId && // pi.PhysicalInventoryDate.Date == DateTime.Now.Date) ?? var selectedPhysicalInventory = new PhysicalInventoryHeaderDTO { PhysicalInventoryDate = DateTime.Now, Status = PhysicalInventoryStatus.Posted, WarehouseId = warehouseId, PhysicalInventoryNumber = GetNewPhysicalInventoryNumber(warehouseId, false) }; line.PhysicalInventory = selectedPhysicalInventory; line.ItemId = itemId; line.CountedQty = countedQty; line.ExpectedQty = selectedItemQuantity != null ? selectedItemQuantity.QuantityOnHand : 0; line.PhysicalInventoryLineType = lineType; } catch { MessageBox.Show("Problem getting new pi, try again..."); return(null); } finally { //_unitOfWork.Dispose(); } return(line); }
public string Validate(PhysicalInventoryHeaderDTO piHeader) { if (null == piHeader) { return(GenericMessages.ObjectIsNull); } if (piHeader.Warehouse == null) { return("Warehouse " + GenericMessages.ObjectIsNull); } if (String.IsNullOrEmpty(piHeader.PhysicalInventoryNumber)) { return(piHeader.PhysicalInventoryNumber + " " + GenericMessages.StringIsNullOrEmpty); } if (piHeader.PhysicalInventoryNumber.Length > 50) { return(piHeader.PhysicalInventoryNumber + " can not be more than 50 characters "); } return(string.Empty); }
public bool ObjectExists(PhysicalInventoryHeaderDTO piHeader) { var objectExists = false; var iDbContext = DbContextUtil.GetDbContextInstance(); try { var catRepository = new Repository <PhysicalInventoryHeaderDTO>(iDbContext); var catExists = catRepository.Query() .Filter(bp => bp.PhysicalInventoryNumber == piHeader.PhysicalInventoryNumber && bp.Id != piHeader.Id) .Get() .FirstOrDefault(); if (catExists != null) { objectExists = true; } } finally { iDbContext.Dispose(); } return(objectExists); }
public string InsertOrUpdate(PhysicalInventoryHeaderDTO piHeader) { try { var validate = Validate(piHeader); if (!string.IsNullOrEmpty(validate)) { return(validate); } if (ObjectExists(piHeader)) { return(GenericMessages.DatabaseErrorRecordAlreadyExists); } _piHeaderRepository.InsertUpdate(piHeader); _unitOfWork.Commit(); return(string.Empty); } catch (Exception exception) { return(exception.Message); } }