public HttpResponseMessage unlockStockIn(String id, Models.TrnStockIn stockIn) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var stockIns = from d in db.TrnStockIns where d.Id == Convert.ToInt32(id) select d; if (stockIns.Any()) { var updateStockIn = stockIns.FirstOrDefault(); updateStockIn.IsLocked = false; updateStockIn.UpdatedById = userId; updateStockIn.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); inventory.DeleteStockInInventory(Convert.ToInt32(id)); journal.DeleteStockInJournal(Convert.ToInt32(id)); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public HttpResponseMessage AddFolderMonitoringStockIn(List <Entities.FolderMonitoringTrnStockIn> folderMonitoringTrnStockInObjects) { try { if (folderMonitoringTrnStockInObjects.Any()) { foreach (var folderMonitoringTrnStockInObject in folderMonitoringTrnStockInObjects) { Boolean isBranchExist = false, isAccountExist = false, isArticleExist = false, isUserExist = false, isItemExist = false; var branch = from d in db.MstBranches where d.BranchCode.Equals(folderMonitoringTrnStockInObject.BranchCode) select d; if (branch.Any()) { isBranchExist = true; } List <easyfis.Entities.MstArticle> listArticles = new List <easyfis.Entities.MstArticle>(); var account = from d in db.MstAccounts where d.AccountCode.Equals(folderMonitoringTrnStockInObject.AccountCode) select d; if (account.Any()) { isAccountExist = true; var accountArticleTypes = from d in db.MstAccountArticleTypes where d.AccountId == Convert.ToInt32(account.FirstOrDefault().Id) select d; if (accountArticleTypes.Any()) { foreach (var accountArticleType in accountArticleTypes) { var articles = from d in db.MstArticles where d.ArticleTypeId == accountArticleType.ArticleTypeId && d.IsLocked == true select d; if (articles.Any()) { foreach (var articleObject in articles) { listArticles.Add(new easyfis.Entities.MstArticle() { Id = articleObject.Id, ManualArticleCode = articleObject.ManualArticleCode, Article = articleObject.Article }); } } } } } var article = from d in listArticles where d.ManualArticleCode.Equals(folderMonitoringTrnStockInObject.ArticleCode) select d; if (article.Any()) { isArticleExist = true; } var user = from d in db.MstUsers where d.UserName.Equals(folderMonitoringTrnStockInObject.UserCode) select d; if (user.Any()) { isUserExist = true; } var item = from d in db.MstArticles where d.ArticleTypeId == 1 && d.ManualArticleCode.Equals(folderMonitoringTrnStockInObject.ItemCode) && d.IsInventory == true && d.IsLocked == true select d; if (item.Any()) { isItemExist = true; } if (isBranchExist && isUserExist && isAccountExist && isArticleExist && isItemExist) { Int32 INId = 0; var currentStockIn = from d in db.TrnStockIns where d.BranchId == branch.FirstOrDefault().Id&& d.ManualINNumber.Equals(folderMonitoringTrnStockInObject.ManualINNumber) && d.IsLocked == true select d; if (currentStockIn.Any()) { INId = currentStockIn.FirstOrDefault().Id; var unlockStockIn = currentStockIn.FirstOrDefault(); unlockStockIn.IsLocked = false; unlockStockIn.UpdatedById = user.FirstOrDefault().Id; unlockStockIn.UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnStockInObject.CreatedDateTime); db.SubmitChanges(); journal.DeleteStockInJournal(INId); inventory.DeleteStockInInventory(INId); } else { var defaultINNumber = "0000000001"; var lastStockIn = from d in db.TrnStockIns.OrderByDescending(d => d.Id) where d.BranchId == branch.FirstOrDefault().Id select d; if (lastStockIn.Any()) { var INNumber = Convert.ToInt32(lastStockIn.FirstOrDefault().INNumber) + 0000000001; defaultINNumber = FillLeadingZeroes(INNumber, 10); } Data.TrnStockIn newStockIn = new Data.TrnStockIn { BranchId = branch.FirstOrDefault().Id, INNumber = defaultINNumber, INDate = Convert.ToDateTime(folderMonitoringTrnStockInObject.INDate), AccountId = account.FirstOrDefault().Id, ArticleId = article.FirstOrDefault().Id, Particulars = folderMonitoringTrnStockInObject.Remarks, ManualINNumber = folderMonitoringTrnStockInObject.ManualINNumber, IsProduced = folderMonitoringTrnStockInObject.IsProduce, PreparedById = user.FirstOrDefault().Id, CheckedById = user.FirstOrDefault().Id, ApprovedById = user.FirstOrDefault().Id, Status = null, IsPrinted = false, IsLocked = false, CreatedById = user.FirstOrDefault().Id, CreatedDateTime = Convert.ToDateTime(folderMonitoringTrnStockInObject.CreatedDateTime), UpdatedById = user.FirstOrDefault().Id, UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnStockInObject.CreatedDateTime) }; db.TrnStockIns.InsertOnSubmit(newStockIn); db.SubmitChanges(); INId = newStockIn.Id; } var unitConversion = from d in item.FirstOrDefault().MstArticleUnits where d.MstUnit.Unit.Equals(folderMonitoringTrnStockInObject.Unit) select d; if (unitConversion.Any()) { Decimal baseQuantity = folderMonitoringTrnStockInObject.Quantity * 1; if (unitConversion.FirstOrDefault().Multiplier > 0) { baseQuantity = folderMonitoringTrnStockInObject.Quantity * (1 / unitConversion.FirstOrDefault().Multiplier); } Decimal baseCost = folderMonitoringTrnStockInObject.Amount; if (baseQuantity > 0) { baseCost = folderMonitoringTrnStockInObject.Amount / baseQuantity; } Data.TrnStockInItem newStockInItem = new Data.TrnStockInItem { INId = INId, ItemId = item.FirstOrDefault().Id, Particulars = folderMonitoringTrnStockInObject.Particulars, UnitId = unitConversion.FirstOrDefault().UnitId, Quantity = folderMonitoringTrnStockInObject.Quantity, Cost = folderMonitoringTrnStockInObject.Cost, Amount = folderMonitoringTrnStockInObject.Amount, BaseUnitId = item.FirstOrDefault().UnitId, BaseQuantity = baseQuantity, BaseCost = baseCost }; db.TrnStockInItems.InsertOnSubmit(newStockInItem); db.SubmitChanges(); var stockIn = from d in db.TrnStockIns where d.Id == INId && d.IsLocked == false select d; if (stockIn.Any()) { var lockStockIn = stockIn.FirstOrDefault(); lockStockIn.IsLocked = true; lockStockIn.UpdatedById = user.FirstOrDefault().Id; lockStockIn.UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnStockInObject.CreatedDateTime); db.SubmitChanges(); journal.InsertStockInJournal(INId); inventory.InsertStockInInventory(INId); } } } } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "No data found.")); } } catch (Exception ex) { Debug.WriteLine(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }
public HttpResponseMessage UnlockStockIn(String id) { try { var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var currentUserId = currentUser.FirstOrDefault().Id; var userForms = from d in db.MstUserForms where d.UserId == currentUserId && d.SysForm.FormName.Equals("StockInDetail") select d; if (userForms.Any()) { if (userForms.FirstOrDefault().CanUnlock) { var stockIn = from d in db.TrnStockIns where d.Id == Convert.ToInt32(id) select d; if (stockIn.Any()) { if (stockIn.FirstOrDefault().IsLocked) { var unlockStockIn = stockIn.FirstOrDefault(); unlockStockIn.IsLocked = false; unlockStockIn.UpdatedById = currentUserId; unlockStockIn.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); // ===================== // Journal and Inventory // ===================== Business.Journal journal = new Business.Journal(); Business.Inventory inventory = new Business.Inventory(); if (!unlockStockIn.IsLocked) { journal.DeleteStockInJournal(Convert.ToInt32(id)); inventory.DeleteStockInInventory(Convert.ToInt32(id)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Unlocking Error. These stock in details are already unlocked.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found. These stock in details are not found in the server.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to unlock stock in.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this stock in page.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in.")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }