Ejemplo n.º 1
0
 public IHttpActionResult VerifyAdjusting(int adjustingSessionPK, string userID, bool isApproved)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Manager"))
     {
         StoringDAO       storingDAO       = new StoringDAO();
         Verification     verification     = null;
         AdjustingSession adjustingSession = null;
         try
         {
             adjustingSession = db.AdjustingSessions.Find(adjustingSessionPK);
             if (adjustingSession != null && adjustingSession.IsVerified == false)
             {
                 storingDAO.UpdateAdjustingSession(adjustingSession.AdjustingSessionPK, true);
                 verification = storingDAO.CreateVerification(adjustingSession.AdjustingSessionPK, userID, isApproved, false);
             }
             else
             {
                 return(Content(HttpStatusCode.Conflict, "AdjustingSession SAI!"));
             }
         }
         catch (Exception e)
         {
             if (adjustingSession != null)
             {
                 storingDAO.UpdateAdjustingSession(adjustingSession.AdjustingSessionPK, 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!"));
     }
 }
Ejemplo n.º 2
0
 public void DeleteAdjustingSession(int adjustingSessionPK)
 {
     try
     {
         AdjustingSession adjustingSession = db.AdjustingSessions.Find(adjustingSessionPK);
         db.AdjustingSessions.Remove(adjustingSession);
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 3
0
 public void UpdateAdjustingSession(int adjustingSessionPK, bool isVerified)
 {
     try
     {
         AdjustingSession adjustingSession = db.AdjustingSessions.Find(adjustingSessionPK);
         adjustingSession.IsVerified      = isVerified;
         db.Entry(adjustingSession).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 4
0
 public IHttpActionResult AdjustInventory(string boxID, int itemPK, double adjustedQuantity, bool isRestored, string userID, string comment)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff"))
     {
         BoxDAO           boxDAO           = new BoxDAO();
         StoringDAO       storingDAO       = new StoringDAO();
         AdjustingSession adjustingSession = 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();
                 adjustingSession = storingDAO.CreateAdjustingSession(comment, false, userID);
                 if (adjustedQuantity > storingDAO.EntriesQuantity(entries))
                 {
                     storingDAO.CreateAdjustEntry(sBox, itemPK, adjustedQuantity, isRestored, false, adjustingSession);
                 }
                 if (adjustedQuantity < storingDAO.EntriesQuantity(entries))
                 {
                     storingDAO.CreateAdjustEntry(sBox, itemPK, adjustedQuantity, isRestored, true, adjustingSession);
                 }
                 else
                 {
                     return(Content(HttpStatusCode.Conflict, "SỐ LƯỢNG KHÔNG HỢP LỆ!"));
                 }
             }
             else
             {
                 if (adjustingSession != null)
                 {
                     storingDAO.DeleteAdjustingSession(adjustingSession.AdjustingSessionPK);
                 }
                 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!"));
     }
 }
Ejemplo n.º 5
0
 public AdjustingSession CreateAdjustingSession(string comment, bool isVerified, string userID)
 {
     try
     {
         AdjustingSession adjustingSession = new AdjustingSession(comment, isVerified, userID);
         db.AdjustingSessions.Add(adjustingSession);
         db.SaveChanges();
         adjustingSession = (from Ass in db.AdjustingSessions.OrderByDescending(unit => unit.AdjustingSessionPK)
                             select Ass).FirstOrDefault();
         return(adjustingSession);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 6
0
 public void CreateAdjustEntry(StoredBox sBox, int itemPK, double adjustedQuantity, bool isRestored, bool isMinus, AdjustingSession adjustingSession)
 {
     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);
         }
         if (isMinus)
         {
             entry = new Entry(sBox, "AdjustingMinus", adjustingSession.AdjustingSessionPK, isRestored, adjustedQuantity, itemPK, accessory);
         }
         else
         {
             entry = new Entry(sBox, "AdjustingPlus", adjustingSession.AdjustingSessionPK, isRestored, adjustedQuantity, itemPK, accessory);
         }
         db.Entries.Add(entry);
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 7
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);
        }