public StationeryRequestApiModel SelectedStationeryRequest(String rid) { var resultT = from x in context.TransactionDetail where x.TransactionRef == rid select new RequestTransactionDetailApiModel { TransactionId = x.TransactionId, TransactionRef = rid, ItemId = x.ItemId, Quantity = x.Quantity, UnitPrice = x.UnitPrice }; //var resultS = from x in context.StationeryRequest // where x.RequestId == rid // select x; //StationeryRequest ss = resultS.First(); StationeryRequest ss = RetrieveReq(rid); List <RequestTransactionDetailApiModel> tt = resultT.ToList(); StationeryRequestApiModel stModel = new StationeryRequestApiModel(); stModel.RequestId = rid; stModel.RequestedBy = ss.AspNetUsers1.EmployeeName; stModel.RequestDate = ss.RequestDate; stModel.Status = ss.Status; stModel.requestTransactionDetailApiModels = tt; return(stModel); }
public ActionResult Edit(StationeryRequest requests) { string result = null; if (requests != null) { result = "data include"; string userId = User.Identity.GetUserId(); var stationery = _context.StationeryRequest.Find(requests.RequestId); var stationerytran = _context.TransactionDetail.Where(x => x.TransactionRef == requests.RequestId).ToList(); if (stationery == null) { return(HttpNotFound()); } else { //for collection date check { var dep = _context.Department.FirstOrDefault(x => x.DepartmentId == stationery.DepartmentId); if (dep.NextAvailableDate > DateTime.Now) { _context.Entry(stationery).Property("CollectionDate").CurrentValue = dep.NextAvailableDate; } else { DateTime nextMon = Next(DateTime.Today, DayOfWeek.Monday); _context.Entry(stationery).Property("CollectionDate").CurrentValue = nextMon; } } _context.Entry(stationery).Property("Status").CurrentValue = requests.Status; _context.Entry(stationery).Property("ApprovedBy").CurrentValue = userId; _context.Entry(stationery).Property("Comment").CurrentValue = requests.Comment; _context.SaveChanges(); } if (stationerytran == null) { return(HttpNotFound()); } else { foreach (TransactionDetail detail in stationerytran) { _context.Entry(detail).Property("Remarks").CurrentValue = requests.Status; } _context.SaveChanges(); } } return(Json(result, JsonRequestBehavior.AllowGet)); }
public string GenerateRequestId() { StationeryRequest lastItem = _context.StationeryRequest.OrderByDescending(m => m.RequestId).First(); string lastRequestIdWithoutPrefix = lastItem.RequestId.Substring(3, 7); int newRequestIdWithoutPrefixInt = Int32.Parse(lastRequestIdWithoutPrefix) + 1; string newRequestIdWithoutPrefixString = newRequestIdWithoutPrefixInt.ToString().PadLeft(7, '0'); string requestId = "Req" + newRequestIdWithoutPrefixString; return(requestId); }
//Approve Req public bool ApproveReq(StationeryRequestApiModel req) { string depid = GetUserDepId(req.Userid); var dep = from d in context.Department where d.DepartmentId == depid select d; Department department = dep.FirstOrDefault(); StationeryRequest stationeryRequest = RetrieveReq(req.RequestId); if (stationeryRequest != null) { stationeryRequest.ApprovedBy = req.Userid; stationeryRequest.Status = "Pending Disbursement"; DateTime nextMonday = DateTime.Today.AddDays(7 - ((int)DateTime.Today.DayOfWeek - (int)DayOfWeek.Monday)); DateTime nextAD = (DateTime)department.NextAvailableDate; //S1:postpone has expired so if the day is before friday,collection date should be set to next monday if (DateTime.Today > nextAD && DateTime.Now.DayOfWeek < DayOfWeek.Friday) { stationeryRequest.CollectionDate = nextMonday; } //S2: postpone has expired,if request is raised in Friday or after Friday,date should be set to next next monday if (DateTime.Today > nextAD && DateTime.Now.DayOfWeek > DayOfWeek.Friday) { stationeryRequest.CollectionDate = nextMonday.AddDays(7); } //S3:postpone is avaliable so if the day is before friday,collection date should be set to postpone date if (DateTime.Today < nextAD.AddDays(-3)) { stationeryRequest.CollectionDate = department.NextAvailableDate; } //S4:postpone is avaliable so if the day is before friday,collection date should be set to postpone date +7 if (nextAD.AddDays(-3) <= DateTime.Today && DateTime.Today < nextAD) { stationeryRequest.CollectionDate = nextAD.AddDays(7); } context.SaveChanges(); #region SendEmail StationeryRequest ss = RetrieveReq(req.RequestId); string recipientEmail, subject, content; //recipientEmail =ss.AspNetUsers1.Email; recipientEmail = "*****@*****.**"; subject = " Request approved!"; content = "Your Request was approved"; Email.Send(recipientEmail, subject, content); #endregion return(true); } return(false); }
public IHttpActionResult ReturnAllItem(List <ReturnToWarehouseSetApiModel> apiModels) { List <string> statusList = new List <string>(); foreach (ReturnToWarehouseSetApiModel apiModel in apiModels) { string status = "fail"; StationeryRequest stationeryRequestInDb = _context.StationeryRequest.FirstOrDefault(m => m.RequestId == apiModel.RequestId); TransactionDetail transactionDetailInDb = stationeryRequestInDb.TransactionDetail.FirstOrDefault(m => m.ItemId == apiModel.ItemId && m.Quantity == apiModel.Quantity); //moving from quantity in transit to quantity in warehouse Stationery stationeryInDb = _context.Stationery.FirstOrDefault(m => m.ItemId == transactionDetailInDb.ItemId); stationeryInDb.QuantityTransit -= apiModel.Quantity; stationeryInDb.QuantityWarehouse += apiModel.Quantity; transactionDetailInDb.Remarks = "Returned"; _context.SaveChanges(); status = "Successfully added"; statusList.Add(status); stationeryRequestInDb = _context.StationeryRequest.FirstOrDefault(m => m.RequestId == apiModel.RequestId); //Checking if all items are returned bool allReturned = true; foreach (TransactionDetail current in stationeryRequestInDb.TransactionDetail) { if (current.Remarks == "Void") { allReturned = false; break; } } if (allReturned) { stationeryRequestInDb.Status = "Returned"; Disbursement disbursementInDb = _context.Disbursement.FirstOrDefault(m => m.RequestId == apiModel.RequestId); disbursementInDb.Status = "Returned"; _context.SaveChanges(); } } return(Ok(statusList)); }
public IHttpActionResult GetReturnInfo(string itemId) { Stationery stationery = _context.Stationery.Single(xy => xy.ItemId == itemId); Stationery x = new Stationery(); TransactionDetail y = new TransactionDetail(); StationeryRequest v = new StationeryRequest(); CollectionPoint z = new CollectionPoint(); TransactionDetail trans = _context.TransactionDetail.Single(xz => xz.ItemId == itemId); ReturntoWarehouseApiViewModel model = new ReturntoWarehouseApiViewModel(); model.Description = x.Description; model.Quantity = y.Quantity; model.Department = v.DepartmentId; model.Location = z.CollectionDescription; return(Ok(model)); }
public bool VoidDisbursement(string disbno) { var disb = context.Disbursement.Where(x => x.DisbursementNo == disbno).ToList(); if (disb != null) { var onedisb = disb.First(); string reqid = onedisb.RequestId; StationeryRequest req = context.StationeryRequest.Find(reqid); if (req != null) { req.Status = "Void"; } foreach (Disbursement dd in disb) { dd.Status = "Void"; context.SaveChanges(); var transactionDetail = context.TransactionDetail.Where(x => x.TransactionRef == dd.RequestId).ToList(); if (transactionDetail != null) { foreach (TransactionDetail detail in transactionDetail) { detail.Remarks = "Void"; } } var transactionDetaildisb = context.TransactionDetail.Where(x => x.TransactionRef == dd.DisbursementId).ToList(); if (transactionDetaildisb != null) { foreach (TransactionDetail detail in transactionDetaildisb) { detail.Remarks = "Void"; } } } context.SaveChanges(); return(true); } return(false); throw new NotImplementedException(); }
public ActionResult Detail(string id) { StationeryRequest stationeryRequest = _context.StationeryRequest.Single(x => x.RequestId == id); string userId = User.Identity.GetUserId(); AspNetUsers user = _context.AspNetUsers.FirstOrDefault(m => m.Id == userId); if (user.DepartmentId == stationeryRequest.DepartmentId) { HistoryDetailViewModel detailModel = new HistoryDetailViewModel() { Request = stationeryRequest, Details = _context.TransactionDetail .Where(x => x.StationeryRequest.RequestId == stationeryRequest.RequestId).ToList() }; return(View(detailModel)); } else { return(View()); } }
public List <StationeryRequest> GetRequestList(string deptID) { List <StationeryRequest> requestlist = new List <StationeryRequest>(); SqlDataReader reader = null; try { string sql = "SELECT R.Status as Status,E.Name as Name,R.DateTime as Date,R.Id as RequestId , SUM(IR.NeededQty) AS [TotalQuantity] " + "FROM Request R,Employee E, ItemRequest IR " + "WHERE E.ID = R.EmployeeID " + "AND E.DeptID = '" + deptID + "' " + "AND R.ID = IR.RequestID " + "GROUP BY R.Status ,E.Name,R.DateTime,R.Id; "; SqlCommand cmd = new SqlCommand(sql, connection); connection.Open(); reader = cmd.ExecuteReader(); while (reader != null && reader.Read()) { StationeryRequest request = new StationeryRequest() { EmpName = (string)reader["Name"], Date = (DateTime)reader["Date"], Status = (string)reader["Status"], RequestId = (int)reader["RequestId"], TotalItem = (int)reader["TotalQuantity"] }; requestlist.Add(request); } } finally { if (reader != null) { reader.Close(); } connection.Close(); } return(requestlist); }
//Reject Req public bool RejectReq(StationeryRequestApiModel req) { StationeryRequest stationeryRequest = RetrieveReq(req.RequestId); if (stationeryRequest != null) { stationeryRequest.ApprovedBy = req.ApprovedBy; stationeryRequest.Status = "Rejected"; context.SaveChanges(); #region SendEmail StationeryRequest ss = RetrieveReq(req.RequestId); string recipientEmail, subject, content; //recipientEmail =ss.AspNetUsers1.Email; recipientEmail = "*****@*****.**"; subject = " Request rejected!"; content = "Unfortunately, your Request was rejected"; Email.Send(recipientEmail, subject, content); #endregion return(true); } return(false); }
public List <StationeryRequest> ViewPendingRequestDetails(int requestId) { List <StationeryRequest> requestlist = new List <StationeryRequest>(); SqlDataReader reader = null; try { string sql = "SELECT e.UserName as Name,i.Description,ir.NeededQty as Qty,r.ID as RequestId " + "FROM Employee e, Request r, Item i,ItemRequest ir " + "WHERE e.id = r.EmployeeID AND r.ID = ir.RequestID AND ir.ItemID = i.ID AND r.ID = @reqId"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.AddWithValue("@reqId", requestId); connection.Open(); reader = cmd.ExecuteReader(); while (reader != null && reader.Read()) { StationeryRequest request = new StationeryRequest() { EmpName = (string)reader["Name"], Description = (string)reader["Description"], TotalItem = (int)reader["Qty"], RequestId = (int)reader["RequestId"] }; requestlist.Add(request); } } finally { if (reader != null) { reader.Close(); } connection.Close(); } return(requestlist); }
public IHttpActionResult SetRetrievalList(SetStationeryRetrievalApiModel apiModelToSet) { //remove entries that are ignored apiModelToSet.ApiModelList.RemoveAll(m => m.NewQuantity == 0 && m.Remarks == ""); //This controller method will generate stationery retrieval, disbursement, stock adjustment string currentUserId = User.Identity.GetUserId(); string newRetrievalId = GenerateRetrievalId(); //create a new stationery retrieval with pending delivery StationeryRetrieval retrievalInDb = new StationeryRetrieval { RetrievalId = newRetrievalId, RetrievedBy = apiModelToSet.UserId, Date = DateTime.Today, }; _context.StationeryRetrieval.Add(retrievalInDb); _context.SaveChanges(); int newTransactionId = GenerateTransactionDetailId() - 1;//-1 to get last value, id will be increased in foreach loop //check if there is need to raise a stock adjustment, put to list to get total of each item and compare with warehouse string newStockAdjustmentId = GenerateStockAdjustmentId(); List <string> items = apiModelToSet.ApiModelList.Select(m => m.ItemId).Distinct().ToList(); Dictionary <string, StockAdjustmentValidate> stockAdjustmentDict = new Dictionary <string, StockAdjustmentValidate>(); foreach (string item in items) { stockAdjustmentDict.Add(item, new StockAdjustmentValidate()); } foreach (StationeryRetrievalApiModel current in apiModelToSet.ApiModelList) { stockAdjustmentDict[current.ItemId].RequestedQty += current.NeededQuantity.GetValueOrDefault(); stockAdjustmentDict[current.ItemId].RetrievedQty += current.NewQuantity.GetValueOrDefault(); stockAdjustmentDict[current.ItemId].WarehouseQty = _context.Stationery.Where(m => m.ItemId == current.ItemId).Select(m => m.QuantityWarehouse).FirstOrDefault(); stockAdjustmentDict[current.ItemId].Remarks += current.Remarks; } bool stockAdjustmentRequired = false; foreach (KeyValuePair <string, StockAdjustmentValidate> currentValidate in stockAdjustmentDict) { //check retrieved<requested and retrieved!=warehouse qty, means there are damaged item, will automatically raise stock adjustment if (currentValidate.Value.RetrievedQty < currentValidate.Value.RequestedQty && currentValidate.Value.RetrievedQty != currentValidate.Value.WarehouseQty) { //check if there are any stock adjustment raised, if yes it will skip as to prevent double raise bool existingItemYetApproved = false; List <StockAdjustment> stockAdjustmentNotApproved = _context.StockAdjustment.Where(m => m.ApprovedBy == null).ToList(); foreach (StockAdjustment current in stockAdjustmentNotApproved) { foreach (TransactionDetail subDetail in current.TransactionDetail) { if (subDetail.ItemId == currentValidate.Key) { existingItemYetApproved = true; break; } } if (existingItemYetApproved == true) { newTransactionId += 1; } break; } //create a stock adjustment if item does not have a stock adjustment if (existingItemYetApproved == false) { newTransactionId += 1; TransactionDetail transactionStockAdjustmentInDb = new TransactionDetail { TransactionId = newTransactionId, ItemId = currentValidate.Key, Quantity = currentValidate.Value.RetrievedQty - currentValidate.Value.WarehouseQty, Remarks = currentValidate.Value.Remarks.IsNullOrWhiteSpace() ? "Stock adjustment from Mobile" : currentValidate.Value.Remarks, TransactionRef = newStockAdjustmentId, TransactionDate = DateTime.Now, UnitPrice = _context.Stationery.FirstOrDefault(m => m.ItemId == currentValidate.Key).FirstSuppPrice, }; _context.TransactionDetail.Add(transactionStockAdjustmentInDb); _context.SaveChanges(); stockAdjustmentRequired = true; } } } if (stockAdjustmentRequired) { StockAdjustment stockAdjustmentInDb = new StockAdjustment { StockAdjId = newStockAdjustmentId, PreparedBy = currentUserId, Remarks = "Damage", Date = DateTime.Now }; _context.StockAdjustment.Add(stockAdjustmentInDb); _context.SaveChanges(); } //preparing for disbursement List <string> departmentId = apiModelToSet.ApiModelList.Select(m => m.DepartmentId).Distinct().ToList(); Dictionary <string, List <TransactionDetail> > keyTransactionList = new Dictionary <string, List <TransactionDetail> >(); foreach (string depId in departmentId) { keyTransactionList.Add(depId, new List <TransactionDetail>()); } foreach (StationeryRetrievalApiModel current in apiModelToSet.ApiModelList) { newTransactionId += 1; //create stationery TransactionDetail for retrieval TransactionDetail transactionInDb = new TransactionDetail { TransactionId = newTransactionId, ItemId = current.ItemId, Quantity = current.NewQuantity.GetValueOrDefault(), Remarks = "Retrieved", TransactionRef = newRetrievalId, TransactionDate = DateTime.Now, UnitPrice = _context.Stationery.FirstOrDefault(m => m.ItemId == current.ItemId).FirstSuppPrice, }; _context.TransactionDetail.Add(transactionInDb); _context.SaveChanges(); //minus the quantity from stock and put it to in transit Stationery stationeryInDb = _context.Stationery.FirstOrDefault(m => m.ItemId == current.ItemId); stationeryInDb.QuantityWarehouse -= transactionInDb.Quantity; stationeryInDb.QuantityTransit += transactionInDb.Quantity; ////calculate amount of stock to raise less the amount pending approval //int quantityPendingApproval = _context.TransactionDetail.Where(m => // m.TransactionRef.StartsWith("SAD-") && m.StockAdjustment.ApprovedBy.IsNullOrWhiteSpace()) // .Sum(m => m.Quantity); ////automatically raise stock adjustment if quantity different //if (current.NewQuantity != current.NeededQuantity) //{ // newTransactionId += 1; // TransactionDetail transactionStockAdjustmentInDb = new TransactionDetail // { // TransactionId = newTransactionId, // ItemId = current.ItemId, // Quantity = current.NewQuantity.GetValueOrDefault()-stationeryInDb.QuantityWarehouse+quantityPendingApproval, // Remarks = current.Remarks.IsNullOrWhiteSpace()?"Stock adjustment from Mobile":current.Remarks, // TransactionRef = newStockAdjustmentId, // TransactionDate = DateTime.Now, // UnitPrice = _context.Stationery.FirstOrDefault(m => m.ItemId == current.ItemId).FirstSuppPrice, // }; // _context.TransactionDetail.Add(transactionStockAdjustmentInDb); // _context.SaveChanges(); //} //issue a disbursement with status in transit //for disbursement (transaction ref not initialized yet newTransactionId += 1; TransactionDetail transactionDisbursementInDb = new TransactionDetail { TransactionId = newTransactionId, ItemId = current.ItemId, Quantity = current.NewQuantity.GetValueOrDefault(), Remarks = "In Transit", TransactionDate = DateTime.Now, UnitPrice = _context.Stationery.FirstOrDefault(m => m.ItemId == current.ItemId).FirstSuppPrice, }; keyTransactionList[current.DepartmentId].Add(transactionDisbursementInDb); } int newDisbIdWithoutPrefixInt = GenerateDisbursementIdSuffixOnly() - 1; //-1 to prepare for for loop, will + 1 for each loop int newDisbNoWithoutPrefixInt = GenerateDisbursementNoSuffixOnly() - 1; //-1 to prepare for for loop, will + 1 for each loop foreach (KeyValuePair <string, List <TransactionDetail> > pair in keyTransactionList) { //getting disbursementId newDisbIdWithoutPrefixInt += 1; string newDisbursementIdWithoutPrefixString = newDisbIdWithoutPrefixInt.ToString().PadLeft(6, '0'); string disbursementId = "DISB" + newDisbursementIdWithoutPrefixString; //getting disbursementNo newDisbNoWithoutPrefixInt += 1; string newDisbursementNoWithoutPrefixString = newDisbNoWithoutPrefixInt.ToString().PadLeft(5, '0'); string disbursementNo = "D" + pair.Key + newDisbursementNoWithoutPrefixString; StationeryRequest requestLinked = _context.StationeryRequest.OrderByDescending(m => m.RequestId) .FirstOrDefault(m => m.Status == "Pending Disbursement" || m.Status == "Partially Fulfilled"); Disbursement disbursementInDb = new Disbursement { DisbursementId = disbursementId, DisbursementNo = disbursementNo, DepartmentId = pair.Key, AcknowledgedBy = null, DisbursedBy = currentUserId, Date = DateTime.Now, RequestId = requestLinked.RequestId, Status = "In Transit", OTP = GenerateOTP() }; _context.Disbursement.Add(disbursementInDb); _context.SaveChanges(); //emailing the disbursement to department rep //string depRepEmail = _context.Department.FirstOrDefault(m => m.DepartmentId == pair.Key).AspNetUsers1.Email; string recipient = "*****@*****.**"; //dummy email used string title = "Disbursement is scheduled on " + requestLinked.CollectionDate; string body = "The Stationery Request " + requestLinked.RequestId + " will be issued on " + requestLinked.CollectionDate + ". Kindly use the OTP " + disbursementInDb.OTP + " to retrieve it."; Email.Send(recipient, title, body); for (int i = 0; i < pair.Value.Count; i++) { pair.Value[i].TransactionRef = disbursementId; } _context.TransactionDetail.AddRange(pair.Value); _context.SaveChanges(); } //changing stationery records that matches to In Transit List <StationeryRequest> partiallyAndPendingRequest = _context.StationeryRequest.Where(m => m.Status == "Partially Fulfilled" || m.Status == "Pending Disbursement").ToList(); for (int i = 0; i < apiModelToSet.ApiModelList.Count; i++) { for (int j = 0; j < partiallyAndPendingRequest.Count; j++) { for (int k = 0; k < partiallyAndPendingRequest[j].TransactionDetail.Count; k++) { if (apiModelToSet.ApiModelList[i].DepartmentId == partiallyAndPendingRequest[j].DepartmentId && apiModelToSet.ApiModelList[i].ItemId == partiallyAndPendingRequest[j].TransactionDetail.ElementAt(k).ItemId) { string affectedStationeryRequestId = partiallyAndPendingRequest[j].RequestId; StationeryRequest stationeryRequestedToModify = _context.StationeryRequest.FirstOrDefault(m => m.RequestId == affectedStationeryRequestId); stationeryRequestedToModify.Status = "In Transit"; _context.SaveChanges(); } } } } //foreach (StationeryRetrievalApiModel apiModel in apiModelToSet.ApiModelList) //{ // foreach (StationeryRequest stationeryRequest in partiallyAndPendingRequest) // { // foreach (TransactionDetail transactionDetail in stationeryRequest.TransactionDetail) // { // apiModelToSet.ApiModelList[i].DepartmentId == quest.DepartmentId && apiModel.ItemId == transactionDetail.ItemId) // stationeryRequest // } // } //} //Email the clerk if item is below reorder level foreach (StationeryRetrievalApiModel current in apiModelToSet.ApiModelList) { Stationery stationery = _context.Stationery.FirstOrDefault(m => m.ItemId == current.ItemId); if (stationery.QuantityWarehouse < stationery.ReorderQuantity) { string recipient = "*****@*****.**"; string title = "Item " + stationery.Description + " needs to be ordered"; string body = "The current item quantity is less than reorder level of " + stationery.ReorderQuantity + ". Kindly restock the supplies."; Email.Send(recipient, title, body); } } return(Ok()); }
public ActionResult Save(RaiseRequestViewModel[] requests) { string result = "Error! Request is incomplete!"; bool validQuantity = false; if (requests != null) { for (int i = 0; i < requests.Length; i++) { validQuantity = requests[i].Quantity > 0; if (validQuantity != true) { break; } } if (!validQuantity) { result = "Invalid input! Kindly raise a valid request."; } else { string currentUserId = User.Identity.GetUserId(); AspNetUsers currentUser = _context.AspNetUsers.First(m => m.Id == currentUserId); string newStationeryRequestId = GenerateRequestId(); if (requests != null) { StationeryRequest stationeryRequestInDb = new StationeryRequest { RequestId = newStationeryRequestId, RequestedBy = currentUserId, ApprovedBy = null, DepartmentId = currentUser.DepartmentId, Status = "Pending Approval", Comment = null, RequestDate = DateTime.Today, CollectionDate = null }; _context.StationeryRequest.Add(stationeryRequestInDb); _context.SaveChanges(); foreach (var item in requests) { decimal itemPrice = _context.Stationery.Single(m => m.ItemId == item.Description).FirstSuppPrice; TransactionDetail transactionDetailInDb = new TransactionDetail { TransactionId = GenerateTransactionDetailId(), ItemId = item.Description, Quantity = item.Quantity, Remarks = "Pending Approval", TransactionRef = newStationeryRequestId, TransactionDate = DateTime.Today, UnitPrice = itemPrice }; _context.TransactionDetail.Add(transactionDetailInDb); } _context.SaveChanges(); //Sending email to department head to approve the request //string depRepEmail = _context.Department.FirstOrDefault(m => m.DepartmentId == pair.Key).AspNetUsers1.Email; string recipient = "*****@*****.**"; //dummy email used string title = "A request by " + currentUser.EmployeeName + " is raised"; string body = "Kindly check the details for the request."; Email.Send(recipient, title, body); result = "Success! Request is complete!"; } } } else { result = "List is empty."; } return(Json(result, JsonRequestBehavior.AllowGet)); }