public ActionResult CreateAdjustment(LossesAndAdjustmentsViewModel viewModel) { var newViewModel = new LossesAndAdjustmentsViewModel(); var user = _userProfileService.GetUser(User.Identity.Name); viewModel.IsLoss = false; _adjustmentService.AddNewLossAndAdjustment(viewModel, user); return RedirectToAction("Index"); }
public ActionResult CreateAdjustment() { var user = _userProfileService.GetUser(User.Identity.Name); var commodity = _commodityService.GetAllParents(); var stores = _hubService.GetAllStoreByUser(user); var adjustmentReasonMinus = _adjustmentReasonService.GetAllAdjustmentReason().Where(c => c.Direction == "-").ToList(); var adjustmentReasonPlus = _adjustmentReasonService.GetAllAdjustmentReason().Where(c => c.Direction == "+").ToList(); var units = _unitService.GetAllUnit().ToList(); var programs = _programService.GetAllProgramsForReport(); var viewModel = new LossesAndAdjustmentsViewModel(commodity, stores, adjustmentReasonMinus, adjustmentReasonPlus, units, programs, user, 2); return View(viewModel); }
public ActionResult CreateAdjustment() { List<Commodity> commodity; List<StoreViewModel> stores; List<AdjustmentReason> adjustmentReasonMinus; List<AdjustmentReason> adjustmentReasonPlus; List<Unit> units; List<ProgramViewModel> programs; UserProfile user = _userProfileService.GetUser(User.Identity.Name); commodity = _commodityService.GetAllParents(); stores = _hubService.GetAllStoreByUser(user); adjustmentReasonMinus = _adjustmentReasonService.GetAllAdjustmentReason().Where(c => c.Direction == "-").ToList(); adjustmentReasonPlus = _adjustmentReasonService.GetAllAdjustmentReason().Where(c => c.Direction == "+").ToList(); units = _unitService.GetAllUnit().ToList(); programs = _programService.GetAllProgramsForReport(); LossesAndAdjustmentsViewModel viewModel = new LossesAndAdjustmentsViewModel(commodity, stores, adjustmentReasonMinus, adjustmentReasonPlus, units, programs, user, 2); return View(viewModel); }
public ActionResult CreateLoss(LossesAndAdjustmentsViewModel viewModel) { List<Commodity> commodity; List<StoreViewModel> stores; List<AdjustmentReason> adjustmentReasonMinus; List<AdjustmentReason> adjustmentReasonPlus; List<Unit> units; List<ProgramViewModel> programs; UserProfile user = _userProfileService.GetUser(User.Identity.Name); commodity = _commodityService.GetAllParents(); stores = _hubService.GetAllStoreByUser(user); adjustmentReasonMinus = _adjustmentReasonService.GetAllAdjustmentReason().Where(c => c.Direction == "-").ToList(); adjustmentReasonPlus = _adjustmentReasonService.GetAllAdjustmentReason().Where(c => c.Direction == "+").ToList(); units = _unitService.GetAllUnit().ToList(); programs = _programService.GetAllProgramsForReport(); //if (ModelState.IsValid) //{ LossesAndAdjustmentsViewModel newViewModel = new LossesAndAdjustmentsViewModel(commodity, stores, adjustmentReasonMinus, adjustmentReasonPlus, units, programs, user, 1); if (viewModel.QuantityInMt > _TransactionService.GetCommodityBalanceForStore(viewModel.StoreId, viewModel.CommodityId, viewModel.ShippingInstructionId, viewModel.ProjectCodeId)) { ModelState.AddModelError("QuantityInMT", "You have nothing to loss"); return View(newViewModel); } if (viewModel.QuantityInMt <= 0) { ModelState.AddModelError("QuantityInMT", "You have nothing to loss"); return View(newViewModel); } viewModel.IsLoss = true; _adjustmentService.AddNewLossAndAdjustment(viewModel, user); return RedirectToAction("Index"); //} //return View(); }
public void AddNewLossAndAdjustment(LossesAndAdjustmentsViewModel viewModel, UserProfile user) { _transactionService.SaveLossAdjustmentTransaction(viewModel, user); }
/// <summary> /// </summary> /// <param name="viewModel"></param> /// <param name="user"></param> /// <exception cref="System.Exception"></exception> public void SaveLossTrasnsaction(LossesAndAdjustmentsViewModel viewModel, UserProfile user) { Commodity commodity = _unitOfWork.CommodityRepository.FindById(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.GOODS_ON_HAND;// 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.QuantityInUint; transactionOne.UnitID = viewModel.UnitId; transactionOne.TransactionDate = DateTime.Now; Transaction transactionTwo = new Transaction(); transactionTwo.TransactionID = Guid.NewGuid(); transactionTwo.TransactionGroupID = transactionGroupId; transactionTwo.LedgerID = Cats.Models.Ledger.Constants.LOSS_IN_TRANSIT;// 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.QuantityInUint; transactionTwo.UnitID = viewModel.UnitId; 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 = viewModel.ReasonId; lossAndAdjustment.AdjustmentDirection = "L"; lossAndAdjustment.AdjustmentDate = viewModel.SelectedDate; lossAndAdjustment.ApprovedBy = viewModel.ApprovedBy; lossAndAdjustment.Remarks = viewModel.Description; lossAndAdjustment.UserProfileID = user.UserProfileID; lossAndAdjustment.ReferenceNumber = viewModel.MemoNumber; lossAndAdjustment.StoreManName = viewModel.StoreMan; // 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); } }
/// <summary> /// Saves the loss adjustment transaction. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="user">The user.</param> public void SaveLossAdjustmentTransaction(LossesAndAdjustmentsViewModel viewModel, UserProfile user) { if (viewModel.IsLoss == true) { SaveLossTrasnsaction(viewModel, user); } else { SaveAdjustmentTrasnsaction(viewModel, user); } }