public ActionResult UpdateCollectionPoint(int idDisbursement, int idCollectionPt)
        {
            //int idEmployee = 4;
            int      idEmployee    = (int)Session["IdEmployee"];
            int      IdStoreClerk1 = _disbursementDAO.FindById(idDisbursement).IdDisbursedBy.GetValueOrDefault(0);//old clerk
            string   cp1           = _disbursementDAO.FindById(idDisbursement).CollectionPoint.Location;
            string   cp2           = _collectionPointDAO.Find(idCollectionPt).Location;
            Employee employee      = _employeeDAO.FindEmployeeById(idEmployee);

            bool result1 = _departmentDAO.UpdateCollectionPt(employee.CodeDepartment, idCollectionPt);
            bool result2 = _disbursementDAO.UpdateCollectionPt(idDisbursement, idCollectionPt);

            var hub           = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
            int IdStoreClerk2 = _disbursementDAO.FindById(idDisbursement).IdDisbursedBy.GetValueOrDefault(0);//new clerk

            hub.Clients.All.receiveNotification(IdStoreClerk1);
            hub.Clients.All.receiveNotification(IdStoreClerk2);
            EmailClass emailClass = new EmailClass();
            string     message    = "Hi," + _employeeDAO.FindEmployeeById(IdStoreClerk1).Name +
                                    employee.Name + "from Department " + employee.CodeDepartment + "has changed the Collection Point from " + cp1 + " to " + cp2 + ".";

            _notificationChannelDAO.CreateNotificationsToIndividual(IdStoreClerk1, (int)Session["IdEmployee"], message);
            emailClass.SendTo(_employeeDAO.FindEmployeeById(IdStoreClerk1).Email, "SSIS System Email", message);

            message = "Hi," + _employeeDAO.FindEmployeeById(IdStoreClerk2).Name +
                      employee.Name + "from Department " + employee.CodeDepartment + "has changed the Collection Point from " + cp1 + " to " + cp2 + ".";
            _notificationChannelDAO.CreateNotificationsToIndividual(IdStoreClerk2, (int)Session["IdEmployee"], message);
            emailClass.SendTo(_employeeDAO.FindEmployeeById(IdStoreClerk2).Email, "SSIS System Email", message);



            return(RedirectToAction("Home"));
        }
예제 #2
0
        public ActionResult SaveDisbursement(int[] IdItemRetrieved)
        {
            // Assume ClerkID
            int IdStoreClerk = (int)Session["IdEmployee"];

            // Get Department that seleceted same collection point as store clerk
            List <string> DClerk = _disbursementDAO.ReturnStoreClerkCP(IdStoreClerk);

            if (IdItemRetrieved.Any())
            {
                // Get IdDisbursementItem from Selecte Retrieved Item
                List <int> IdDisbursementItem = _disbursementItemDAO.GetIdByItemRetrieved(DClerk, IdItemRetrieved);
                // update disbursementitem and set status to "prepared"
                // return IdDisbursement with at lease one items have been set as "prepared"
                List <int> IdDisbursement = _disbursementItemDAO.UpdateDisbursementItem(IdDisbursementItem);
                // update disbursement and set status to "prepared"
                _disbursementDAO.UpdateDisbursement(IdDisbursement);
                // update item stock unit and available unit
                _itemDAO.UpdateItem(IdDisbursementItem);

                // update stockrecord
                _stockRecordDAO.UpdateStockRecord(IdStoreClerk, IdDisbursementItem);

                // check if stock unit is less reorder level
                bool IsLowerThanReorderLevel = _itemDAO.CheckIfLowerThanReorderLevel(IdItemRetrieved);

                if (IsLowerThanReorderLevel)
                {
                    // @Shutong: raise alert to all stockclerks, their ID are 1,2,3
                    Employee        storeclerk1 = new Employee();
                    Employee        storeclerk2 = new Employee();
                    Employee        storeclerk3 = new Employee();
                    List <Employee> clerks      = _employeeDAO.FindAllClerk();
                    if (clerks.Count >= 3)
                    {
                        storeclerk1 = clerks[0];
                        storeclerk2 = clerks[1];
                        storeclerk3 = clerks[2];
                    }

                    var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                    hub.Clients.All.receiveNotification(1);
                    hub.Clients.All.receiveNotification(2);
                    hub.Clients.All.receiveNotification(3);
                    EmailClass emailClass = new EmailClass();
                    string     message    = "The stock levels of some items are running low!";
                    _notificationChannelDAO.CreateNotificationsToGroup("Clerk", IdStoreClerk, message);
                    emailClass.SendTo(storeclerk1.Email, "SSIS System Email", message);
                    emailClass.SendTo(storeclerk2.Email, "SSIS System Email", message);
                    emailClass.SendTo(storeclerk3.Email, "SSIS System Email", message);
                }
            }
            else
            {
                return(RedirectToAction("FormRetrieve", "StoreClerk"));
            }
            return(RedirectToAction("FormRetrieve", "StoreClerk"));
        }
