public JsonResult RemoveItem(int stationeryId) { if (Session["existinguser"] != null) { LoginDTO currentUser = (LoginDTO)Session["existinguser"]; if (currentUser.RoleId == (int)Enums.Roles.StoreClerk) { POCreateDTO poCreateDTO = (POCreateDTO)TempData["PO"]; TempData.Keep("PO"); int supplierId = poCreateDTO.SelectedItems.Single(x => x.Id == stationeryId).CategoryId; poCreateDTO.SelectedItems.Remove(poCreateDTO.SelectedItems.Single(x => x.Id == stationeryId)); if (supplierId != 0) { if (poCreateDTO.SelectedItems.Where(x => x.CategoryId == supplierId).Count() <= 0) { if (poCreateDTO.EstimatedDates.Where(x => x.Key == supplierId).Count() == 1) { poCreateDTO.EstimatedDates.Remove(poCreateDTO.EstimatedDates.Single(x => x.Key == supplierId)); } } } TempData["PO"] = poCreateDTO; return(Json(true, JsonRequestBehavior.AllowGet)); } } return(Json(false, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateSelectedSupplier(int stationeryId, int supplierId) { if (Session["existinguser"] != null) { LoginDTO currentUser = (LoginDTO)Session["existinguser"]; if (currentUser.RoleId == (int)Enums.Roles.StoreClerk) { POCreateDTO poCreateDTO = (POCreateDTO)TempData["PO"]; TempData.Keep("PO"); int oldSupplierId = poCreateDTO.SelectedItems.Single(x => x.Id == stationeryId).CategoryId; //update supplier id poCreateDTO.SelectedItems.Single(x => x.Id == stationeryId).CategoryId = supplierId; //remove estimated date if the old supplier doesn't have any more item if (poCreateDTO.SelectedItems.Where(x => x.CategoryId == oldSupplierId).Count() <= 0) { if (poCreateDTO.EstimatedDates.Where(x => x.Key == oldSupplierId).Count() == 1) { poCreateDTO.EstimatedDates.Remove(poCreateDTO.EstimatedDates.Single(x => x.Key == oldSupplierId)); } } TempData["PO"] = poCreateDTO; return(Json(true, JsonRequestBehavior.AllowGet)); } } return(Json(false, JsonRequestBehavior.AllowGet)); }
public JsonResult RaisePO(bool removeZero) { if (Session["existinguser"] != null) { LoginDTO currentUser = (LoginDTO)Session["existinguser"]; if (currentUser.RoleId == (int)Enums.Roles.StoreClerk) { POCreateDTO poCreateDTO = (POCreateDTO)TempData["PO"]; TempData.Keep("PO"); var ids = poCreateDTO.SelectedItems.Select(x => x.Id).ToList(); int zeroCount = poCreateDTO.Catalogue.Where(x => ids.Contains(x.Id)).Where(o => o.Unsubmitted == 0).Count(); if (zeroCount > 0 && removeZero == false) { return(Json(new object[] { true, "Currently, there are some stationery of Order Quantity fills as 0. Stationery with Order Quantity 0 will not raise PO. Click OK to continue raising PO for other stationeries. Click CANCEL to edit." }, JsonRequestBehavior.AllowGet)); } if (poCreateDTO.SelectedItems.Where(s => s.CategoryId != 0 && s.Status == "confirmed").Count() > 0) { PurchaseOrderService.Instance.RaisePO(poCreateDTO, currentUser.EmployeeId); TempData["PO"] = null; return(Json(new object[] { true, null }, JsonRequestBehavior.AllowGet)); } else { return(Json(new object[] { false, "Currently, there is no confirmed stationery to raise PO. Please confirm first." }, JsonRequestBehavior.AllowGet)); } } } return(Json(new object[] { false, "You don't have permission." }, JsonRequestBehavior.AllowGet)); }
public void RaisePO(POCreateDTO poCreateDTO, int createdBy) { foreach (Stationery item in poCreateDTO.SelectedItems.Where(s => s.CategoryId != 0 && s.Status == "confirmed")) { if (poCreateDTO.Catalogue.Single(c => c.Id == item.Id).Unsubmitted > 0) { PurchaseOrder po = new PurchaseOrder(); PurchaseOrderDetail pod = new PurchaseOrderDetail(); pod.StationeryId = item.Id; pod.QuantityOrdered = poCreateDTO.Catalogue.Single(c => c.Id == item.Id).Unsubmitted; if (poCreateDTO.ConfirmedPOs.Count == 0 || poCreateDTO.ConfirmedPOs.Where(x => x.SupplierId == item.CategoryId).Count() <= 0) { //if no Confirm PO for this supplier yet, create new PO po.SupplierId = item.CategoryId; po.Status = Enum.GetName(typeof(Enums.POStatus), Enums.POStatus.PENDING); po.EstDeliveryDate = poCreateDTO.EstimatedDates.Single(e => e.Key == po.SupplierId).Value; pod.PurchaseOrderId = po.Id; po.PurchaseOrderDetails.Add(pod); poCreateDTO.ConfirmedPOs.Add(po); } else { poCreateDTO.ConfirmedPOs.Single(x => x.SupplierId == item.CategoryId).PurchaseOrderDetails.Add(pod); } } } Employee employee = EmployeeRepo.Instance.FindById(createdBy); foreach (PurchaseOrder purchaseOrder in poCreateDTO.ConfirmedPOs) { purchaseOrder.EmployeeId = createdBy; PurchaseOrderService.Instance.CreatePO(purchaseOrder); EmailNotificationService.Instance.SendNotificationEmail(receipient: "*****@*****.**", subject: "Request for purchase order approval", body: "Dear Manager,\n\nStore clerk - " + employee.Name + " raised a purchase order. Please check and approve.", cc: "*****@*****.**"); } }
public ActionResult SelectSupplier() { if (Session["existinguser"] != null) { LoginDTO currentUser = (LoginDTO)Session["existinguser"]; if (currentUser.RoleId != (int)Enums.Roles.StoreClerk) { return(RedirectToAction("RedirectToClerkOrDepartmentView", "Login")); } if (TempData["PO"] == null) { return(RedirectToAction("Catalogue")); } POCreateDTO poCreateDTO = (POCreateDTO)TempData["PO"]; TempData.Keep("PO"); return(View(poCreateDTO)); } return(RedirectToAction("Index", "Login")); }
public JsonResult ConfirmItemToPO(int stationeryId, string confirmStatus) { if (Session["existinguser"] != null) { LoginDTO currentUser = (LoginDTO)Session["existinguser"]; if (currentUser.RoleId == (int)Enums.Roles.StoreClerk) { if (TempData["PO"] != null) { POCreateDTO poCreateDTO = (POCreateDTO)TempData["PO"]; TempData.Keep("PO"); poCreateDTO.SelectedItems.Single(x => x.Id == stationeryId).Status = confirmStatus; TempData["PO"] = poCreateDTO; return(Json(true, JsonRequestBehavior.AllowGet)); } return(Json(false, JsonRequestBehavior.AllowGet)); } } return(Json(false, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateEstimatedDate(DateTime estDate, int supplierId) { if (Session["existinguser"] != null) { LoginDTO currentUser = (LoginDTO)Session["existinguser"]; if (currentUser.RoleId == (int)Enums.Roles.StoreClerk) { POCreateDTO poCreateDTO = (POCreateDTO)TempData["PO"]; TempData.Keep("PO"); if (poCreateDTO.EstimatedDates.Where(x => x.Key == supplierId).Count() == 1) { poCreateDTO.EstimatedDates.Remove(poCreateDTO.EstimatedDates.Single(x => x.Key == supplierId)); } poCreateDTO.EstimatedDates.Add(new KeyValuePair <int, DateTime>(supplierId, estDate)); TempData["PO"] = poCreateDTO; return(Json(true, JsonRequestBehavior.AllowGet)); } } return(Json(false, JsonRequestBehavior.AllowGet)); }
public ActionResult Catalogue() { if (Session["existinguser"] != null) { LoginDTO currentUser = (LoginDTO)Session["existinguser"]; if (currentUser.RoleId != (int)Enums.Roles.StoreClerk) { return(RedirectToAction("RedirectToClerkOrDepartmentView", "Login")); } POCreateDTO poCreateDTO = new POCreateDTO(); if (TempData["PO"] != null) { poCreateDTO = (POCreateDTO)TempData["PO"]; TempData.Keep("PO"); } else { poCreateDTO.Catalogue = PurchaseOrderService.Instance.RetrievePurchaseOrderCatalogue().ToList(); } return(View(poCreateDTO)); } return(RedirectToAction("Index", "Login")); }
public JsonResult updateSelectList(int stationeryId, int qty, bool selectOrNot, bool selectAllSelected) { if (Session["existinguser"] != null) { LoginDTO currentUser = (LoginDTO)Session["existinguser"]; if (currentUser.RoleId == (int)Enums.Roles.StoreClerk) { POCreateDTO poCreateDTO = new POCreateDTO(); if (TempData["PO"] != null) { poCreateDTO = (POCreateDTO)TempData["PO"]; TempData.Keep("PO"); } else { poCreateDTO = new POCreateDTO(); poCreateDTO.Catalogue = PurchaseOrderService.Instance.RetrievePurchaseOrderCatalogue().ToList(); } if (selectAllSelected == false)//if show all selected is not selected { if (stationeryId == 0 && qty == 0 && selectOrNot == false) { TempData["PO"] = poCreateDTO; return(Json(this.RenderRazorViewToString("~/Views/PurchaseOrder/Catalogue_Partial.cshtml", poCreateDTO), JsonRequestBehavior.AllowGet)); } else { poCreateDTO.Catalogue.Single(x => x.Id == stationeryId).Unsubmitted = qty; if (selectOrNot) { if (poCreateDTO.SelectedItems == null) { poCreateDTO.SelectedItems = new List <Stationery>(); } if (poCreateDTO.SelectedItems.Where(x => x.Id == stationeryId).Count() <= 0) { Stationery item = StationeryService.Instance.GetStationeryById(stationeryId); item.CategoryId = 0; poCreateDTO.SelectedItems.Add(item); } } else { if (poCreateDTO != null && poCreateDTO.SelectedItems.Where(x => x.Id == stationeryId).Count() > 0) { poCreateDTO.SelectedItems.Remove(poCreateDTO.SelectedItems.Single(x => x.Id == stationeryId)); } } TempData["PO"] = poCreateDTO; return(Json(true, JsonRequestBehavior.AllowGet)); } } else { TempData["PO"] = poCreateDTO; List <PO_getPOCatalogue_Result> catalogueSelected = new List <PO_getPOCatalogue_Result>(); foreach (var item in poCreateDTO.SelectedItems) { catalogueSelected.Add(poCreateDTO.Catalogue.Single(x => x.Id == item.Id)); } POCreateDTO selectedCatalogueDTO = new POCreateDTO(); selectedCatalogueDTO.Catalogue = catalogueSelected; return(Json(this.RenderRazorViewToString("~/Views/PurchaseOrder/Catalogue_Partial.cshtml", selectedCatalogueDTO), JsonRequestBehavior.AllowGet)); } } } return(Json(false, JsonRequestBehavior.AllowGet)); }