Ejemplo n.º 1
0
        //Create new Requisition with Detials
        public static RequisitionModel CreateRequisitionwithDetails(RequisitionModel reqm, List <RequisitionDetailsModel> reqd, out string error)
        {
            error = "";
            LUSSISEntities           entities = new LUSSISEntities();
            requisition              req      = new requisition();
            List <requisitiondetail> reqlist  = new List <requisitiondetail>();

            try
            {
                req.reqid      = reqm.Reqid;
                req.raisedby   = reqm.Raisedby;
                req.approvedby = reqm.Approvedby;
                req.deptid     = reqm.Depid;
                req.cpid       = reqm.Cpid;
                req.status     = ConRequisition.Status.PENDING;
                req.reqdate    = DateTime.Now;

                req = entities.requisitions.Add(req);
                entities.SaveChanges();

                foreach (RequisitionDetailsModel rdm in reqd)
                {
                    requisitiondetail rqd = new requisitiondetail
                    {
                        reqid  = req.reqid,
                        itemid = rdm.Itemid,
                        qty    = rdm.Qty
                    };
                    rqd = entities.requisitiondetails.Add(rqd);
                    entities.SaveChanges();
                    reqlist.Add(rqd);
                }

                reqm = GetRequisitionByRequisitionId(req.reqid, out error);



                NotificationModel nom = new NotificationModel();
                nom.Deptid   = DepartmentRepo.GetDepartmentByUserid(reqm.Raisedby ?? default(int), out error).Deptid;
                nom.Role     = ConUser.Role.HOD;
                nom.Title    = "Requisition Approval";
                nom.NotiType = ConNotification.NotiType.RequisitionApproval;
                nom.ResID    = reqm.Reqid;
                nom.Remark   = "A new requisition has been raised by " + reqm.Rasiedbyname + "!";
                nom          = NotificationRepo.CreatNotification(nom, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(reqm);
        }
Ejemplo n.º 2
0
        //create the requisition
        public static RequisitionModel CreateRequisition(RequisitionModel req, out string error)
        {
            error = "";
            bool           RaisedByTempHOD = true;
            LUSSISEntities entities        = new LUSSISEntities();
            requisition    reqn            = new requisition();

            try
            {
                reqn.raisedby   = req.Raisedby;
                reqn.approvedby = req.Approvedby;
                if (req.Approvedby == null || req.Approvedby == 0)
                {
                    reqn.approvedby = req.Raisedby;
                    RaisedByTempHOD = false;
                }
                reqn.deptid  = req.Depid;
                reqn.cpid    = req.Cpid;
                reqn.status  = ConRequisition.Status.PENDING;
                reqn.reqdate = DateTime.Now;
                reqn         = entities.requisitions.Add(reqn);
                entities.SaveChanges();
                req = GetRequisitionByRequisitionId(reqn.reqid, out error);

                if (!RaisedByTempHOD)
                {
                    NotificationModel nom = new NotificationModel();
                    nom.Deptid   = DepartmentRepo.GetDepartmentByUserid(reqn.raisedby ?? default(int), out error).Deptid;
                    nom.Role     = ConUser.Role.HOD;
                    nom.Title    = "Requisition Approval";
                    nom.NotiType = ConNotification.NotiType.RequisitionApproval;
                    nom.ResID    = reqn.reqid;
                    nom.Remark   = "A new requisition has been raised by " + req.Rasiedbyname + "!";
                    nom          = NotificationRepo.CreatNotification(nom, out error);
                }
                else
                {
                    req.Status = ConRequisition.Status.APPROVED;
                    req        = UpdateRequisition(req, out error);
                }
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(req);
        }
Ejemplo n.º 3
0
        //create delegation
        public static DelegationModel CreateDelegation(DelegationModel dele, out string error)
        {
            error = "";
            LUSSISEntities  entities = new LUSSISEntities();
            delegation      d        = new delegation();
            DelegationModel ndel     = new DelegationModel();

            try
            {
                DepartmentModel  dep      = DepartmentRepo.GetDepartmentByUserid(dele.Userid, out error);
                List <UserModel> userlist = UserRepo.GetUserByDeptid(dep.Deptid, out error);
                foreach (UserModel u in userlist)
                {
                    List <DelegationModel> delelist = GetDelegationByUserId(u.Userid, out error);
                    foreach (DelegationModel deleg in delelist)
                    {
                        delegation del = entities.delegations.Where(p => p.delid == deleg.Delid).FirstOrDefault <delegation>();
                        del.active = ConDelegation.Active.INACTIVE;
                        if (u.Role != ConUser.Role.DEPARTMENTREP)
                        {
                            UserRepo.Canceldelegateuser(u.Userid);
                        }
                        entities.SaveChanges();
                    }
                }
                d.startdate  = dele.Startdate;
                d.enddate    = dele.Enddate;
                d.userid     = dele.Userid;
                d.active     = ConDelegation.Active.ACTIVE;
                d.assignedby = dele.AssignedbyId;
                d            = entities.delegations.Add(d);
                entities.SaveChanges();

                dele = GetDelegationByDelegationID(d.delid, out error);


                user us = entities.users.Where(p => p.userid == dele.Userid).FirstOrDefault();

                NotificationModel nom = new NotificationModel();
                nom.Deptid   = us.deptid;
                nom.Role     = ConUser.Role.TEMPHOD;
                nom.Title    = "New Authority";
                nom.NotiType = ConNotification.NotiType.DelegationAssigned;
                nom.ResID    = dele.Userid;
                nom.Remark   = us.fullname + " has been assigned as a Temp HOD from " + dele.Startdate.Value.ToShortDateString() + " to " + dele.Enddate.Value.ToShortDateString();
                nom          = NotificationRepo.CreatNotification(nom, out error);


                nom.Deptid   = us.deptid;
                nom.Role     = ConUser.Role.EMPLOYEEREP;
                nom.Title    = "New Authority";
                nom.NotiType = ConNotification.NotiType.DelegationAssigned;
                nom.ResID    = dele.Userid;
                nom.Remark   = us.fullname + " has been assigned as a Temp HOD from " + dele.Startdate.Value.ToShortDateString() + " to " + dele.Enddate.Value.ToShortDateString();
                nom          = NotificationRepo.CreatNotification(nom, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dele);
        }
Ejemplo n.º 4
0
        //Update Adjustment
        public static AdjustmentModel UpdateAdjustment(AdjustmentModel adjm, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();

            NotificationModel nom = new NotificationModel();

            adjustment adj = new adjustment();

            try
            {
                adj            = entities.adjustments.Where(a => a.adjid == adjm.Adjid).First <adjustment>();
                adj.raisedby   = adjm.Raisedby;
                adj.raisedto   = adjm.Raisedto;
                adj.issueddate = adjm.Issueddate;
                adj.status     = adjm.Status;
                nom.Remark     = "The Adjustment Voucher has been Rejected!";


                if (adj.status == ConAdjustment.Active.APPROVED)
                {
                    nom.Remark = "The Adjustment Voucher has been Approved!";
                }

                List <AdjustmentDetailModel> adjustds = AdjustmentDetailRepo.GetAdjustmentDetailByAdjID(adj.adjid, out error);
                foreach (AdjustmentDetailModel adjustd in adjustds)
                {
                    InventoryModel inventm = InventoryRepo.GetInventoryByItemid(adjustd.Itemid, out error);
                    inventory      invent  = entities.inventories.Where(i => i.invid == inventm.Invid).First <inventory>();
                    invent.stock += adjustd.Adjustedqty;

                    InventoryTransactionModel invtm = new InventoryTransactionModel();

                    invtm.InvID     = invent.invid;
                    invtm.ItemID    = invent.itemid;
                    invtm.Qty       = adjustd.Adjustedqty;
                    invtm.TransType = ConInventoryTransaction.TransType.ADJUSTMENT;
                    invtm.TransDate = DateTime.Now;
                    invtm.Remark    = adjustd.Reason;

                    invtm = InventoryTransactionRepo.CreateInventoryTransaction(invtm, out error);
                }


                entities.SaveChanges();
                adjm = GetAdjustmentByID(adj.adjid, out error);

                nom.Deptid   = DepartmentRepo.GetDepartmentByUserid(adj.raisedto ?? default(int), out error).Deptid;
                nom.Role     = UserRepo.GetUserByUserID(adj.raisedby ?? default(int)).Role;
                nom.Title    = "Adjustment Approval";
                nom.NotiType = ConNotification.NotiType.Adjustment;
                nom.ResID    = adj.adjid;
                nom          = NotificationRepo.CreatNotification(nom, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(adjm);
        }
Ejemplo n.º 5
0
        //Create new Adjustment
        public static AdjustmentModel CreateAdjustment(AdjustmentModel adjm, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();
            adjustment     adj      = new adjustment();

            try
            {
                adj.raisedby   = adjm.Raisedby;
                adj.issueddate = adjm.Issueddate;
                adj.status     = ConAdjustment.Active.PENDING;
                List <AdjustmentDetailModel> adjds = adjm.Adjds;

                //check item price
                foreach (AdjustmentDetailModel adjd in adjds)
                {
                    adj.raisedto = 0;
                    SupplierItemModel supp  = SupplierItemRepo.GetSupplierItemByItemId(adjd.Itemid, out error);
                    double?           price = Math.Abs((Int32)adjd.Adjustedqty) * supp.Price;

                    //Check total price of each item to consider who to report to
                    if (price >= ConAdjustment.Active.REPORTMANAGER)
                    {
                        user user = entities.users.Where(u => u.role == ConUser.Role.MANAGER).First();
                        adj.raisedto = user.userid;
                    }
                    else
                    {
                        user user = entities.users.Where(u => u.role == ConUser.Role.SUPERVISOR).First();
                        adj.raisedto = user.userid;
                    }
                }
                adj = entities.adjustments.Add(adj);
                entities.SaveChanges();

                foreach (AdjustmentDetailModel adjdm in adjds)
                {
                    adjustmentdetail adjd = new adjustmentdetail
                    {
                        adjid       = adj.adjid,
                        itemid      = adjdm.Itemid,
                        adjustedqty = adjdm.Adjustedqty,
                        reason      = adjdm.Reason
                    };
                    adjd = entities.adjustmentdetails.Add(adjd);
                    entities.SaveChanges();
                }

                adjm = GetAdjustmentByID(adj.adjid, out error);

                NotificationModel nom = new NotificationModel();
                nom.Deptid   = DepartmentRepo.GetDepartmentByUserid(adj.raisedto ?? default(int), out error).Deptid;
                nom.Role     = UserRepo.GetUserByUserID(adj.raisedto ?? default(int)).Role;
                nom.Title    = "New Adjustment";
                nom.NotiType = ConNotification.NotiType.Adjustment;
                nom.ResID    = adj.adjid;
                nom.Remark   = "A new adjustment has been raised by clerk!";
                nom          = NotificationRepo.CreatNotification(nom, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(adjm);
        }