Пример #1
0
        public ActionResult ConfirmIssue(int id)
        {
            var item = InventoryIssue.TryFind(id);

            if (item == null || item.IsCompleted || item.IsCancelled)
            {
                return(RedirectToAction("Issues"));
            }

            item.Store = item.Warehouse.Store;

            try {
                item.Serial = (from x in InventoryIssue.Queryable
                               where x.Store.Id == item.Store.Id
                               select x.Serial).Max() + 1;
            } catch {
                item.Serial = 1;
            }

            item.IsCompleted      = true;
            item.ModificationTime = DateTime.Now;

            using (var scope = new TransactionScope()) {
                item.UpdateAndFlush();

                foreach (var x in item.Details)
                {
                    InventoryHelpers.ChangeNotification(TransactionType.InventoryIssue, item.Id,
                                                        item.ModificationTime, item.Warehouse, null, x.Product, -x.Quantity);
                }
            }

            return(RedirectToAction("Issues"));
        }
Пример #2
0
        public HttpResponseMessage PostInventoryIssue(InventoryIssue _InventoryIssue)
        {
            HttpRequestMessage  Request = new HttpRequestMessage();
            HttpResponseMessage response;

            Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            if (ModelState.IsValid)
            {
                bool IsItemAvailable = CheckAndUpdateItem(_InventoryIssue);
                if (IsItemAvailable)
                {
                    unitOfWork.InventoryIssueRepository.Insert(_InventoryIssue);
                    unitOfWork.Save();
                    response = Request.CreateResponse(HttpStatusCode.Created, _InventoryIssue);
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.NotAcceptable, _InventoryIssue);
                }
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Пример #3
0
        private bool CheckAndUpdateItem(InventoryIssue _InventoryIssue)
        {
            try
            {
                int ItemIssueId       = _InventoryIssue.IIID;
                int ItemId            = Convert.ToInt32(_InventoryIssue.Item);
                int IssueItemQuantity = Convert.ToInt32(_InventoryIssue.Quantity);

                InventoryItem objInventoryItem = unitOfWork.InventoryItemRepository.GetById(ItemId);

                InventoryIssue OldIssueItem         = unitOfWork.InventoryIssueRepository.GetFirstOrDefault(x => x.IIID == ItemIssueId);
                int            OldIssueItemQuantity = OldIssueItem != null?Convert.ToInt32(OldIssueItem.Quantity) : 0;

                if (OldIssueItem != null)
                {
                    unitOfWork.InventoryIssueRepository.Detach(OldIssueItem);
                }
                var AvailableItem = (Convert.ToInt32(objInventoryItem.Quantity) + OldIssueItemQuantity) - IssueItemQuantity;
                if (AvailableItem > 0)
                {
                    objInventoryItem.Quantity = AvailableItem;
                    unitOfWork.InventoryItemRepository.Update(objInventoryItem);
                    unitOfWork.Save();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #4
0
        public JsonResult UpdateInventoryIssue(int ID, InventoryIssue _InventoryIssue)
        {
            InventoriesController obj = new InventoriesController();
            var response = obj.PutInventoryIssue(ID, _InventoryIssue);

            return(Json(((InventoryIssue)(((System.Net.Http.ObjectContent)(response.Content)).Value)).IIID, JsonRequestBehavior.AllowGet));
        }
Пример #5
0
        public InventoryIssue GetInventoryIssue(int id)
        {
            InventoryIssue objInventoryIssue = unitOfWork.InventoryIssueRepository.GetById(id);

            if (objInventoryIssue == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            return(objInventoryIssue);
        }
Пример #6
0
        public ActionResult CancelIssue(int id)
        {
            var item = InventoryIssue.Find(id);

            item.IsCancelled = true;

            using (var scope = new TransactionScope()) {
                item.UpdateAndFlush();
            }

            return(RedirectToAction("Issues"));
        }
Пример #7
0
        public ActionResult EditIssue(InventoryIssue item)
        {
            var movement = InventoryIssue.Find(item.Id);

            movement.Warehouse        = Warehouse.Find(item.WarehouseId);
            movement.Store            = movement.Warehouse.Store;
            movement.Updater          = CurrentUser.Employee;
            movement.ModificationTime = DateTime.Now;
            movement.Comment          = item.Comment;

            using (var scope = new TransactionScope()) {
                movement.UpdateAndFlush();
            }

            return(PartialView("Issues/_MasterView", movement));
        }
Пример #8
0
        public ActionResult EditIssue(int id)
        {
            var item = InventoryIssue.Find(id);

            if (item.IsCompleted || item.IsCancelled)
            {
                return(RedirectToAction("Issue", new {
                    id = item.Id
                }));
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView("Issues/_MasterEditView", item));
            }
            else
            {
                return(View("Issues/Edit", item));
            }
        }
Пример #9
0
        public JsonResult AddIssueDetail(int movement, int product)
        {
            var p = Product.Find(product);

            var item = new InventoryIssueDetail {
                Issue       = InventoryIssue.Find(movement),
                Product     = p,
                ProductCode = p.Code,
                ProductName = p.Name,
                Quantity    = 1
            };

            using (var scope = new TransactionScope()) {
                item.CreateAndFlush();
            }

            return(Json(new {
                id = item.Id
            }));
        }
Пример #10
0
        public InventoryIssue DeleteInventoryIssue(int Id)
        {
            InventoryIssue _InventoryIssue = unitOfWork.InventoryIssueRepository.GetById(Id);

            if (_InventoryIssue == null)
            {
                return(_InventoryIssue);
            }

            try
            {
                unitOfWork.InventoryIssueRepository.Delete(Id);
                unitOfWork.Save();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(_InventoryIssue);
            }
            return(_InventoryIssue);
        }
Пример #11
0
        public ActionResult NewIssue(InventoryIssue item)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("Issues/_Create", item));
            }

            item.CreationTime     = DateTime.Now;
            item.ModificationTime = item.CreationTime;
            item.Creator          = CurrentUser.Employee;
            item.Updater          = item.Creator;
            item.Warehouse        = Warehouse.Find(item.WarehouseId);
            item.Store            = item.Warehouse.Store;

            using (var scope = new TransactionScope()) {
                item.CreateAndFlush();
            }

            return(PartialView("Issues/_CreateSuccesful", new InventoryIssue {
                Id = item.Id
            }));
        }
Пример #12
0
        public HttpResponseMessage PutInventoryIssue(int Id, InventoryIssue _InventoryIssue)
        {
            HttpRequestMessage Request = new HttpRequestMessage();

            Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
            HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid Request");

            if (!ModelState.IsValid)
            {
                return(response);
            }

            if (Id != _InventoryIssue.IIID)
            {
                return(response);
            }

            try
            {
                bool IsItemAvailable = CheckAndUpdateItem(_InventoryIssue);
                if (IsItemAvailable)
                {
                    unitOfWork.InventoryIssueRepository.Update(_InventoryIssue);
                    unitOfWork.Save();
                    response = Request.CreateResponse(HttpStatusCode.Accepted, _InventoryIssue);
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.NotAcceptable, _InventoryIssue);
                }
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(response);
            }
            return(response);
        }
