//Update Adjustmentdetail
        public static AdjustmentDetailModel UpdateAdjustmentDetail(AdjustmentDetailModel adjdm, out string error)
        {
            error = "";
            LUSSISEntities   entities = new LUSSISEntities();
            adjustmentdetail adjd     = new adjustmentdetail();

            try
            {
                adjd = entities.adjustmentdetails.Where(a => a.adjid == adjdm.Adjid && a.itemid == adjdm.Itemid).First <adjustmentdetail>();
                //adjd.adjid = adjdm.adjid;
                //adjd.itemid = adjdm.itemid;
                adjd.reason      = adjdm.Reason;
                adjd.adjustedqty = adjdm.Adjustedqty;

                entities.SaveChanges();
                adjdm = GetAdjustDetailByItemandAdjustID(adjd.itemid, adjd.adjid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(adjdm);
        }
        public static List <InventoryDetailWithStatus> GetInventoryDetailWithStatus(out string error)
        {
            LUSSISEntities entities = new LUSSISEntities();

            error = "";
            List <InventoryDetailWithStatus> invdms = new List <InventoryDetailWithStatus>();

            try
            {
                List <adjustmentdetail> adjds = entities.adjustmentdetails.Where(x => x.adjustment.status == ConAdjustment.Active.PENDING).ToList();

                List <inventory> invs = entities.inventories.ToList <inventory>();
                foreach (inventory inv in invs)
                {
                    bool IsPending = false;
                    int  count     = adjds.Where(x => x.itemid == inv.itemid).Count();
                    InventoryDetailWithStatus invdm = new InventoryDetailWithStatus();
                    int    CurrentStock             = inv.stock;
                    string Reason = "";
                    if (count > 0)
                    {
                        adjustmentdetail adj = adjds.Where(x => x.itemid == inv.itemid).FirstOrDefault();
                        IsPending    = true;
                        CurrentStock = adj.adjustedqty + inv.stock;
                        Reason       = adj.reason;
                    }
                    invdm = new InventoryDetailWithStatus(inv.invid, inv.itemid, inv.item.description, inv.stock, inv.reorderlevel, inv.reorderqty, inv.item.catid, inv.item.category.name,
                                                          inv.item.description, inv.item.uom, IsPending, inv.item.category.shelflocation,
                                                          inv.item.category.shelflevel, CurrentStock, Reason);
                    invdms.Add(invdm);
                }
            }

            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }

            catch (Exception e)
            {
                // for other exceptions
                error = e.Message;
            }

            //returning the list
            return(invdms);
        }
        //Get All adjustments by item id & adjustment id
        public static AdjustmentDetailModel GetAdjustDetailByItemandAdjustID(int itemid, int adjid, out string error)
        {
            error = "";
            LUSSISEntities        entities = new LUSSISEntities();
            AdjustmentDetailModel adjdm    = new AdjustmentDetailModel();

            try
            {
                adjustmentdetail adjd = entities.adjustmentdetails.Where(a => a.itemid == itemid && a.adjid == adjid).First <adjustmentdetail>();
                adjdm = ConvertDBtoAPIAdjustDetail(adjd);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(adjdm);
        }
        //Changed from DB to APIModel
        public static AdjustmentDetailModel ConvertDBtoAPIAdjustDetail(adjustmentdetail adjd)
        {
            AdjustmentDetailModel adjdm = new AdjustmentDetailModel(adjd.adjid, adjd.itemid, adjd.item.description, adjd.adjustedqty, adjd.reason, adjd.item.category.name, adjd.item.uom);

            return(adjdm);
        }
Esempio 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);
        }