Beispiel #1
0
 public IHttpActionResult VerifyDiscarding(int discardingSessionPK, string userID, bool isApproved)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Manager"))
     {
         StoringDAO        storingDAO        = new StoringDAO();
         Verification      verification      = null;
         DiscardingSession discardingSession = null;
         try
         {
             discardingSession = db.DiscardingSessions.Find(discardingSessionPK);
             if (discardingSession != null && discardingSession.IsVerified == false)
             {
                 storingDAO.UpdateDiscardingSession(discardingSession.DiscardingSessionPK, true);
                 verification = storingDAO.CreateVerification(discardingSession.DiscardingSessionPK, userID, isApproved, true);
             }
             else
             {
                 return(Content(HttpStatusCode.Conflict, "DiscardingSession SAI!"));
             }
         }
         catch (Exception e)
         {
             if (discardingSession != null)
             {
                 storingDAO.UpdateDiscardingSession(discardingSession.DiscardingSessionPK, false);
             }
             return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
         }
         return(Content(HttpStatusCode.OK, "VERIFY ADJUSTING THÀNH CÔNG!"));
     }
     else
     {
         return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY!"));
     }
 }
 public void DeleteDiscardingSession(int discardingSessionPK)
 {
     try
     {
         DiscardingSession discardingSession = db.DiscardingSessions.Find(discardingSessionPK);
         db.DiscardingSessions.Remove(discardingSession);
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void UpdateDiscardingSession(int discardingSessionPK, bool isVerified)
 {
     try
     {
         DiscardingSession discardingSession = db.DiscardingSessions.Find(discardingSessionPK);
         discardingSession.IsVerified      = isVerified;
         db.Entry(discardingSession).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #4
0
 public IHttpActionResult DiscardInventory(string boxID, int itemPK, double discardedQuantity, bool isRestored, string userID, string comment)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff"))
     {
         BoxDAO            boxDAO            = new BoxDAO();
         StoringDAO        storingDAO        = new StoringDAO();
         DiscardingSession discardingSession = null;
         try
         {
             Box       box  = boxDAO.GetBoxByBoxID(boxID);
             StoredBox sBox = boxDAO.GetStoredBoxbyBoxPK(box.BoxPK);
             if (sBox != null)
             {
                 List <Entry> entries = (from e in db.Entries
                                         where e.StoredBoxPK == sBox.StoredBoxPK && e.ItemPK == itemPK && e.IsRestored == isRestored
                                         select e).ToList();
                 discardingSession = storingDAO.CreateDiscardingSession(comment, false, userID);
                 if (discardedQuantity > storingDAO.EntriesQuantity(entries))
                 {
                     storingDAO.CreateDiscardEntry(sBox, itemPK, discardedQuantity, isRestored, discardingSession);
                 }
                 if (discardedQuantity < storingDAO.EntriesQuantity(entries))
                 {
                     storingDAO.CreateDiscardEntry(sBox, itemPK, discardedQuantity, isRestored, discardingSession);
                 }
                 else
                 {
                     return(Content(HttpStatusCode.Conflict, "SỐ LƯỢNG KHÔNG HỢP LỆ!"));
                 }
             }
             else
             {
                 if (discardingSession != null)
                 {
                     storingDAO.DeleteDiscardingSession(discardingSession.DiscardingSessionPK);
                 }
                 return(Content(HttpStatusCode.Conflict, "THÙNG KHÔNG HỢP LỆ!"));
             }
         }
         catch (Exception e)
         {
             return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
         }
         return(Content(HttpStatusCode.OK, "THAY ĐỔI KHO THÀNH CÔNG!"));
     }
     else
     {
         return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY!"));
     }
 }
 public DiscardingSession CreateDiscardingSession(string comment, bool isVerified, string userID)
 {
     try
     {
         DiscardingSession discardingSession = new DiscardingSession(comment, isVerified, userID);
         db.DiscardingSessions.Add(discardingSession);
         db.SaveChanges();
         discardingSession = (from Ass in db.DiscardingSessions.OrderByDescending(unit => unit.DiscardingSessionPK)
                              select Ass).FirstOrDefault();
         return(discardingSession);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void CreateDiscardEntry(StoredBox sBox, int itemPK, double discardedQuantity, bool isRestored, DiscardingSession discardingSession)
 {
     try
     {
         Entry     entry;
         Accessory accessory;
         if (isRestored)
         {
             RestoredItem restoredItem = db.RestoredItems.Find(itemPK);
             accessory = db.Accessories.Find(restoredItem.AccessoryPK);
         }
         else
         {
             PassedItem     passedItem     = db.PassedItems.Find(itemPK);
             ClassifiedItem classifiedItem = db.ClassifiedItems.Find(passedItem.ClassifiedItemPK);
             PackedItem     packedItem     = db.PackedItems.Find(classifiedItem.PackedItemPK);
             OrderedItem    orderedItem    = db.OrderedItems.Find(packedItem.OrderedItemPK);
             accessory = db.Accessories.Find(orderedItem.AccessoryPK);
         }
         entry = new Entry(sBox, "Discarding", discardingSession.DiscardingSessionPK, isRestored, discardedQuantity, itemPK, accessory);
         db.Entries.Add(entry);
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public double EntriesQuantity(List <Entry> entries)
        {
            double result = 0;

            foreach (var entry in entries)
            {
                AdjustingSession adjustingSession;
                Verification     verification;
                KindRole         kindRole = db.KindRoles.Find(entry.KindRoleName);
                switch (entry.KindRoleName)
                {
                case "Discarding":
                    DiscardingSession discardingSession = db.DiscardingSessions.Find(entry.SessionPK);
                    verification = (from ver in db.Verifications
                                    where ver.SessionPK == discardingSession.DiscardingSessionPK && ver.IsDiscard
                                    select ver).FirstOrDefault();
                    if (!(discardingSession.IsVerified && !verification.IsApproved))
                    {
                        result += entry.Quantity * (kindRole.Sign ? 1 : -1);
                    }
                    break;

                case "AdjustingMinus":
                    adjustingSession = db.AdjustingSessions.Find(entry.SessionPK);
                    verification     = (from ver in db.Verifications
                                        where ver.SessionPK == adjustingSession.AdjustingSessionPK && !ver.IsDiscard
                                        select ver).FirstOrDefault();
                    if (!(adjustingSession.IsVerified && !verification.IsApproved))
                    {
                        result += entry.Quantity * (kindRole.Sign ? 1 : -1);
                    }
                    break;

                case "AdjustingPlus":
                    adjustingSession = db.AdjustingSessions.Find(entry.SessionPK);
                    verification     = (from ver in db.Verifications
                                        where ver.SessionPK == adjustingSession.AdjustingSessionPK && !ver.IsDiscard
                                        select ver).FirstOrDefault();
                    if (adjustingSession.IsVerified && verification.IsApproved)
                    {
                        result += entry.Quantity * (kindRole.Sign ? 1 : -1);
                    }
                    break;

                case "In":
                    result += entry.Quantity * (kindRole.Sign ? 1 : -1);
                    break;

                case "Issuing":
                    result += entry.Quantity * (kindRole.Sign ? 1 : -1);
                    break;

                case "Out":
                    result += entry.Quantity * (kindRole.Sign ? 1 : -1);
                    break;

                case "Receiving":
                    result += entry.Quantity * (kindRole.Sign ? 1 : -1);
                    break;

                case "Storing":
                    result += entry.Quantity * (kindRole.Sign ? 1 : -1);
                    break;

                default:
                    break;
                }
            }
            return(result);
        }
Beispiel #8
0
        public List <Client_Box_Shelf_Row> StoredBox_ItemPK_IsRestoredOfEntries(Accessory accessory)
        {
            List <Client_Box_Shelf_Row> result = new List <Client_Box_Shelf_Row>();
            StoringDAO storingDAO = new StoringDAO();

            try
            {
                // cực phẩm IQ
                double inStoredQuantity = InStoredQuantity(accessory.AccessoryPK);
                if (inStoredQuantity == 0)
                {
                    throw new Exception("HÀNG TRONG KHO ĐÃ HẾT!");
                }
                List <Entry> entries = (from e in db.Entries
                                        where e.AccessoryPK == accessory.AccessoryPK
                                        select e).ToList();
                Dictionary <StoredBox_ItemPK_IsRestored, InBoxQuantity_AvailableQuantity> tempDictionary = new Dictionary <StoredBox_ItemPK_IsRestored, InBoxQuantity_AvailableQuantity>();
                foreach (var entry in entries)
                {
                    double    inBoxQuantity = 0;
                    StoredBox storedBox     = db.StoredBoxes.Find(entry.StoredBoxPK);

                    if (entry.KindRoleName == "AdjustingMinus" || entry.KindRoleName == "AdjustingPlus")
                    {
                        AdjustingSession adjustingSession = db.AdjustingSessions.Find(entry.SessionPK);
                        Verification     verification     = db.Verifications.Where(unit => unit.SessionPK == adjustingSession.AdjustingSessionPK &&
                                                                                   unit.IsDiscard == false).FirstOrDefault();
                        if (verification != null && verification.IsApproved)
                        {
                            inBoxQuantity = storingDAO.EntryQuantity(entry);
                        }
                    }
                    else if (entry.KindRoleName == "Discarding")
                    {
                        DiscardingSession discardingSession = db.DiscardingSessions.Find(entry.SessionPK);
                        Verification      verification      = db.Verifications.Where(unit => unit.SessionPK == discardingSession.DiscardingSessionPK &&
                                                                                     unit.IsDiscard == true).FirstOrDefault();
                        if (verification != null && verification.IsApproved)
                        {
                            inBoxQuantity = storingDAO.EntryQuantity(entry);
                        }
                    }
                    else
                    {
                        inBoxQuantity = storingDAO.EntryQuantity(entry);
                    }

                    Box          box = db.Boxes.Find(storedBox.BoxPK);
                    PassedItem   passedItem;
                    RestoredItem restoredItem;
                    StoredBox_ItemPK_IsRestored key;
                    if (entry.IsRestored)
                    {
                        restoredItem = db.RestoredItems.Find(entry.ItemPK);
                        key          = new StoredBox_ItemPK_IsRestored(storedBox.StoredBoxPK, restoredItem.RestoredItemPK, entry.IsRestored);
                    }
                    else
                    {
                        passedItem = db.PassedItems.Find(entry.ItemPK);
                        key        = new StoredBox_ItemPK_IsRestored(storedBox.StoredBoxPK, passedItem.PassedItemPK, entry.IsRestored);
                    }
                    if (box.IsActive)
                    {
                        InBoxQuantity_AvailableQuantity tmp = new InBoxQuantity_AvailableQuantity(inBoxQuantity, storingDAO.EntryQuantity(entry));
                        if (!tempDictionary.ContainsKey(key))
                        {
                            tempDictionary.Add(key, tmp);
                        }
                        else
                        {
                            tempDictionary[key].InBoxQuantity     += tmp.InBoxQuantity;
                            tempDictionary[key].AvailableQuantity += tmp.AvailableQuantity;
                        }
                    }
                }

                foreach (var item in tempDictionary)
                {
                    if (item.Value.AvailableQuantity > 0)
                    {
                        StoredBox storedBox = db.StoredBoxes.Find(item.Key.StoredBoxPK);
                        Box       box       = db.Boxes.Find(storedBox.BoxPK);
                        Shelf     shelf     = db.Shelves.Find(storedBox.ShelfPK);
                        Row       row       = db.Rows.Find(shelf.RowPK);
                        if (item.Key.IsRestored)
                        {
                            RestoredItem restoredItem = db.RestoredItems.Find(item.Key.ItemPK);
                            Restoration  restoration  = db.Restorations.Find(restoredItem.RestorationPK);
                            result.Add(new Client_Box_Shelf_Row(box.BoxID, storedBox.StoredBoxPK, shelf.ShelfID, row.RowID, item.Key.ItemPK, item.Key.IsRestored, item.Value.InBoxQuantity, restoration.RestorationID, item.Value.AvailableQuantity));
                        }
                        else
                        {
                            PassedItem     passedItem     = db.PassedItems.Find(item.Key.ItemPK);
                            ClassifiedItem classifiedItem = db.ClassifiedItems.Find(passedItem.ClassifiedItemPK);
                            PackedItem     packedItem     = db.PackedItems.Find(classifiedItem.PackedItemPK);
                            Pack           pack           = db.Packs.Find(packedItem.PackPK);
                            result.Add(new Client_Box_Shelf_Row(box.BoxID, storedBox.StoredBoxPK, shelf.ShelfID, row.RowID, item.Key.ItemPK, item.Key.IsRestored, item.Value.InBoxQuantity, pack.PackID, item.Value.AvailableQuantity));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(result);
        }