예제 #3
0
        public JsonResult reqId(string username)
        {
            //   if (Session["IdEmployee"] == null)
            //    return RedirectToAction("Login", "Home");

            int idEmployee = (int)Session["IdEmployee"];

            Requisition req = _requisitionDAO.CreateRequisition(idEmployee);

            //@Shutong: send notification here
            int IdHead       = _employeeDAO.FindHeadIdByIdEmployee(idEmployee);
            int IdActingHead = _employeeDAO.FindActingHeadIdByIdEmployee(idEmployee);
            var hub          = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();

            hub.Clients.All.receiveNotification(IdHead);
            EmailClass emailClass = new EmailClass();
            string     message    = "Hi Department Head," + _employeeDAO.FindEmployeeById(idEmployee).Name
                                    + "has raised a stationery requisition: " + req.IdRequisition + " on " + req.RaiseDate + ". Please kindly approve or reject it.";

            _notificationChannelDAO.CreateNotificationsToIndividual(IdHead, (int)Session["IdEmployee"], message);
            emailClass.SendTo(_employeeDAO.FindEmployeeById(IdHead).Email, "SSIS System Email", message);
            if (IdActingHead != 0)
            {
                message = "Hi Department Acting Head," + _employeeDAO.FindEmployeeById(idEmployee).Name
                          + "has raised a stationery requisition: " + req.IdRequisition + " on " + req.RaiseDate + ". Please kindly approve or reject it.";
                hub.Clients.All.receiveNotification(IdActingHead);
                _notificationChannelDAO.CreateNotificationsToIndividual(IdActingHead, (int)Session["IdEmployee"], message);
                emailClass.SendTo(_employeeDAO.FindEmployeeById(IdActingHead).Email, "SSIS System Email", message);
            }

            message = "Hi " + _employeeDAO.FindEmployeeById(idEmployee).Name + "you has raised a stationery requisition: " + req.IdRequisition + " on " + req.RaiseDate + ". Your Head/Acting Head will handle it in 5 working days.";
            hub.Clients.All.receiveNotification(idEmployee);
            _notificationChannelDAO.CreateNotificationsToIndividual(idEmployee, idEmployee, message);
            emailClass.SendTo(_employeeDAO.FindEmployeeById(idEmployee).Email, "SSIS System Email", message);
            //end of notification sending

            //replace with below

            /*            using (SqlConnection conn = new SqlConnection(connectionString))
             *          {
             *              conn.Open();
             *
             *              Random rand = new Random();
             *              int orderNum = rand.Next(10000000, 100000000);
             *
             *              string sql = @"INSERT INTO Requisitions(IdStatusCurrent,RaiseDate,HeadRemark,ApprovedDate,WithdrawlDate,IdEmployee)
             *                                  VALUES(1,GETDATE(),null,GETDATE(),GETDATE()," + idEmployee + ")";
             *
             *              SqlCommand cmdd = new SqlCommand(sql, conn);
             *
             *              cmdd.ExecuteNonQuery();
             *          }*/

            return(Json(new
            {
                result = "OK"
            }));
        }
예제 #4
0
        public void RaiseSAandNotifyBoss(DateTime date, int IdOperation, String IdDepartment, String IdSupplier, int IdStoreClerk, Item item, int qty,
                                         Employee supervisor, Employee manager)
        {
            var    hub     = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
            String message = $"Stock adjustment raised for Item ({item.Description}). Please approve/reject.";

            _stockRecordDAO.RaiseSA(date, IdOperation, IdDepartment, IdSupplier, IdStoreClerk, item.IdItem, qty);
            int notifId = _notificationDAO.CreateNotification(message);


            SupplierItem si = _supplierItemDAO.FindByItem(item);

            if (Math.Abs(qty * si.Price) > 250)
            {
                _notificationChannelDAO.SendNotification(IdStoreClerk, manager.IdEmployee, notifId, date);
                //var hub = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
                hub.Clients.All.receiveNotification(manager.IdEmployee);
                EmailClass emailClass = new EmailClass();
                emailClass.SendTo(manager.Email, "SSIS System Email", message);
            }

            else
            {
                _notificationChannelDAO.SendNotification(IdStoreClerk, supervisor.IdEmployee, notifId, date);
                hub.Clients.All.receiveNotification(supervisor.IdEmployee);
                EmailClass emailClass = new EmailClass();
                emailClass.SendTo(supervisor.Email, "SSIS System Email", message);
            }
        }
