view model for Internal Movements Internal Movements are the movements of commdity from one store to another on the same Hub
 public ActionResult Create()
 {
     var user = _userProfileService.GetUser(User.Identity.Name);
     var fromStore = _hubService.GetAllStoreByUser(user);
     var commodities = _commodityService.GetAllParents();
     var programs = _programService.GetAllProgramsForReport();
     var units = _unitService.GetAllUnit();
     var toStore = _hubService.GetAllStoreByUser(user);
     var reasons = _detailService.GetReasonByMaster(Master.Constants.REASON_FOR_INTERNAL_MOVMENT);
     var viewModel = new InternalMovementViewModel(fromStore, commodities, programs, units, toStore, reasons);
     return View(viewModel);
 }
 public ActionResult Create(InternalMovementViewModel viewModel)
 {
     var user = _userProfileService.GetUser(User.Identity.Name);
     var fromStore = _hubService.GetAllStoreByUser(user);
     var commodities = _commodityService.GetAllParents();
     var programs = _programService.GetAllProgramsForReport();
     var units = _unitService.GetAllUnit();
     var toStore = _hubService.GetAllStoreByUser(user);
     var reasons = _detailService.GetReasonByMaster(Master.Constants.REASON_FOR_INTERNAL_MOVMENT);
     var newViewModel = new InternalMovementViewModel(fromStore, commodities, programs, units, toStore, reasons);
     if (viewModel.QuantityInMt > _transactionService.GetCommodityBalanceForStack(viewModel.FromStoreId, viewModel.FromStackId, viewModel.CommodityId, viewModel.ShippingInstructionId, viewModel.ProjectCodeId))
     {
         ModelState.AddModelError("QuantityInMt", "you dont have sufficent ammout to transfer");
         return View(newViewModel);
     }
     if (viewModel.QuantityInMt <= 0)
     {
         ModelState.AddModelError("QuantityInMt", "You have nothing to transfer");
         return View(newViewModel);
     }
     _transactionService.SaveInternalMovementTrasnsaction(viewModel,user);
       //  _internalMovementService.AddNewInternalMovement(viewModel, user);
     return RedirectToAction("Index", "InternalMovement");
 }
Example #3
0
 public void AddNewInternalMovement(InternalMovementViewModel viewModel, UserProfile user)
 {
     //  _unitOfWork.TransactionRepository.SaveInternalMovementTrasnsaction(viewModel, user);
 }
 public void CanDoCreatePostback()
 {
     //ACT
     var internalMovementViewModel = new InternalMovementViewModel
         {
             //TODO: Seed data before tesing
         };
     var viewResult = _internalMovementController.Create(internalMovementViewModel) as ViewResult;
     
     //ASSERT
     Assert.NotNull(viewResult);
     var model = viewResult.Model;
     Assert.IsInstanceOf<InternalMovementViewModel>(model);
 }
Example #5
0
        /// <summary>
        /// </summary>
        /// <param name="viewModel"></param>
        /// <param name="user"></param>
        /// <exception cref="System.Exception"></exception>
        public void SaveInternalMovementTrasnsaction(InternalMovementViewModel viewModel, UserProfile user)
        {
            InternalMovement internalMovement = new InternalMovement();
            TransactionGroup transactionGroup = new TransactionGroup();
            Transaction transactionFromStore = new Transaction();
            var transactionGroupId = Guid.NewGuid();

            Commodity commodity = _unitOfWork.CommodityRepository.FindById(viewModel.CommodityId);

            transactionFromStore.TransactionID = Guid.NewGuid();
            transactionFromStore.TransactionGroupID = transactionGroupId;
            transactionFromStore.LedgerID = 2;
            transactionFromStore.HubOwnerID = user.DefaultHubObj.HubOwner.HubOwnerID;
            //trasaction.AccountID
            transactionFromStore.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); //
            transactionFromStore.HubID = user.DefaultHub.Value;
            transactionFromStore.StoreID = viewModel.FromStoreId;  //
            transactionFromStore.Stack = viewModel.FromStackId; //
            transactionFromStore.ProjectCodeID = viewModel.ProjectCodeId;
            transactionFromStore.ShippingInstructionID = viewModel.ShippingInstructionId;
            transactionFromStore.ProgramID = viewModel.ProgramId;
            transactionFromStore.ParentCommodityID = (commodity.ParentID == null)
                                                       ? commodity.CommodityID
                                                       : commodity.ParentID.Value;
            transactionFromStore.CommodityID = viewModel.CommodityId;
            transactionFromStore.CommodityGradeID = null; // How did I get this value ?
            transactionFromStore.QuantityInMT = 0 - viewModel.QuantityInMt;
            transactionFromStore.QuantityInUnit = 0 - viewModel.QuantityInUnit;
            transactionFromStore.UnitID = viewModel.UnitId;
            transactionFromStore.TransactionDate = DateTime.Now;

            Transaction transactionToStore = new Transaction();

            transactionToStore.TransactionID = Guid.NewGuid();
            transactionToStore.TransactionGroupID = transactionGroupId;
            transactionToStore.LedgerID = 2;
            transactionToStore.HubOwnerID = user.DefaultHubObj.HubOwner.HubOwnerID;
            //transactionToStore.AccountID
            transactionToStore.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); //
            transactionToStore.HubID = user.DefaultHub.Value;
            transactionToStore.StoreID = viewModel.ToStoreId;  //
            transactionToStore.Stack = viewModel.ToStackId; //
            transactionToStore.ProjectCodeID = viewModel.ProjectCodeId;
            transactionToStore.ShippingInstructionID = viewModel.ShippingInstructionId;
            transactionToStore.ProgramID = viewModel.ProgramId;

            transactionToStore.ParentCommodityID = (commodity.ParentID == null)
                                                       ? commodity.CommodityID
                                                       : commodity.ParentID.Value;
            transactionToStore.CommodityID = viewModel.CommodityId;
            transactionToStore.CommodityGradeID = null; // How did I get this value ?
            transactionToStore.QuantityInMT = viewModel.QuantityInMt;
            transactionToStore.QuantityInUnit = viewModel.QuantityInUnit;
            transactionToStore.UnitID = viewModel.UnitId;
            transactionToStore.TransactionDate = DateTime.Now;

            transactionGroup.TransactionGroupID = transactionGroupId;
            transactionGroup.Transactions.Add(transactionFromStore);
            transactionGroup.Transactions.Add(transactionToStore);
            transactionGroup.PartitionId = 0;

            internalMovement.InternalMovementID = Guid.NewGuid();
            internalMovement.PartitionId = 0;
            internalMovement.TransactionGroupID = transactionGroupId;
            internalMovement.TransactionGroup = transactionGroup;
            internalMovement.TransferDate = viewModel.SelectedDate;
            internalMovement.DReason = viewModel.ReasonId;
            internalMovement.Notes = viewModel.Note;
            internalMovement.ApprovedBy = viewModel.ApprovedBy;
            internalMovement.ReferenceNumber = viewModel.ReferenceNumber;
            internalMovement.HubID = user.DefaultHub.Value;

            // Try to save this transaction

            try
            {
                _unitOfWork.InternalMovementRepository.Add(internalMovement);
                _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);
            }
        }