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 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);
        }