예제 #5
0
        public ActionResult ClerkSign(IEnumerable <int> disbId)
        {
            /*            if (Session["IdEmployee"] == null || (String)Session["Role"] != "StockClerk")
             *              return RedirectToAction("Login", "Home");*/

            int IdStoreClerk = 1;

            if (Session["IdEmployee"] != null)
            {
                IdStoreClerk = (int)Session["IdEmployee"];
            }

            // updates the disb's status to "Disbursed" or 7
            _disbursementDAO.UpdateStatus(disbId, 7, DateTime.Now, IdStoreClerk);

            // emails a copy / sends notification to DR and Clerk
            foreach (var di in disbId)
            {
                Disbursement targetDisbursement = _disbursementDAO.FindById(di);
                // Get Dep Rep
                Employee depRep = targetDisbursement.Department.Employees
                                  .Where(emp => emp.IdRole == 3)
                                  .FirstOrDefault();

                String message = $"Attached a copy of the acknolwedged Disbursement for {targetDisbursement.CodeDepartment} on {targetDisbursement.Date.ToString("dd/MM/yyyy")}./n" +
                                 $"Department Rep: " + depRep.Name + "/n" +
                                 $"Store Clerk: " + _employeeDAO.FindEmployeeById(IdStoreClerk).Name +
                                 $"Both achknowledged. " +
                                 "Download report at https://localhost:44304/StoreClerk/PrintDisbursementPdf?disbId=" + targetDisbursement.IdDisbursement;

                int notifId = _notificationDAO.CreateNotification(message);
                _notificationChannelDAO.SendNotification(IdStoreClerk, depRep.IdEmployee, notifId, DateTime.Now);
                _notificationChannelDAO.SendNotification(IdStoreClerk, IdStoreClerk, notifId, DateTime.Now);
                var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                hub.Clients.All.receiveNotification(depRep.IdEmployee);
                hub.Clients.All.receiveNotification(IdStoreClerk);
                EmailClass emailClass = new EmailClass();
                emailClass.SendTo(depRep.Email, "SSIS System Email", message);
                emailClass.SendTo(_employeeDAO.FindEmployeeById(IdStoreClerk).Email, "SSIS System Email", message);
            }

            return(RedirectToAction("Disbursement"));
        }
예제 #6
0
        public ActionResult Schedule(IEnumerable <int> disbIdsToSchedule, String pickDate)
        {
            /*            if (Session["IdEmployee"] == null || (String)Session["Role"] != "StockClerk")
             *              return RedirectToAction("Login", "Home");*/

            int IdStoreClerk = 1;

            if (Session["IdEmployee"] != null)
            {
                IdStoreClerk = (int)Session["IdEmployee"];
            }



            if (disbIdsToSchedule != null)
            {
                // schedule for selected date by setting the date from the form
                DateTime SDate = DateTime.ParseExact(pickDate, "yyyy-MM-dd",
                                                     System.Globalization.CultureInfo.InvariantCulture);

                _disbursementDAO.UpdateStatus(disbIdsToSchedule, 10, SDate, null);

                // add in notification here upon updating status
                foreach (var disbId in disbIdsToSchedule)
                {
                    Disbursement targetDisbursement = _disbursementDAO.FindById(disbId);
                    // Get Dep Rep
                    Employee depRep = targetDisbursement.Department.Employees
                                      .Where(emp => emp.IdRole == 3)
                                      .FirstOrDefault();

                    String message = (targetDisbursement.DisbursementItems.ToList().All(i => i.UnitIssued >= i.UnitRequested)) ?
                                     $"Your department's request will be ready for collection on {SDate.ToString("dd/MM/yyyy")}." :
                                     $"Your department's request will be ready for collection on {SDate.ToString("dd/MM/yyyy")}. " +
                                     $"We are currently unable to prepare the full quantity of requested items from your department.";

                    int notifId = _notificationDAO.CreateNotification(message);
                    _notificationChannelDAO.SendNotification(IdStoreClerk, depRep.IdEmployee, notifId, DateTime.Now);
                    var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                    hub.Clients.All.receiveNotification(depRep.IdEmployee);
                    EmailClass emailClass = new EmailClass();
                    emailClass.SendTo(depRep.Email, "SSIS System Email", message);
                }
            }

            return(RedirectToAction("Disbursement"));
        }
예제 #7
0
        //@Shutong
        public ActionResult WithdrawPO(int id)
        {
            int idEmployee = (int)Session["IdEmployee"];

            _purchaseOrderDAO.UpdateStatusToIncomplete(id);
            //@Shutong: raise notification
            var hub          = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
            int idsupervisor = _employeeDAO.FindIdByRole("Supervisor")[0];

            hub.Clients.All.receiveNotification(idsupervisor);//5 is supervisor
            EmailClass emailClass = new EmailClass();
            string     message    = "Hi Supervisor, your store clerk " + _employeeDAO.FindEmployeeById(idEmployee).Name + " has withdrawed the PO " + id;

            _notificationChannelDAO.CreateNotificationsToGroup("Supervisor", idEmployee, message);
            emailClass.SendTo(_employeeDAO.FindEmailsByRole("Supervisor")[0], "SSIS System Email", message);
            return(RedirectToAction("PurchaseOrderCart", "StoreClerk"));
        }
