Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }