/// <summary> /// This method creates a history for inventory modified /// </summary> /// <param name="inventory">the modified inventory </param> public void InsertHistoryFromInventory(Inventory inventory, Int32?dropTypeId, Int32?saleId, Int32?userId) { var inventoryHistory = new InventoryHistory(); inventoryHistory.InventoryDropTypeId = dropTypeId; inventoryHistory.SaleId = saleId; inventoryHistory.UserId = userId; inventoryHistory.CompanyId = inventory.CompanyId; inventoryHistory.AverageCosts = inventory.AverageCosts; inventoryHistory.CurrencyRateId = inventory.CurrencyRateId; inventoryHistory.DepositId = inventory.DepositId; inventoryHistory.FiscalNumber = inventory.FiscalNumber; inventoryHistory.Localization = inventory.Localization; inventoryHistory.ProductId = inventory.ProductId; inventoryHistory.Profit = inventory.Profit; inventoryHistory.MinimumRequired = inventory.MinimumRequired; inventoryHistory.RealCost = inventory.RealCost; inventoryHistory.SupplierId = inventory.SupplierId; inventoryHistory.UnitPrice = inventory.UnitPrice; inventoryHistory.LogDate = DateTime.Now; inventoryHistory.Quantity = inventory.Quantity; InsertHistory(inventoryHistory); }
public async Task <IActionResult> PutInventoryHistory([FromRoute] Guid id, [FromBody] InventoryHistory inventoryHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != inventoryHistory.InventoryHistoryId) { return(BadRequest()); } _context.Entry(inventoryHistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InventoryHistoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
protected void btnSave_Click(object sender, EventArgs e) { DataTable productList = (DataTable)Page.ViewState["ProductList"]; Inventory inv = new Inventory(); Inventory inventoryData = new Inventory(); Product prod = new Product(); InventoryRMA rma = new InventoryRMA(); InventoryHistory his = new InventoryHistory(); InventoryManager iManager = new InventoryManager(this); CompanyManager cManager = new CompanyManager(this); if (productList.Rows.Count <= 1) { ShowError(Resources.Exception.InsertProduct); return; } foreach (DataRow row in productList.Rows) { if (row.Table.Rows.IndexOf(row) != 0) { if (!CheckIfCanSale(Convert.ToInt16(row["ProductId"]), Convert.ToInt16(row["Quantity"]))) { ShowError(Resources.Exception.InvalidStockQuantity + " Linha: " + Convert.ToInt16((row.Table.Rows.IndexOf(row)) + 1).ToString()); return; } } } productList.Rows.RemoveAt(0); try { foreach (DataRow row in productList.Rows) { inv.CompanyId = Company.CompanyId; inv.DepositId = Deposit.DepositId; inv.ProductId = Convert.ToInt16(row["ProductId"]); inv.Quantity = Convert.ToInt16(row["Quantity"]); inventoryData = iManager.GetProductInventory(Company.CompanyId, inv.ProductId, inv.DepositId); if (inventoryData != null) { rma.CompanyId = inv.CompanyId; rma.DepositId = inv.DepositId; rma.ModifiedDate = DateTime.Now; rma.ProductId = inv.ProductId; rma.Quantity = inv.Quantity; rma.Substituted = false; rma.SupplierId = Convert.ToInt16(inventoryData.SupplierId); iManager.InventoryDrop(inv, inv.Quantity, (int)DropType.RMA, null); iManager.InsertStockRMA(rma); } } InSuccess(); } catch (Exception ex) { ShowError(Resources.Exception.nonSentProductToRMA); } }
public async Task <bool> Delete(InventoryHistory InventoryHistory) { await DataContext.InventoryHistory.Where(x => x.Id == InventoryHistory.Id).UpdateFromQueryAsync(x => new InventoryHistoryDAO { DeletedAt = StaticParams.DateTimeNow, UpdatedAt = StaticParams.DateTimeNow }); return(true); }
public async Task <IActionResult> PostInventoryHistory([FromBody] InventoryHistory inventoryHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.InventoryHistories.Add(inventoryHistory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetInventoryHistory", new { id = inventoryHistory.InventoryHistoryId }, inventoryHistory)); }
public async Task <InventoryHistory> Get(long Id) { InventoryHistory InventoryHistory = await DataContext.InventoryHistory.AsNoTracking() .Where(x => x.Id == Id) .Where(x => x.DeletedAt == null) .Select(x => new InventoryHistory() { Id = x.Id, InventoryId = x.InventoryId, OldSaleStock = x.OldSaleStock, SaleStock = x.SaleStock, OldAccountingStock = x.OldAccountingStock, AccountingStock = x.AccountingStock, AppUserId = x.AppUserId, AppUser = x.AppUser == null ? null : new AppUser { Id = x.AppUser.Id, Username = x.AppUser.Username, DisplayName = x.AppUser.DisplayName, Address = x.AppUser.Address, Email = x.AppUser.Email, Phone = x.AppUser.Phone, SexId = x.AppUser.SexId, Birthday = x.AppUser.Birthday, Avatar = x.AppUser.Avatar, Department = x.AppUser.Department, OrganizationId = x.AppUser.OrganizationId, Longitude = x.AppUser.Longitude, Latitude = x.AppUser.Latitude, StatusId = x.AppUser.StatusId, RowId = x.AppUser.RowId, Used = x.AppUser.Used, }, Inventory = x.Inventory == null ? null : new Inventory { Id = x.Inventory.Id, WarehouseId = x.Inventory.WarehouseId, ItemId = x.Inventory.ItemId, SaleStock = x.Inventory.SaleStock, AccountingStock = x.Inventory.AccountingStock, }, }).FirstOrDefaultAsync(); if (InventoryHistory == null) { return(null); } return(InventoryHistory); }
protected void btnConfirm_Click(object sender, EventArgs e) { Inventory inventory = new Inventory(); InventoryMoviment movement = new InventoryMoviment(); InventoryHistory history = new InventoryHistory(); InventoryManager manager = new InventoryManager(this); DropDownList cboDropType; foreach (GridViewRow row in grdRefused.Rows) { cboDropType = row.FindControl("cboDropType") as DropDownList; // //if selected value not null or empty, then delete iventory moviment and //insert a history // if (!String.IsNullOrEmpty(cboDropType.SelectedValue)) { int movementId = Convert.ToInt16(grdRefused.DataKeys[row.RowIndex]["InventoryMovementId"]); movement = manager.RetrievePendingTransfers(movementId); inventory = manager.GetProductInventory(Company.CompanyId, movement.ProductId, movement.DepositId); history.CompanyId = Company.CompanyId; history.CurrencyRateId = inventory.CurrencyRateId; history.DepositId = movement.DepositId; history.FiscalNumber = inventory.FiscalNumber; history.InventoryDropTypeId = Convert.ToInt16(cboDropType.SelectedValue); history.Localization = inventory.Localization; history.LogDate = DateTime.Now; history.MinimumRequired = inventory.MinimumRequired; history.ProductId = movement.ProductId; history.Profit = inventory.Profit; history.Quantity = movement.Quantity; history.RealCost = inventory.RealCost; history.SupplierId = inventory.SupplierId; history.UnitPrice = inventory.UnitPrice; history.UserId = User.Identity.UserId; manager.InsertHistory(history); manager.DeleteMovement(movement); grdRefused.DataBind(); } } }
public async Task <bool> Create(InventoryHistory InventoryHistory) { InventoryHistoryDAO InventoryHistoryDAO = new InventoryHistoryDAO(); InventoryHistoryDAO.Id = InventoryHistory.Id; InventoryHistoryDAO.InventoryId = InventoryHistory.InventoryId; InventoryHistoryDAO.OldSaleStock = InventoryHistory.OldSaleStock; InventoryHistoryDAO.SaleStock = InventoryHistory.SaleStock; InventoryHistoryDAO.OldAccountingStock = InventoryHistory.OldAccountingStock; InventoryHistoryDAO.AccountingStock = InventoryHistory.AccountingStock; InventoryHistoryDAO.AppUserId = InventoryHistory.AppUserId; InventoryHistoryDAO.CreatedAt = StaticParams.DateTimeNow; InventoryHistoryDAO.UpdatedAt = StaticParams.DateTimeNow; DataContext.InventoryHistory.Add(InventoryHistoryDAO); await DataContext.SaveChangesAsync(); InventoryHistory.Id = InventoryHistoryDAO.Id; await SaveReference(InventoryHistory); return(true); }
/// <summary> /// this method rollback inventoryHistory /// </summary> /// <param name="entity"></param> public void RollbackInventoryHistory(InventoryHistory entity) { //retrieve the product of Inventory Inventory inventory = GetProductInventory(entity.CompanyId, entity.ProductId, entity.DepositId); //rollback set the properties of inventoryHistory in inventory inventory.UnitPrice = entity.UnitPrice; inventory.Localization = entity.Localization; inventory.MinimumRequired = entity.MinimumRequired; inventory.RealCost = entity.RealCost; inventory.Profit = entity.Profit; inventory.FiscalNumber = entity.FiscalNumber; inventory.Quantity = entity.Quantity; inventory.AverageCosts = entity.AverageCosts.Value; DbContext.SubmitChanges(); //delete the last row of inventoryHistory DbContext.InventoryHistories.Attach(entity); DbContext.InventoryHistories.DeleteOnSubmit(entity); DbContext.SubmitChanges(); }
/// <summary> /// this method delete RMA /// </summary> /// <param name="RMAId"></param> public void DeleteRMA(int RMAId) { /* * This method performs all functions * necessary for the exclusion of an RMA */ var inventory = new Inventory(); var rma = new InventoryRMA(); var inventoryManager = new InventoryManager(this); var history = new InventoryHistory(); rma = inventoryManager.RetrieveRMA(RMAId); //retrieve the RMA by RMAId inventory = inventoryManager.GetProductInventory(rma.CompanyId, rma.ProductId, rma.DepositId); //Retrieve The Inventory //set InventotyHistory history.CompanyId = inventory.CompanyId; history.CurrencyRateId = inventory.CurrencyRateId; history.DepositId = rma.DepositId; history.FiscalNumber = inventory.FiscalNumber; history.InventoryEntryTypeId = (int)EntryType.RMA; history.Localization = inventory.Localization; history.LogDate = DateTime.Now; history.MinimumRequired = inventory.MinimumRequired; history.ProductId = rma.ProductId; history.Profit = inventory.Profit; history.Quantity = rma.Quantity; history.RealCost = inventory.RealCost; history.SupplierId = inventory.SupplierId; history.UnitPrice = inventory.UnitPrice; //set quantity and AverageCost in inventory inventory.Quantity += rma.Quantity; inventory.AverageCosts = (((inventory.Quantity * inventory.RealCost) + (rma.Quantity * inventory.RealCost)) / (inventory.Quantity + rma.Quantity)); //applay the changes inventoryManager.InsertHistory(history); DbContext.InventoryRMAs.DeleteOnSubmit(rma); DbContext.SubmitChanges(); }
public async Task <bool> Update(InventoryHistory InventoryHistory) { InventoryHistoryDAO InventoryHistoryDAO = DataContext.InventoryHistory.Where(x => x.Id == InventoryHistory.Id).FirstOrDefault(); if (InventoryHistoryDAO == null) { return(false); } InventoryHistoryDAO.Id = InventoryHistory.Id; InventoryHistoryDAO.InventoryId = InventoryHistory.InventoryId; InventoryHistoryDAO.OldSaleStock = InventoryHistory.OldSaleStock; InventoryHistoryDAO.SaleStock = InventoryHistory.SaleStock; InventoryHistoryDAO.OldAccountingStock = InventoryHistory.OldAccountingStock; InventoryHistoryDAO.AccountingStock = InventoryHistory.AccountingStock; InventoryHistoryDAO.AppUserId = InventoryHistory.AppUserId; InventoryHistoryDAO.UpdatedAt = StaticParams.DateTimeNow; await DataContext.SaveChangesAsync(); await SaveReference(InventoryHistory); return(true); }
/// <summary> /// This method creates a history for inventory modified /// </summary> /// <param name="inventory">the modified inventory </param> public void InsertHistoryFromInventory(Inventory inventory, Int32? dropTypeId, Int32? saleId, Int32? userId) { var inventoryHistory = new InventoryHistory(); inventoryHistory.InventoryDropTypeId = dropTypeId; inventoryHistory.SaleId = saleId; inventoryHistory.UserId = userId; inventoryHistory.CompanyId = inventory.CompanyId; inventoryHistory.AverageCosts = inventory.AverageCosts; inventoryHistory.CurrencyRateId = inventory.CurrencyRateId; inventoryHistory.DepositId = inventory.DepositId; inventoryHistory.FiscalNumber = inventory.FiscalNumber; inventoryHistory.Localization = inventory.Localization; inventoryHistory.ProductId = inventory.ProductId; inventoryHistory.Profit = inventory.Profit; inventoryHistory.MinimumRequired = inventory.MinimumRequired; inventoryHistory.RealCost = inventory.RealCost; inventoryHistory.SupplierId = inventory.SupplierId; inventoryHistory.UnitPrice = inventory.UnitPrice; inventoryHistory.LogDate = DateTime.Now; inventoryHistory.Quantity = inventory.Quantity; InsertHistory(inventoryHistory); }
/// <summary> /// this method transfer a product Between two deposit /// </summary> /// <param name="moviment"></param> public void TransferStockDeposit(InventoryMoviment moviment, Int32 userId) { //company Source Inventory Moviment InventoryMoviment sourceInventoryMoviment = RetrievePendingTransfers(moviment.InventoryMovementId); //company Souce Inventory Inventory sourceInventory = GetProductInventory(moviment.CompanyId, moviment.ProductId, moviment.DepositId); //company targeting Inventory Inventory destinationInventory = GetProductInventory(moviment.CompanyId, moviment.ProductId, moviment.DepositDestinationId); //insert Inventory History var history = new InventoryHistory(); history.Quantity = sourceInventory.Quantity; history.CurrencyRateId = sourceInventory.CurrencyRateId; history.FiscalNumber = sourceInventory.FiscalNumber; history.Localization = sourceInventory.Localization; history.MinimumRequired = sourceInventory.MinimumRequired; history.ProductId = sourceInventory.ProductId; history.Profit = sourceInventory.Profit; history.RealCost = sourceInventory.RealCost; history.SupplierId = sourceInventory.SupplierId; history.UnitPrice = sourceInventory.UnitPrice; history.CompanyId = moviment.CompanyId; history.DepositId = sourceInventory.DepositId; history.DestinationDepositId = moviment.DepositDestinationId; history.InventoryEntryTypeId = (int)EntryType.Transfer; history.LogDate = DateTime.Now; history.UserId = userId; //insert History InsertHistory(history); if (destinationInventory != null) { //set the new AverageCost destinationInventory.AverageCosts = ((destinationInventory.Quantity * destinationInventory.UnitPrice + sourceInventoryMoviment.Quantity * sourceInventory.UnitPrice) / (sourceInventoryMoviment.Quantity + destinationInventory.Quantity)); //set the new Quantity destinationInventory.Quantity += sourceInventoryMoviment.Quantity; } else { //insert a Inventory if the product not exists in the target inventory //set the new depositId and companyId var newInventory = new Inventory(); newInventory.CopyPropertiesFrom(sourceInventory); newInventory.DepositId = moviment.DepositDestinationId; newInventory.CompanyId = moviment.CompanyId; Insert(newInventory); } //delete Moviment DeleteMovement(moviment); //submit changes DbContext.SubmitChanges(); }
/// <summary> /// Método que insere uma linha no histórico de tranferência /// </summary> /// <param name="entity"></param> public void InsertHistory(InventoryHistory entity) { DbContext.InventoryHistories.InsertOnSubmit(entity); DbContext.SubmitChanges(); }
public async Task <ResponseModel <string> > ApproveUserRequest(RequestApproveModel entity, SecurityModel securityModel) { ResponseModel <string> response = new ResponseModel <string>(); try { var bookRequestbyUser = await _dynamodbContext.GetByIdAsync(entity.Id); var user = await _dynamoDbUserContex.GetByIdAsync(entity.UserId); var book = await _dynamoDBBookContext.GetByIdAsync(entity.BookId); bookRequestbyUser.RequestStatus = entity.Status; //Approved, Rejected await _dynamodbContext.SaveAsync(bookRequestbyUser); if (entity.Status == "Approved") { book.RemaningStock = (book.Stock - 1); book.UserDetails.Add(_mapper.Map <UserViewModel>(user)); book.librarian.IssieOn = DateTime.UtcNow; book.librarian.RenewOn = DateTime.UtcNow.AddDays(7); await _dynamoDBBookContext.SaveAsync(book); InventoryHistory invHistory = new InventoryHistory { Id = Guid.NewGuid().ToString(), BookId = entity.BookId, BookAuthor = book.BookAuthor, BookDescription = book.BookDescription, BookName = book.BookName, BookPrice = book.BookPrice, BookPublication = book.BookPublication, BookType = book.BookType, City = user.City, Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, MobileNumber = user.MobileNumber, PostCode = user.PostCode, State = user.State, Suburb = user.Suburb, UserId = entity.UserId, UserName = user.Email, librarian = new librarian { BookId = entity.BookId, IssieOn = book.librarian.IssieOn, IssueDescription = book.librarian.IssueDescription, RenewOn = book.librarian.RenewOn }, RenewOn = book.librarian.RenewOn, ReturnStatus = BookReturnStatus.Borrow }; await _dynamoDbHistoryContex.SaveAsync(invHistory); } else { bookRequestbyUser.IsReserved = false; } await _mailService.SendMail("", user.Email, "Request '" + entity.Status + "'", "Hi '" + user.FirstName + "' you request has been '" + entity.Status + "'"); response.Entity = "success"; response.Status = true; response.ReturnMessage.Add("Request has been " + entity.Status + " sucessfully."); } catch (AmazonServiceException amazon) { response.Status = false; response.ReturnMessage.Add($"Amazon error in table operation! Error: {amazon.Message}"); } catch (Exception ex) { response.Status = false; response.ReturnMessage.Add(ex.Message); } return(response); }
private async Task SaveReference(InventoryHistory InventoryHistory) { }