예제 #8
0
        public ActionResult ApproveReject(string judge, int idRequisition, string remarks)
        {
            int    id = idRequisition;
            string r  = remarks;
            string w  = r;

            if (judge.Equals("Approve"))
            {
                _requisitionDAO.UpdateApproveStatusAndRemarks(idRequisition, remarks);

                //@Shutong: send notification here
                Requisition req        = _requisitionDAO.FindRequisitionByRequisionId(idRequisition);
                int         IdEmployee = req.IdEmployee;
                var         hub        = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                hub.Clients.All.receiveNotification(IdEmployee);
                EmailClass emailClass = new EmailClass();
                string     message    = "Hi," + _employeeDAO.FindEmployeeById(IdEmployee).Name
                                        + " your requisition: " + req.IdRequisition + " raised on " + req.RaiseDate + " has been approved. Remarks: " + remarks;

                _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message);
                emailClass.SendTo(_employeeDAO.FindEmployeeById(IdEmployee).Email, "SSIS System Email", message);
                //end of notification sending
                return(RedirectToAction("PendingLists", "DepartmentHead"));
            }
            else if (judge.Equals("Reject"))
            {
                _requisitionDAO.UpdateRejectStatusAndRemarks(idRequisition, remarks);

                //@Shutong: send notification here
                Requisition req        = _requisitionDAO.FindRequisitionByRequisionId(idRequisition);
                int         IdEmployee = req.IdEmployee;
                var         hub        = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                hub.Clients.All.receiveNotification(IdEmployee);
                EmailClass emailClass = new EmailClass();
                string     message    = "Hi," + _employeeDAO.FindEmployeeById(IdEmployee).Name
                                        + " your requisition: " + req.IdRequisition + " raised on " + req.RaiseDate + " has been rejected. Remarks: " + remarks;

                _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message);
                emailClass.SendTo(_employeeDAO.FindEmployeeById(IdEmployee).Email, "SSIS System Email", message);
                //end of notification sending
                return(RedirectToAction("PendingLists", "DepartmentHead"));
            }
            return(RedirectToAction("PendingLists", "DepartmentHead"));
        }
예제 #9
0
        public JsonResult SendEmailToGroup(string role, string message)
        {
            List <string> emails = _employeeDAO.FindEmailsByRole(role);
            string        status = "Ok";

            try
            {
                foreach (string email in emails)
                {
                    EmailClass emailClass = new EmailClass();
                    emailClass.SendTo(email, "SSIS System Email", message);
                }
            }
            catch (Exception)
            {
                status = "Bad";
            }
            return(Json(status, JsonRequestBehavior.AllowGet));
        }
예제 #10
0
        public ActionResult RemoveDelegation(int idDelegation, int idEmployee)
        {
            Delegation d = _delegationDAO.RemoveDelegate(idDelegation);

            //@Shutong: send notification here
            Employee e          = _employeeDAO.FindEmployeeById(idEmployee);
            string   empName    = e.Name;
            int      IdEmployee = e.IdEmployee;
            var      hub        = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();

            hub.Clients.All.receiveNotification(IdEmployee);
            EmailClass emailClass = new EmailClass();
            string     message    = "Hi," + empName
                                    + " your delegation assignment start on " + d.StartDate + " has been canceled.";

            _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message);
            emailClass.SendTo(_employeeDAO.FindEmployeeById(IdEmployee).Email, "SSIS System Email", message);
            //end of notification sending
            return(RedirectToAction("ViewDelegations", "DepartmentHead"));
        }
        public ActionResult AcknowledgeCollection(int idDisbursement)
        {
            //int idEmployee = 4;
            int      idEmployee   = (int)Session["IdEmployee"];
            Employee employee     = _employeeDAO.FindEmployeeById(idEmployee);
            bool     result       = _disbursementDAO.AcknowledgeCollection(idDisbursement, employee.IdEmployee);
            var      hub          = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
            int      IdStoreClerk = _disbursementDAO.FindById(idDisbursement).IdDisbursedBy.GetValueOrDefault(0);

            hub.Clients.All.receiveNotification(IdStoreClerk);
            EmailClass emailClass = new EmailClass();

            if (IdStoreClerk != 0)
            {
                string message = "Hi," + _employeeDAO.FindEmployeeById(IdStoreClerk).Name + employee.Name + "from Department " + employee.CodeDepartment + "has acknowledged the disbursement received just now. Please counter sign ";
                _notificationChannelDAO.CreateNotificationsToIndividual(IdStoreClerk, (int)Session["IdEmployee"], message);
                emailClass.SendTo(_employeeDAO.FindEmployeeById(IdStoreClerk).Email, "SSIS System Email", message);
            }

            return(RedirectToAction("Home"));
        }
