Пример #1
0
        public IEnumerable <StockAdjustmentViewModel> GetAllStockAdjustments()
        {
            stockAdjustmentService = new StockAdjustmentService(Context);

            List <StockAdjustment>          list = stockAdjustmentService.FindAllStockAdjustment();
            List <StockAdjustmentViewModel> sadj = new List <StockAdjustmentViewModel>();


            foreach (StockAdjustment s in list)
            {
                StockAdjustmentViewModel savm = new StockAdjustmentViewModel();

                savm.StockAdjustmentId    = s.StockAdjustmentId;
                savm.CreatedBy            = s.CreatedBy == null?"":s.CreatedBy.FirstName + " " + s.CreatedBy.LastName;
                savm.ApprovedBySupervisor = s.ApprovedBySupervisor == null ? "" : s.ApprovedBySupervisor.FirstName + " " + s.ApprovedBySupervisor.LastName;
                savm.CreatedDateTime      = s.CreatedDateTime.ToString("yyyy-MM-dd HH: mm:ss");
                savm.StatusName           = s.Status.Name;
                if (s.ApprovedByManager != null && s.ApprovedBySupervisor == null)
                {
                    savm.ApprovedBySupervisor = s.ApprovedByManager.FirstName + " " + s.ApprovedByManager.LastName;
                }
                else if (s.ApprovedByManager == null && s.ApprovedBySupervisor != null)
                {
                    savm.ApprovedBySupervisor = s.ApprovedBySupervisor.FirstName + " " + s.ApprovedBySupervisor.LastName;
                }
                else if (s.ApprovedByManager == null && s.ApprovedBySupervisor == null)
                {
                    savm.ApprovedBySupervisor = "";
                }
                sadj.Add(savm);
            }
            return(sadj);
        }
        public ActionResult DetailsNoEdit(string id)
        {
            stockAdjustmentService = new StockAdjustmentService(context);
            //get the stockadjustment
            StockAdjustment          sa = stockAdjustmentService.FindStockAdjustmentById(id);
            StockAdjustmentViewModel sv = new StockAdjustmentViewModel();

            sv.StockAdjustmentId = sa.StockAdjustmentId;
            sv.CreatedBy         = (sa.CreatedBy == null) ? "" : sa.CreatedBy.FirstName + " " + sa.CreatedBy.LastName;
            sv.CreatedDateTime   = sa.CreatedDateTime.ToString("yyyy-MM-dd HH: mm:ss");

            if (sa.ApprovedBySupervisor == null && sa.ApprovedByManager == null)
            {
                sv.ApprovedBySupervisor = "";
            }
            else if (sa.ApprovedBySupervisor != null && sa.ApprovedByManager == null)
            {
                sv.ApprovedBySupervisor = sa.ApprovedBySupervisor.FirstName + " " + sa.ApprovedBySupervisor.LastName;
            }
            else if (sa.ApprovedBySupervisor == null && sa.ApprovedByManager != null)
            {
                sv.ApprovedBySupervisor = sa.ApprovedByManager.FirstName + " " + sa.ApprovedByManager.LastName;
            }

            if (sa.UpdatedDateTime != null)
            {
                DateTime updatetime = (DateTime)sa.UpdatedDateTime;
                sv.UpdateDateTime = updatetime.ToString("yyyy-MM-dd HH: mm:ss");
            }
            else
            {
            }

            return(View(sv));
        }
        // GET: StockAdjustment View
        public ActionResult Index()
        {
            var viewModel = new StockAdjustmentViewModel()
            {
                StockAdjustments = stockAdjustmentService.GetAll(),
                Items            = itemService.GetAll()
            };

            return(View(viewModel));
        }
        public ActionResult DetailsEdit(string Id)
        {
            stockAdjustmentService = new StockAdjustmentService(context);
            userService            = new UserService(context);
            //get the stockadjustment
            StockAdjustment          sa = stockAdjustmentService.FindStockAdjustmentById(Id);
            StockAdjustmentViewModel sv = new StockAdjustmentViewModel();

            sv.StockAdjustmentId = sa.StockAdjustmentId;
            sv.CreatedBy         = (sa.CreatedBy == null) ? "" : sa.CreatedBy.FirstName + " " + sa.CreatedBy.LastName;
            sv.CreatedDateTime   = sa.CreatedDateTime.ToString("yyyy-MM-dd HH: mm:ss");
            sv.StatusName        = sa.Status.Name;
            if (sa.ApprovedBySupervisor == null && sa.ApprovedByManager == null)
            {
                sv.ApprovedBySupervisor = "";
            }
            else if (sa.ApprovedBySupervisor != null && sa.ApprovedByManager == null)
            {
                sv.ApprovedBySupervisor = sa.ApprovedBySupervisor.FirstName + " " + sa.ApprovedBySupervisor.LastName;
            }
            else if (sa.ApprovedBySupervisor == null && sa.ApprovedByManager != null)
            {
                sv.ApprovedBySupervisor = sa.ApprovedByManager.FirstName + " " + sa.ApprovedByManager.LastName;
            }
            if (sa.UpdatedDateTime != null)
            {
                DateTime updatetime = (DateTime)sa.UpdatedDateTime;
                sv.UpdateDateTime = updatetime.ToString("yyyy-MM-dd HH: mm:ss");
            }
            else
            {
            }

            //string UserName = System.Web.HttpContext.Current.User.Identity.GetUserName();
            Department d = userService.FindUserByEmail(CurrentUserName).Department;

            List <ApplicationUser> supervisors = new List <ApplicationUser>();

            List <ApplicationUser> managers = new List <ApplicationUser>();

            if (d != null)
            {
                supervisors = userService.FindSupervisorsByDepartment(d);
                managers    = new List <ApplicationUser>()
                {
                    d.Head
                };
            }

            sv.supervisors = supervisors;
            sv.managers    = managers;

            return(View(sv));
        }
        public ActionResult StockAdjustmentApprovedList()
        {
            var viewModel = new StockAdjustmentViewModel()
            {
                StockAdjustments = stockAdjustmentService.GetAll().Where(sa => sa.Status == CustomStatus.Approved),
                Items            = itemService.GetAll()
            };

            ViewBag.SaView = "Showing Results for Approved List";
            return(View("Index", viewModel));
        }
        public void Process_Test()
        {
            // Arrange
            StockAdjustmentController controller = new StockAdjustmentController()
            {
                CurrentUserName = "******",
                context         = this.context
            };
            // Act
            ViewResult result = controller.Process("he01") as ViewResult;
            StockAdjustmentViewModel viewmodel = (StockAdjustmentViewModel)result.Model;

            //Assert

            Assert.AreEqual(viewmodel.ApprovedBySupervisor, "Store Supervisor");
        }
        public void DetailsEdit_Test()
        {
            // Arrange
            StockAdjustmentController controller = new StockAdjustmentController()
            {
                CurrentUserName = "******",
                context         = this.context
            };
            // Act
            ViewResult result = controller.DetailsEdit("he01") as ViewResult;
            StockAdjustmentViewModel viewmodel = (StockAdjustmentViewModel)result.Model;

            //Assert

            Assert.IsNotNull(result);
        }
        public ActionResult Details(string id)
        {
            //Get stockAdjustment
            var stockAdjustment = stockAdjustmentService.Get(id);
            //Get list of itemStockAdjustments
            var itemStockAdjustments = itemStockAdjustmentService.FindByStockAdjustmentId(stockAdjustment.Id);

            var stockAdjustmentViewModel = new StockAdjustmentViewModel()
            {
                Id      = stockAdjustment.Id,
                Remarks = stockAdjustment.Remarks,
                itemStockAdjustments = itemStockAdjustments,
                Status = stockAdjustment.Status
            };

            return(View(stockAdjustmentViewModel));
        }
        public void GetAllStockadjustment_ContainResult()
        {
            //Arrange
            //Instantiate controller
            var controller = new StockAdjustmentAPIController();

            StockAdjustment sa1 = new StockAdjustment();

            sa1.StockAdjustmentId = "he01";
            sa1.Remarks           = "THIS IS A TEST";
            sa1.CreatedDateTime   = DateTime.Now;
            sa1.Status            = statusRepository.FindById(3);

            StockAdjustmentDetail s1 = new StockAdjustmentDetail();

            s1.StockAdjustmentId = "he01";
            s1.ItemCode          = "C001";
            s1.OriginalQuantity  = 10;
            s1.AfterQuantity     = 20;
            StockAdjustmentDetail s2 = new StockAdjustmentDetail();

            s2.StockAdjustmentId = "he01";
            s2.ItemCode          = "C002";
            s2.OriginalQuantity  = 20;
            s2.AfterQuantity     = 30;
            List <StockAdjustmentDetail> list = new List <StockAdjustmentDetail>();

            list.Add(s1);
            list.Add(s2);
            sa1.StockAdjustmentDetails = list;
            saRepository.Save(sa1);

            //Act
            StockAdjustmentViewModel result = controller.GetAllStockAdjustments().OrderByDescending
                                                  (x => x.CreatedDateTime).First();

            //Assert
            Assert.AreEqual(sa1.StockAdjustmentId, result.StockAdjustmentId);
            saRepository.Delete(saRepository.FindById("he01"));
        }