Пример #13
0
        public ActionResult ConfirmReturn(int id)
        {
            var item = SupplierReturn.Find (id);

            var qry = from x in item.Details
                  where x.Order.Id == id
                  group x by x.Warehouse into g
                  select new { Warehouse = g.Key, Details = g.ToList () };

            var dt = DateTime.Now;
            var employee = CurrentUser.Employee;

            using (var scope = new TransactionScope ()) {
                foreach (var x in qry) {
                    var master = new InventoryIssue {
                        Return = item,
                        Warehouse = x.Warehouse,
                        CreationTime = dt,
                        ModificationTime = dt,
                        Creator = employee,
                        Updater = employee,
                        Comment = string.Format (Resources.Message_SupplierReturn, item.Supplier.Name, item.PurchaseOrder.Id, item.Id)
                    };

                    master.Create ();

                    foreach (var y in x.Details) {
                        var detail = new InventoryIssueDetail {
                            Issue = master,
                            Product = y.Product,
                            Quantity = y.Quantity,
                            ProductCode = y.ProductCode,
                            ProductName = y.ProductName
                        };

                        detail.Create ();
                    }
                }

                item.IsCompleted = true;
                item.UpdateAndFlush ();
            }

            return RedirectToAction ("Index");
        }
Пример #14
0
        public ActionResult NewIssue(InventoryIssue item)
        {
            if (!ModelState.IsValid)
                return PartialView ("Issues/_Create", item);

            item.CreationTime = DateTime.Now;
            item.ModificationTime = item.CreationTime;
            item.Creator = CurrentUser.Employee;
            item.Updater = item.Creator;
            item.Warehouse = Warehouse.Find (item.WarehouseId);
            item.Store = item.Warehouse.Store;

            using (var scope = new TransactionScope ()) {
                item.CreateAndFlush ();
            }

            return PartialView ("Issues/_CreateSuccesful", new InventoryIssue { Id = item.Id });
        }
Пример #15
0
        public ViewResult PrintIssue(int id)
        {
            var item = InventoryIssue.Find(id);

            return(View("Issues/Print", item));
        }
Пример #16
0
 public ActionResult GetTotalQuantityIssue(int id)
 {
     return(PartialView("Issues/_TotalQuantity", InventoryIssue.Find(id)));
 }
Пример #17
0
 public ActionResult DiscardIssueChanges(int id)
 {
     return(PartialView("Issues/_MasterView", InventoryIssue.TryFind(id)));
 }
Пример #18
0
        public ActionResult EditIssue(InventoryIssue item)
        {
            var movement = InventoryIssue.Find (item.Id);

            movement.Warehouse = Warehouse.Find (item.WarehouseId);
            movement.Store = movement.Warehouse.Store;
            movement.Updater = CurrentUser.Employee;
            movement.ModificationTime = DateTime.Now;
            movement.Comment = item.Comment;

            using (var scope = new TransactionScope ()) {
                movement.UpdateAndFlush ();
            }

            return PartialView ("Issues/_MasterView", movement);
        }