예제 #12
0
        public ActionResult HandlePO(string handle, List <int> purchase_ordersId, string remarks)
        {
            List <PurchaseOrder> purchaseOrders = new List <PurchaseOrder>();

            foreach (int id in purchase_ordersId)
            {
                PurchaseOrder po = _purchaseOrderDAO.FindPOById(id);
                purchaseOrders.Add(po);
            }
            if (handle == "Approve")
            {
                _purchaseOrderDAO.UpdatePOToApproved(purchaseOrders);

                foreach (PurchaseOrder po in purchaseOrders)
                {
                    var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                    hub.Clients.All.receiveNotification(po.IdStoreClerk);
                    EmailClass emailClass = new EmailClass();
                    string     message    = "Hi," + po.StoreClerk.Name + " your purchase order made with " + po.Supplier.Name + " ordered on " + po.OrderDate + " has been approved";
                    _notificationChannelDAO.CreateNotificationsToIndividual(po.StoreClerk.IdEmployee, (int)Session["IdEmployee"], message);
                    emailClass.SendTo(po.StoreClerk.Email, "SSIS System Email", message);
                }
            }
            else
            {
                _purchaseOrderDAO.UpdatePOToRejected(purchaseOrders, remarks);

                foreach (PurchaseOrder po in purchaseOrders)
                {
                    var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                    hub.Clients.All.receiveNotification(po.IdStoreClerk);
                    EmailClass emailClass = new EmailClass();
                    string     message    = "Hi," + po.StoreClerk.Name + " your purchase order made with " + po.Supplier.Name + " ordered on " + po.OrderDate + " has been reject +/n" +
                                            "Reasons: " + po.PurchaseRemarks;
                    _notificationChannelDAO.CreateNotificationsToIndividual(po.StoreClerk.IdEmployee, (int)Session["IdEmployee"], message);
                    emailClass.SendTo(po.StoreClerk.Email, "SSIS System Email", message);
                }
            }
            return(RedirectToAction("PurchaseOrder", "StoreSupervisor"));
        }
예제 #13
0
        public ActionResult JudgeAdjustment(string judge, List <int> vouchersId)
        {
            List <StockRecord> vouchers = new List <StockRecord>();

            foreach (int id in vouchersId)
            {
                StockRecord voucher = _stockRecordDAO.FindById(id);
                vouchers.Add(voucher);
            }
            if (judge == "Approve")
            {
                _stockRecordDAO.UpdateVoucherToApproved(vouchers);

                foreach (StockRecord sr in vouchers)
                {
                    var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                    hub.Clients.All.receiveNotification(sr.IdStoreClerk);
                    EmailClass emailClass = new EmailClass();
                    string     message    = "Hi," + sr.StoreClerk.Name + " your stock adjustment voucher for (" + sr.Operation.Label.Split('-')[1] + ") " + sr.Unit + " " + sr.Item.unitOfMeasure + sr.Item.Description + " raised on " + sr.Date + " has been approved.";

                    _notificationChannelDAO.CreateNotificationsToIndividual(sr.StoreClerk.IdEmployee, (int)Session["IdEmployee"], message);
                    emailClass.SendTo(sr.StoreClerk.Email, "SSIS System Email", message);
                }
            }
            else
            {
                _stockRecordDAO.UpdateVoucherToRejected(vouchers);
                foreach (StockRecord sr in vouchers)
                {
                    var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                    hub.Clients.All.receiveNotification(sr.IdStoreClerk);
                    EmailClass emailClass = new EmailClass();
                    string     message    = "Hi," + sr.StoreClerk.Name + " your stock adjustment voucher for (" + sr.Operation.Label.Split('-')[1] + ") " + sr.Unit + " " + sr.Item.unitOfMeasure + sr.Item.Description + " raised on " + sr.Date + " has been rejected.";

                    _notificationChannelDAO.CreateNotificationsToIndividual(sr.StoreClerk.IdEmployee, (int)Session["IdEmployee"], message);
                    emailClass.SendTo(sr.StoreClerk.Email, "SSIS System Email", message);
                }
            }
            return(RedirectToAction("Voucher", "StoreManager"));
        }