Пример #10
0
        public StockAdjustmentViewModel SaveStockAdjustment(StockAdjustmentViewModel model)
        {
            exceptionService.Execute((m) =>
            {
                model.DocumentSetupId = (int)eDocumentSetup.StockAdjustment;

                if (model.Details.Count == 0)
                {
                    model.Errors.Add(new ValidationResult("Please enter detail.", new string[] { "" }));
                }
                else
                {
                    if (model.Details.Any(x => x.SectionId == 0))
                    {
                        model.Errors.Add(new ValidationResult("Please select dept./section in item list.", new string[] { "" }));
                    }
                    if (model.Details.Any(x => x.Rate < 1))
                    {
                        model.Errors.Add(new ValidationResult("Please enter rate in item list.", new string[] { "" }));
                    }
                    if (model.Details.Any(x => x.NetAmount < 1))
                    {
                        model.Errors.Add(new ValidationResult("Net amount in item list is missing.", new string[] { "" }));
                    }
                }

                if (model.AdjustmentTypeId == 0)
                {
                    model.Errors.Add(new ValidationResult("Please select adjustment type.", new string[] { "" }));
                }

                if (model.Errors.Any())
                {
                    return;
                }

                if (!model.Validate())
                {
                    return;
                }

                model.Date = model.DateBS.GetDate();

                var entity = new StockTransaction();

                if (model.Id > 0)
                {
                    entity = stockTransactionReporsitory.GetById(model.Id);
                    entity.AdjustmentTypeId = model.AdjustmentTypeId;
                    entity.Date             = model.Date;
                    entity.Remarks          = model.Remarks;
                    stockTransanctionDetailRepository.DeleteRange(entity.StockTransactionDetails);
                }
                else
                {
                    entity = AutomapperConfig.Mapper.Map <StockTransaction>(model);

                    stockTransactionReporsitory.Insert(entity);
                }

                foreach (var item in model.Details)
                {
                    var adjustmentType        = adjustmentTypeRepository.GetById(model.AdjustmentTypeId);
                    var detail                = AutomapperConfig.Mapper.Map <StockTransactionDetail>(item);
                    detail.StockTransactionId = entity.Id;
                    detail.StockEffect        = (adjustmentType.InOut == eStockInOutType.In.ToString()) ? (int)StockEffect.Add : (int)StockEffect.Deduct;
                    detail.NetAmount          = item.NetAmount;
                    stockTransanctionDetailRepository.Insert(detail);
                }

                if (model.Id == 0)
                {
                    model.Message = localizationService.GetLocalizedText("Message.DataSavedSuccessfully", "Data saved successfully.");
                }
                else
                {
                    model.Message = localizationService.GetLocalizedText("Message.DataSavedSuccessfully", "Save changes successfully.");
                }
            }, model);
            return(model);
        }
