Пример #1
0
        // submit request
        // done
        public static RequestVM SubmitReq(int reqId, List <RequestDetailVM> reqDetList)
        {
            // make requestId in reqDetList is the same as reqId
            using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext())
            {
                try
                {
                    RequestVM req = GetReq(reqId);
                    for (int i = 0; i < reqDetList.Count; i++)
                    {
                        if (reqDetList[i].ReqId == reqId)
                        {
                            List <RequestDetail> rdlist = entities.RequestDetails.ToList();
                            for (int j = 0; j < rdlist.Count; j++)
                            {
                                if (reqDetList[i].ReqId == rdlist[j].ReqId && reqDetList[i].ReqLineNo == rdlist[j].ReqLineNo)
                                {
                                    rdlist[j].ReqQty       = reqDetList[i].ReqQty;
                                    rdlist[j].AwaitQty     = reqDetList[i].AwaitQty;
                                    rdlist[j].FulfilledQty = reqDetList[i].FulfilledQty;
                                    entities.SaveChanges();
                                }
                            }
                        }
                    }
                    req.ReqDateTime = DateTime.Now;
                    req.Status      = "Submitted";
                    req             = UpdateReq(req);

                    int        empId    = req.EmpId;
                    Employee   emp      = entities.Employees.Where(x => x.EmpId == empId).FirstOrDefault();
                    string     deptCode = emp.DeptCode;
                    Department dept     = entities.Departments.Where(x => x.DeptCode == deptCode).FirstOrDefault();

                    int fromEmpId = req.EmpId;
                    int toEmpId;
                    if (dept.DelegateApproverId != null && DateTime.Compare(DateTime.Now, (DateTime)dept.DelegateFromDate) >= 0 &&
                        DateTime.Compare(DateTime.Now, (DateTime)dept.DelegateToDate) >= 0)
                    {
                        toEmpId = (int)dept.DelegateApproverId;
                    }
                    else
                    {
                        toEmpId = (int)dept.DeptHeadId;
                    }
                    string type    = "Stationery Request";
                    string content = "A new stationery request has been submitted";
                    NotificationBL.AddNewNotification(fromEmpId, toEmpId, type, content);

                    // for email
                    EmailBL.SendNewReqEmail(empId, req);

                    return(req);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #2
0
        // reject request
        // done
        public static bool RejectRequest(int reqId, int empId, string cmt)
        {
            try
            {
                List <RequestVM> reqlist = GetReq(empId, "Submitted");
                // for email
                RequestVM reqVM = new RequestVM();

                int toId = 0;
                for (int i = 0; i < reqlist.Count; i++)
                {
                    if (reqlist[i].ReqId == reqId)
                    {
                        using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext())
                        {
                            Request req = entities.Requests.Where(r => r.ReqId == reqId).FirstOrDefault();
                            toId                 = req.EmpId;
                            req.ApproverId       = empId;
                            req.ApproverComment  = cmt;
                            req.ApprovedDateTime = DateTime.Now;
                            req.Status           = "Rejected";
                            entities.SaveChanges();
                            // for email
                            reqVM.ReqId            = req.ReqId;
                            reqVM.EmpId            = req.EmpId;
                            reqVM.ApproverId       = req.ApproverId;
                            reqVM.ApproverComment  = req.ApproverComment;
                            reqVM.ReqDateTime      = (DateTime)req.ReqDateTime;
                            reqVM.ApprovedDateTime = (DateTime)req.ApprovedDateTime;
                            //reqVM.CancelledDateTime = (DateTime)req.CancelledDateTime;
                            reqVM.Status = req.Status;
                            //reqVM.FulfilledDateTime = (DateTime)req.FulfilledDateTime;
                        }
                    }
                }
                int    fromEmpId = empId;
                int    toEmpId   = toId;
                string type      = "Stationery Request";
                string content   = "Your stationery request has been rejected : Please review quantities";
                NotificationBL.AddNewNotification(fromEmpId, toEmpId, type, content);
                // for email
                EmailBL.SendReqApprEmail(toId, reqVM);

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        // reject adjustment request
        // done
        public static bool RejectRequest(string voucherNo, int empId, string cmt)
        {
            using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext())
            {
                try
                {
                    // for email
                    List <AdjustmentVM> adjListEmail = new List <AdjustmentVM>();

                    int toId = 0;
                    List <Adjustment> adjList = entities.Adjustments.Where(a => a.VoucherNo.Equals(voucherNo)).ToList();
                    for (int i = 0; i < adjList.Count; i++)
                    {
                        if (adjList[i].ApproverId == empId)
                        {
                            adjList[i].ApproverComment = cmt;
                            adjList[i].Status          = "Rejected";

                            int      adjRaiseEmpId = adjList[i].EmpId;
                            Employee adjRaiseEmp   = entities.Employees.Where(x => x.EmpId == adjRaiseEmpId).FirstOrDefault();
                            if (adjRaiseEmp.Role.Equals("Store Clerk"))
                            {
                                toId = adjRaiseEmpId;
                            }
                            else
                            {
                                toId = entities.Employees.Where(x => x.Role.Equals("Store Clerk")).FirstOrDefault().EmpId;
                            }

                            // for email
                            AdjustmentVM adj = new AdjustmentVM();
                            adj.VoucherNo       = adjList[i].VoucherNo;
                            adj.EmpId           = adjList[i].EmpId;
                            adj.DateTimeIssued  = adjList[i].DateTimeIssued;
                            adj.ItemCode        = adjList[i].ItemCode;
                            adj.Reason          = adjList[i].Reason;
                            adj.QtyChange       = adjList[i].QtyChange;
                            adj.Status          = adjList[i].Status;
                            adj.ApproverId      = (int)adjList[i].ApproverId;
                            adj.ApproverComment = adjList[i].ApproverComment;
                            adjListEmail.Add(adj);
                        }
                    }
                    entities.SaveChanges();

                    int    fromEmpId = empId;
                    int    toEmpId   = toId;
                    string type      = "Adjustment Request";
                    string content   = voucherNo + " has been rejected: Please review quantities";

                    NotificationBL.AddNewNotification(fromEmpId, toEmpId, type, content);

                    // for email
                    EmailBL.SendAdjApprEmail(toId, adjListEmail);

                    return(true);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #4
0
        // accept adjustment request
        // done
        public static bool AcceptRequest(string voucherNo, int empId, string cmt)
        {
            using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext())
            {
                try
                {
                    // for email
                    List <AdjustmentVM> adjListEmail = new List <AdjustmentVM>();

                    int toId = 0;
                    List <Adjustment> adjList = entities.Adjustments.Where(a => a.VoucherNo.Equals(voucherNo)).ToList();
                    for (int i = 0; i < adjList.Count; i++)
                    {
                        if (adjList[i].ApproverId == empId)
                        {
                            adjList[i].ApproverComment = cmt;
                            adjList[i].Status          = "Approved";

                            int      adjRaiseEmpId = adjList[i].EmpId;
                            Employee adjRaiseEmp   = entities.Employees.Where(x => x.EmpId == adjRaiseEmpId).FirstOrDefault();
                            if (adjRaiseEmp.Role.Equals("Store Clerk"))
                            {
                                toId = adjRaiseEmpId;
                            }
                            else
                            {
                                toId = entities.Employees.Where(x => x.Role.Equals("Store Clerk")).FirstOrDefault().EmpId;
                            }

                            // for email
                            AdjustmentVM adj = new AdjustmentVM();
                            adj.VoucherNo       = adjList[i].VoucherNo;
                            adj.EmpId           = adjList[i].EmpId;
                            adj.DateTimeIssued  = adjList[i].DateTimeIssued;
                            adj.ItemCode        = adjList[i].ItemCode;
                            adj.Reason          = adjList[i].Reason;
                            adj.QtyChange       = adjList[i].QtyChange;
                            adj.Status          = adjList[i].Status;
                            adj.ApproverId      = (int)adjList[i].ApproverId;
                            adj.ApproverComment = adjList[i].ApproverComment;
                            adjListEmail.Add(adj);

                            string itemCode = adjList[i].ItemCode;
                            Item   item     = entities.Items.Where(x => x.ItemCode.Equals(itemCode)).First();
                            item.Balance += adjList[i].QtyChange;

                            TransactionVM trans = new TransactionVM();
                            trans.TranDateTime = DateTime.Now;
                            trans.ItemCode     = itemCode;
                            trans.QtyChange    = adjList[i].QtyChange;
                            trans.UnitPrice    = (double)item.Price1;
                            trans.Desc         = "Adjustment";
                            trans.DeptCode     = "";
                            trans.SuppCode     = "";
                            trans.VoucherNo    = adjList[i].VoucherNo;
                            TransactionBL.AddTran(trans);

                            bool status = ItemBL.CheckLowStk(ItemUtility.Convert_ItemObj_To_ItemVMObj(item));

                            if (status)
                            {
                                NotificationBL.AddLowStkNotification(empId, item);
                            }
                        }
                    }
                    entities.SaveChanges();

                    int    fromEmpId = empId;
                    int    toEmpId   = toId;
                    string type      = "Adjustment Request";
                    string content   = voucherNo + " has been approved: No comment";

                    NotificationBL.AddNewNotification(fromEmpId, toEmpId, type, content);

                    // for email
                    EmailBL.SendAdjApprEmail(toId, adjListEmail);

                    return(true);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #5
0
        // raise adjustment
        // done
        public static bool RaiseAdjustments(int empId, List <ItemVM> iList)
        {
            using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext())
            {
                try
                {
                    // for email
                    List <AdjustmentVM> adjList = new List <AdjustmentVM>();

                    string vNum = GenerateVoucherNo();
                    for (int i = 0; i < iList.Count; i++)
                    {
                        if ((iList[i].TempQtyCheck - iList[i].Balance) != 0)
                        {
                            Adjustment a = new Adjustment();
                            a.VoucherNo      = vNum;
                            a.EmpId          = empId;
                            a.DateTimeIssued = DateTime.Now;
                            a.ItemCode       = iList[i].ItemCode;
                            a.Reason         = iList[i].TempReason;
                            a.QtyChange      = (int)iList[i].TempQtyCheck - iList[i].Balance;
                            a.Status         = "Submitted";

                            Employee emp = new Employee();
                            emp = entities.Employees.Where(x => x.Role.Equals("Store Supervisor")).FirstOrDefault();
                            double chgBck = a.QtyChange * iList[i].Price1;
                            if (a.QtyChange < 0)
                            {
                                chgBck = chgBck * -1;
                            }
                            if (chgBck >= 250)
                            {
                                emp = entities.Employees.Where(x => x.Role.Equals("Store Manager")).FirstOrDefault();
                            }
                            a.ApproverId = emp.EmpId;

                            a.ApproverComment = "";
                            entities.Adjustments.Add(a);
                            entities.SaveChanges();

                            // for email
                            AdjustmentVM adj = new AdjustmentVM();
                            adj.VoucherNo       = a.VoucherNo;
                            adj.EmpId           = a.EmpId;
                            adj.DateTimeIssued  = a.DateTimeIssued;
                            adj.ItemCode        = a.ItemCode;
                            adj.Reason          = a.Reason;
                            adj.QtyChange       = a.QtyChange;
                            adj.Status          = a.Status;
                            adj.ApproverId      = (int)a.ApproverId;
                            adj.ApproverComment = a.ApproverComment;
                            adjList.Add(adj);

                            int    fromEmpIdA = empId;
                            int    toEmpIdA   = emp.EmpId;
                            string typeA      = "Adjustment Request";
                            string contentA   = vNum + " has been raised";
                            NotificationBL.AddNewNotification(fromEmpIdA, toEmpIdA, typeA, contentA);
                        }
                    }

                    // for email
                    EmailBL.SendAdjReqEmail(empId, adjList);

                    return(true);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }