// AJAX // Reject Department Requests public ActionResult Ajax_Reject_Department_Request(ajax_model ajax_model_data) { ajax_model ajax_data = new ajax_model { name = ajax_model_data.name, main_data = ajax_model_data.main_data, }; using (var db = new DataBaseContext()) { List <orders> order_lis = db.orders_repository.Where(or => or.staff_obj.department_obj.department_name == ajax_data.name).ToList(); foreach (orders or in order_lis) { or.order_status = "Rejected_by_Clerk"; db.SaveChanges(); } } object reply_to_client = new { key_itemname_lis = "SUCCESS", }; //Email Notification staff rep = StaffData.GetStaffByName(DepartmentData.GetRepresentativebyDepName(ajax_data.name)); string emailadd = rep.email; Task task = Task.Run(() => { EmailNotification.SendNotificationEmailToEmployee(emailadd, "New Disbursment Order Reminder", "There is a new disbursment order to your department was rejected by store clerk."); }); return(Json(reply_to_client, JsonRequestBehavior.AllowGet)); }
// Approve Department Request public ActionResult Ajax_Approve_Department_Request(ajax_model ajax_model_data) { string quantity_status = ""; int stock_level = 0; string order_id_status = ""; Dictionary <string, int> item_and_quantity_of_department = new Dictionary <string, int>(); ajax_model ajax_data = new ajax_model { name = ajax_model_data.name, main_data = ajax_model_data.main_data, }; using (var db = new DataBaseContext()) { List <orders> order_lis = db.orders_repository.Where(or => or.staff_obj.department_obj.department_name == ajax_data.name && or.order_status == "Approved_by_Head").ToList(); Dictionary <int, int> item_quantity = new Dictionary <int, int>(); List <items_warehouse> item_ware_lis = db.item_warehouses_repository.ToList(); foreach (items_warehouse temp_item in item_ware_lis) { item_quantity.Add(temp_item.item.itemId, temp_item.stock_balance); } for (int i = 0; i < order_lis.Count; i++) { orders temp_order = order_lis[i]; stock_level = item_quantity[temp_order.item_obj.itemId]; stock_level = stock_level - temp_order.proposed_quantity; order_id_status = temp_order.ordersId.ToString(); // For Stock Card item_and_quantity_of_department.Add(temp_order.item_obj.item_description, temp_order.proposed_quantity); if (stock_level < 0) { quantity_status = "OUT_OF_STOCK"; break; } else { item_quantity[temp_order.item_obj.itemId] = stock_level; } } if (quantity_status != "OUT_OF_STOCK") { foreach (KeyValuePair <int, int> data in item_quantity) { items_warehouse item_ware_obj = db.item_warehouses_repository.Where(k => k.item.itemId == data.Key).FirstOrDefault(); item_ware_obj.stock_balance = data.Value; db.SaveChanges(); quantity_status = "QUANTITY_SUFFICIENT"; // Add ACTUAL_QUANTITY and DELIVERY DATE foreach (orders temp_order in order_lis) { temp_order.actual_delivered_quantity_by_clerk = temp_order.proposed_quantity; temp_order.delivered_order_date = DateTime.Now.ToString(); db.SaveChanges(); } } // For Stock Card foreach (KeyValuePair <string, int> temp_data in item_and_quantity_of_department) { item item_obj = db.item_warehouse_repository.Where(i => i.item_description == temp_data.Key).FirstOrDefault(); // STOCK CARD UPDATE int stockbalance = StockcardData.GetStockBalanceByItemId(item_obj.itemId); stock_card stock_card_obj = new stock_card(ajax_data.name, DateTime.Now.ToString(), " - " + temp_data.Value, item_obj, stockbalance - temp_data.Value); db.stock_card_repository.Add(stock_card_obj); db.SaveChanges(); } foreach (orders temp_order in order_lis) { temp_order.order_status = "Approved_by_Clerk"; db.SaveChanges(); } } } object reply_to_client = new { item_quantity_status = quantity_status, stock_level_status = stock_level, order_identity_status = order_id_status, }; //Email Notification staff rep = StaffData.GetStaffByName(DepartmentData.GetRepresentativebyDepName(ajax_data.name)); string emailadd = rep.email; Task task = Task.Run(() => { EmailNotification.SendNotificationEmailToEmployee(emailadd, "New Disbursment Order Reminder", "There is a new disbursment order to your department was just approved by store clerk. please get ready to receive it."); }); return(Json(reply_to_client, JsonRequestBehavior.AllowGet)); }