Пример #11
0
        public void RoolbackAllocation(StockAdjustmentViewModel viewModel, UserProfile user)
        {
            Commodity commodity = _unitOfWork.CommodityRepository.FindById((int)viewModel.CommodityID);



            Adjustment       lossAndAdjustment = new Adjustment();
            TransactionGroup transactionGroup  = new TransactionGroup();
            Transaction      transactionOne    = new Transaction();

            var transactionGroupId = Guid.NewGuid();

            transactionOne.TransactionID      = Guid.NewGuid();
            transactionOne.TransactionGroupID = transactionGroupId;
            transactionOne.LedgerID           = Cats.Models.Ledger.Constants.PLEDGED_TO_FDP;// 2;
            transactionOne.HubOwnerID         = user.DefaultHubObj.HubOwner.HubOwnerID;
            //transactionOne.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); //
            transactionOne.HubID                 = user.DefaultHub.Value;
            transactionOne.StoreID               = viewModel.StoreID; //
            transactionOne.ProjectCodeID         = viewModel.ProjectCodeID;
            transactionOne.ShippingInstructionID = viewModel.ShippingInstructionID;

            transactionOne.ParentCommodityID = (commodity.ParentID == null)
                                                       ? commodity.CommodityID
                                                       : commodity.ParentID.Value;
            transactionOne.CommodityID      = viewModel.CommodityID;
            transactionOne.ProgramID        = viewModel.ProgramID;
            transactionOne.CommodityGradeID = null; // How did I get this value ?

            transactionOne.QuantityInMT   = 0 - viewModel.QuantityInMT;
            transactionOne.QuantityInUnit = 0 - viewModel.QuantityInUnit;


            transactionOne.UnitID          = 1;
            transactionOne.TransactionDate = DateTime.Now;



            Transaction transactionTwo = new Transaction();

            transactionTwo.TransactionID      = Guid.NewGuid();
            transactionTwo.TransactionGroupID = transactionGroupId;
            transactionTwo.LedgerID           = Cats.Models.Ledger.Constants.COMMITED_TO_FDP;// 14;
            transactionTwo.HubOwnerID         = user.DefaultHubObj.HubOwnerID;
            //transactionTwo.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); //
            transactionTwo.HubID                 = user.DefaultHub.Value;
            transactionTwo.StoreID               = viewModel.StoreID; //
            transactionTwo.ProjectCodeID         = viewModel.ProjectCodeID;
            transactionTwo.ShippingInstructionID = viewModel.ShippingInstructionID;
            transactionTwo.ParentCommodityID     = (commodity.ParentID == null)
                                                       ? commodity.CommodityID
                                                       : commodity.ParentID.Value;
            transactionTwo.CommodityID      = viewModel.CommodityID;
            transactionTwo.ProgramID        = viewModel.ProgramID;
            transactionTwo.CommodityGradeID = null; // How did I get this value ?


            transactionTwo.QuantityInMT   = viewModel.QuantityInMT;
            transactionTwo.QuantityInUnit = viewModel.QuantityInUnit;


            transactionTwo.UnitID          = 1;
            transactionTwo.TransactionDate = DateTime.Now;

            transactionGroup.TransactionGroupID = transactionGroupId;
            transactionGroup.Transactions.Add(transactionOne);
            transactionGroup.Transactions.Add(transactionTwo);


            lossAndAdjustment.PartitionId        = 0;
            lossAndAdjustment.AdjustmentID       = Guid.NewGuid();
            lossAndAdjustment.TransactionGroupID = transactionGroupId;
            lossAndAdjustment.TransactionGroup   = transactionGroup;
            lossAndAdjustment.HubID = user.DefaultHub.Value;
            lossAndAdjustment.AdjustmentReasonID  = 7;
            lossAndAdjustment.AdjustmentDirection = "A";
            lossAndAdjustment.AdjustmentDate      = DateTime.Now.Date;
            lossAndAdjustment.ApprovedBy          = "";
            lossAndAdjustment.Remarks             = "Stock take adjustement - Allocation";
            lossAndAdjustment.UserProfileID       = user.UserProfileID;
            lossAndAdjustment.ReferenceNumber     = "";
            lossAndAdjustment.StoreManName        = "";



            // Try to save this transaction
            try
            {
                _unitOfWork.AdjustmentRepository.Add(lossAndAdjustment);
                _unitOfWork.Save();
            }
            catch (Exception exp)
            {
                // dbTransaction.Rollback();
                //TODO: Save the detail of this exception somewhere
                throw new Exception("The Internal Movement Transaction Cannot be saved. <br />Detail Message :" + exp.Message);
            }
        }