예제 #14
0
        public ActionResult DeactivateDelegation(int idDelegation, int idEmployee)
        {
            // set the end date to today's date
            //_delegationDAO.DeactivateDelegationById(idEmployee);
            Delegation d = _delegationDAO.DeactivateDelegationByDelegationId(idDelegation);

            //@Shutong: send notification here
            Employee e          = _employeeDAO.FindEmployeeById(idEmployee);
            string   empName    = e.Name;
            int      IdEmployee = e.IdEmployee;
            var      hub        = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();

            hub.Clients.All.receiveNotification(IdEmployee);
            EmailClass emailClass = new EmailClass();
            string     message    = "Hi," + empName
                                    + " Thanks for approving stationery requisition on behalf of me! "
                                    + " Well done. I will now approve on my own.";

            _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message);
            emailClass.SendTo(_employeeDAO.FindEmployeeById(IdEmployee).Email, "SSIS System Email", message);
            //end of notification sending

            return(RedirectToAction("ViewDelegations", "DepartmentHead"));
        }
예제 #15
0
        public ActionResult PostDelegation(string emp, string cp, string judge, string StartDate, string EndDate)
        {
            int    idDepartmentHead = ((int)Session["IdEmployee"]);
            string submit           = judge;
            string empName          = emp;
            string remarks          = cp; // for notification
            string s1 = StartDate;
            string s2 = EndDate;

            if (submit.Equals("Back"))
            {
                Debug.WriteLine("Back");
                return(RedirectToAction("ViewDelegations", "DepartmentHead"));
            }
            else if (submit.Equals("Approve Delegate"))
            {
                Debug.WriteLine("Approve");
                // First check if they are null
                if (empName != null && !string.IsNullOrEmpty(s1) && !string.IsNullOrEmpty(s2))
                {
                    DateTime SDate = DateTime.ParseExact(s1, "dd-MM-yyyy",
                                                         System.Globalization.CultureInfo.InvariantCulture);
                    DateTime EDate = DateTime.ParseExact(s2, "dd-MM-yyyy",
                                                         System.Globalization.CultureInfo.InvariantCulture);
                    // Find the emp by empName--> change emp role to idRole=4, get employee Id, pass id and startdate, end date into delegation
                    if (EDate >= SDate)
                    {
                        // approve delegation
                        // add one day
                        EDate = EDate.AddDays(1);
                        Delegation d = _delegationDAO.CreateDelegation(empName, SDate, EDate);
                        //@Shutong: send notification to acting head
                        Employee e          = _employeeDAO.FindEmployeeByName(empName);
                        int      IdEmployee = e.IdEmployee;
                        var      hub        = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                        hub.Clients.All.receiveNotification(IdEmployee);
                        EmailClass emailClass = new EmailClass();
                        string     message    = "Hi," + empName
                                                + " You are delegated to Acting Department Head from " + d.StartDate + " to " + d.EndDate
                                                + " to assist approve stationery requisition. \r\nRemarks: " + remarks;

                        _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message);
                        emailClass.SendTo(_employeeDAO.FindEmployeeById(IdEmployee).Email, "SSIS System Email", message);
                        //end of notification sending

                        //@Shutong: send notification head who delegating acting head
                        Employee headDept = _employeeDAO.FindEmployeeById(idDepartmentHead);
                        hub.Clients.All.receiveNotification(idDepartmentHead);
                        message = "Hi," + headDept.Name
                                  + " You have delegated " + empName + " as Acting Department Head from " + d.StartDate.ToString() + " to " + d.EndDate.ToString()
                                  + " to assist approve stationery requisition. \r\nRemarks: " + remarks;

                        _notificationChannelDAO.CreateNotificationsToIndividual(idDepartmentHead, (int)Session["IdEmployee"], message);
                        emailClass.SendTo(_employeeDAO.FindEmployeeById(idDepartmentHead).Email, "SSIS System Email", message);
                        //end of notification sending
                    }
                    else
                    {
                        ModelState.AddModelError("", "The end date should be later than startdate.");

                        string          codeDepartment = _departmentDAO.FindCodeDepartmentByIdEmployee((int)Session["IdEmployee"]);
                        List <Employee> empList        = _employeeDAO.FindEmployeeListByDepartmentAndRole(codeDepartment);
                        ViewBag.EmployeeList = empList;
                        return(View("Delegation"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The fields are invalid.");

                    string          codeDepartment = _departmentDAO.FindCodeDepartmentByIdEmployee((int)Session["IdEmployee"]);
                    List <Employee> empList        = _employeeDAO.FindEmployeeListByDepartmentAndRole(codeDepartment);
                    ViewBag.EmployeeList = empList;
                    return(View("Delegation"));
                }
                return(RedirectToAction("ViewDelegations", "DepartmentHead"));
            }
            return(RedirectToAction("ViewDelegations", "DepartmentHead"));
            //int idDepartmentHead=((int)Session["IdEmployee"]);
            //string submit = judge;
            //string empName = emp;
            //string remarks = cp; // for notification
            //string s1 = StartDate;
            //string s2 = EndDate;
            //if (submit.Equals("Back"))
            //{
            //    return RedirectToAction("ViewDelegations", "DepartmentHead");
            //}
            //else if (submit.Equals("Approve Delegate"))
            //{
            //    // First check if they are null
            //    if(empName!=null && !string.IsNullOrEmpty(s1) && !string.IsNullOrEmpty(s2) )
            //    {
            //        DateTime SDate = DateTime.ParseExact(s1, "dd-MM-yyyy",
            //                   System.Globalization.CultureInfo.InvariantCulture);
            //        DateTime EDate = DateTime.ParseExact(s2, "dd-MM-yyyy",
            //                        System.Globalization.CultureInfo.InvariantCulture);
            //        // Find the emp by empName--> change emp role to idRole=4, get employee Id, pass id and startdate, end date into delegation
            //        if (EDate >= SDate)
            //        {
            //            // approve delegation
            //            // add one day
            //            EDate = EDate.AddDays(1);
            //            _employeeDAO.DelegateEmployeeToActingRole(empName);
            //            _delegationDAO.UpdateDelegation(empName, SDate, EDate);

            //            //@Shutong: send notification to acting head
            //            Employee e = _employeeDAO.FindEmployeeByName(empName);
            //            int IdEmployee = e.IdEmployee;
            //            Delegation d = _delegationDAO.FindDelegationById(IdEmployee);
            //            var hub = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
            //            hub.Clients.All.receiveNotification(IdEmployee);
            //            EmailClass emailClass = new EmailClass();
            //            string message = "Hi," + empName
            //                + " You are delegated to Acting Department Head from " + d.StartDate + " to " + d.EndDate
            //                + " to assist approve stationery requisition. \r\nRemarks: "+remarks;

            //            _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message);
            //            emailClass.SendTo(_employeeDAO.FindEmployeeById(IdEmployee).Email, "SSIS System Email", message);
            //            //end of notification sending

            //            //@Shutong: send notification head who delegating acting head
            //            Employee headDept = _employeeDAO.FindEmployeeById(idDepartmentHead);
            //            hub.Clients.All.receiveNotification(idDepartmentHead);
            //            message = "Hi," + headDept.Name
            //                + " You have delegated "+empName+" as Acting Department Head from " + d.StartDate.ToString() + " to " + d.EndDate.ToString()
            //                + " to assist approve stationery requisition. \r\nRemarks: " + remarks;

            //            _notificationChannelDAO.CreateNotificationsToIndividual(idDepartmentHead, (int)Session["IdEmployee"], message);
            //            emailClass.SendTo(_employeeDAO.FindEmployeeById(idDepartmentHead).Email, "SSIS System Email", message);
            //            //end of notification sending

            //        }
            //    }
            //    return RedirectToAction("ViewDelegations", "DepartmentHead");
            //}
            //return RedirectToAction("ViewDelegations", "DepartmentHead");
        }
예제 #16
0
        public ActionResult RefreshDisbursement(IEnumerable <int> disbId, IList <int> disbItemId, IList <int> qtyDisbursed)
        {
            /*            if (Session["IdEmployee"] == null || (String)Session["Role"] != "StockClerk")
             *   return RedirectToAction("Login", "Home");*/

            int IdStoreClerk = 1;

            if (Session["IdEmployee"] != null)
            {
                IdStoreClerk = (int)Session["IdEmployee"];
            }



            Disbursement targetDisbursement = _disbursementDAO.FindById(disbId.First());

            ViewBag.disb = targetDisbursement;
            List <DisbursementItem> targetList = targetDisbursement.DisbursementItems.ToList();
            Employee sup = _employeeDAO.FindByRole(7).FirstOrDefault();
            Employee man = _employeeDAO.FindByRole(6).FirstOrDefault();

            // if qtyDisbursed < disbItem.UnitIssued then raise a SA-broken and a reversal entry to qtyDisbursed
            for (int i = 0; i < targetList.Count; i++)
            {
                if (qtyDisbursed[i] < targetList[i].UnitIssued)
                {
                    _stockRecordDAO.StockAdjustmentDuringDisbursement(qtyDisbursed[i], targetList[i], IdStoreClerk);
                    // reverses the amount disbursed to the department
                    // commented out as net = 0 diff
                    //_itemDAO.UpdateUnits(targetList[i].Item, -(targetList[i].UnitIssued - qtyDisbursed[i]));
                    //_itemDAO.UpdateUnits(targetList[i].Item, (targetList[i].UnitIssued - qtyDisbursed[i]));

                    // sends a notification to either supervisor or manager on stock record's value
                    #region Send notification
                    String message = $"Stock adjustment raised for Item ({targetList[i].Item.Description}). Please approve/reject.";
                    int    notifId = _notificationDAO.CreateNotification(message);
                    var    hub     = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();

                    SupplierItem si = _supplierItemDAO.FindByItem(targetList[i].Item);
                    if (Math.Abs((targetList[i].UnitIssued - qtyDisbursed[i]) * si.Price) >= 250)
                    {
                        _notificationChannelDAO.SendNotification(IdStoreClerk, man.IdEmployee, notifId, DateTime.Now);
                        hub.Clients.All.receiveNotification(man.IdEmployee);
                        EmailClass emailClass = new EmailClass();
                        emailClass.SendTo(man.Email, "SSIS System Email", message);
                    }
                    else
                    {
                        _notificationChannelDAO.SendNotification(IdStoreClerk, sup.IdEmployee, notifId, DateTime.Now);
                        hub.Clients.All.receiveNotification(sup.IdEmployee);
                        EmailClass emailClass = new EmailClass();
                        emailClass.SendTo(sup.Email, "SSIS System Email", message);
                    }
                    #endregion
                }
            }

            // updates the disbitemId's unitissued to the qtyDisbursed
            _disbursementItemDAO.UpdateUnitIssued(disbItemId, qtyDisbursed);

            return(RedirectToAction("Disbursement"));
        }
예제 #17
0
        public ActionResult GetChangeRepCP(string emp, string cp, string judge)
        {
            string submit   = judge;
            string location = cp;
            string empName  = emp;

            if (judge.Equals("Cancel"))
            {
                RedirectToAction("CurrentRepCP", "DepartmentHead");
            }
            else if (judge.Equals("Apply Change"))
            {
                if (location != null && empName != null)
                {
                    Employee newRep             = _employeeDAO.FindEmployeeByName(empName);
                    string   codeDepartment     = newRep.CodeDepartment;
                    string   oldCollectionPoint = _collectionPointDAO.FindByDepartment(codeDepartment);
                    Employee oldRep             = _employeeDAO.FindDepartmentRep(codeDepartment);
                    if (oldRep == null)
                    {
                        //if there is no oldRep then do not need to set idrole etc
                        //but need set new rep
                        _employeeDAO.ChangeNewRepCP(newRep.Name, location);

                        //@Shutong: send notification here
                        Employee e          = _employeeDAO.FindEmployeeByName(newRep.Name);
                        int      IdEmployee = e.IdEmployee;
                        var      hub        = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                        hub.Clients.All.receiveNotification(IdEmployee);
                        EmailClass emailClass = new EmailClass();
                        string     message    = "Hi " + newRep.Name
                                                + ", you are appointed as Department Rep. Collection Point is " + location;

                        _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message);
                        emailClass.SendTo(_employeeDAO.FindEmployeeById(IdEmployee).Email, "SSIS System Email", message);
                        //end of notification sending
                    }
                    else
                    {
                        // old rep is not null
                        //change old rep back to employee
                        //change the current employee to rep and change collection point
                        _employeeDAO.PutOldRepBack(oldRep.Name);
                        _employeeDAO.ChangeNewRepCP(newRep.Name, location);

                        if (newRep.Name != oldRep.Name)
                        {
                            //@Shutong: send notification here
                            int IdEmployee = oldRep.IdEmployee;
                            var hub        = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                            hub.Clients.All.receiveNotification(IdEmployee);
                            EmailClass emailClass = new EmailClass();
                            string     message    = "Hi " + oldRep.Name
                                                    + ", you are not Department Rep anymore.";
                            _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message);
                            emailClass.SendTo(oldRep.Email, "SSIS System Email", message);

                            IdEmployee = newRep.IdEmployee;
                            hub.Clients.All.receiveNotification(IdEmployee);
                            message = "Hi " + newRep.Name
                                      + ", you are appointed as Department Rep. Collection Point is " + location;
                            _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message);
                            emailClass.SendTo(newRep.Email, "SSIS System Email", message);
                            //end of notification sending
                        }
                        //if rep didnot change but only cp changes
                        else
                        {
                            if (oldCollectionPoint != location)
                            {
                                int IdEmployee = oldRep.IdEmployee;
                                var hub        = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                                hub.Clients.All.receiveNotification(IdEmployee);
                                EmailClass emailClass = new EmailClass();
                                string     message    = "Hi " + oldRep.Name
                                                        + ", your collection point has been changed by your head.";
                                _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message);
                                emailClass.SendTo(oldRep.Email, "SSIS System Email", message);
                            }
                        }
                    }

                    return(RedirectToAction("CurrentRepCP", "DepartmentHead"));
                }
            }

            return(RedirectToAction("CurrentRepCP", "DepartmentHead"));
        }