Пример #12
0
        public IEnumerable <StockAdjustmentViewModel> GetAllStockAdjustmentsExceptDraft()
        {
            stockAdjustmentService = new StockAdjustmentService(Context);
            notificationService    = new NotificationService(Context);
            userService            = new UserService(Context);

            List <StockAdjustment>          list = stockAdjustmentService.FindAllStockAdjustmentExceptDraft();
            List <StockAdjustmentViewModel> sadj = new List <StockAdjustmentViewModel>();
            //supervisor and manager process the stock adjustments which are sent to them
            List <Notification> notifications = new List <Notification>();
            List <string>       Ids           = new List <string>();

            if (notificationService.FindNotificationsByUser(userService.FindUserByEmail(CurrentUserName)).Count == 0)
            {
            }
            else
            {
                notifications = notificationService.FindNotificationsByUser(userService.FindUserByEmail(CurrentUserName));
                foreach (Notification n in notifications)
                {
                    var stockAdjustmentId = Regex.Match(n.Contents, @"ADJ-\d{6}-\d{3}");
                    Ids.Add(Convert.ToString(stockAdjustmentId));
                }
            }

            foreach (StockAdjustment s in list)
            {
                StockAdjustmentViewModel savm = new StockAdjustmentViewModel();

                savm.StockAdjustmentId = s.StockAdjustmentId;
                savm.CreatedBy         = s.CreatedBy == null ? "" : s.CreatedBy.FirstName + " " + s.CreatedBy.LastName;
                if (s.ApprovedByManager != null && s.ApprovedBySupervisor == null)
                {
                    savm.ApprovedBySupervisor = s.ApprovedByManager.FirstName + " " + s.ApprovedByManager.LastName;
                }
                else if (s.ApprovedByManager == null && s.ApprovedBySupervisor != null)
                {
                    savm.ApprovedBySupervisor = s.ApprovedBySupervisor.FirstName + " " + s.ApprovedBySupervisor.LastName;
                }
                else if (s.ApprovedByManager == null && s.ApprovedBySupervisor == null)
                {
                    savm.ApprovedBySupervisor = "";
                }



                savm.CreatedDateTime = s.CreatedDateTime.ToString("yyyy-MM-dd HH: mm:ss");
                savm.StatusName      = s.Status.Name;

                if (notificationService.GetCreatedFor(savm.StockAdjustmentId) != null)

                {
                    savm.ProcessBy = notificationService.GetCreatedFor(savm.StockAdjustmentId).FirstName + " " + notificationService.GetCreatedFor(savm.StockAdjustmentId).LastName;
                }
                else
                {
                    savm.ProcessBy = "";
                }


                if (Ids.Contains(savm.StockAdjustmentId))
                {
                    savm.IsSentFor = 1;
                }
                else
                {
                    savm.IsSentFor = 0;
                }



                sadj.Add(savm);
            }

            return(sadj);
        }