public ActionResult SINumberBalance(int?parentCommodityId, int?projectcode, int?SINumber, int?StoreId, int?StackId) { StoreBalanceViewModel viewModel = new StoreBalanceViewModel(); UserProfile user = _userProfileService.GetUser(User.Identity.Name); if (!StoreId.HasValue && !StackId.HasValue && parentCommodityId.HasValue && projectcode.HasValue && SINumber.HasValue) { viewModel.ParentCommodityNameB = _commodityService.FindById(parentCommodityId.Value).Name; viewModel.ProjectCodeNameB = _projectCodeService.FindById(projectcode.Value).Value; viewModel.ShppingInstructionNumberB = _shippingInstructionService.FindById(SINumber.Value).Value; viewModel.QtBalance = _TransactionService.GetCommodityBalanceForHub(user.DefaultHub.Value, parentCommodityId.Value, SINumber.Value, projectcode.Value); } else if (StoreId.HasValue && !StackId.HasValue && parentCommodityId.HasValue && projectcode.HasValue && SINumber.HasValue) { viewModel.ParentCommodityNameB = _commodityService.FindById(parentCommodityId.Value).Name; viewModel.ProjectCodeNameB = _projectCodeService.FindById(projectcode.Value).Value; viewModel.ShppingInstructionNumberB = _shippingInstructionService.FindById(SINumber.Value).Value; viewModel.QtBalance = _TransactionService.GetCommodityBalanceForStore(StoreId.Value, parentCommodityId.Value, SINumber.Value, projectcode.Value); var store = _storeService.FindById(StoreId.Value); viewModel.StoreNameB = string.Format("{0} - {1}", store.Name, store.StoreManName); } else if (StoreId.HasValue && StackId.HasValue && parentCommodityId.HasValue && projectcode.HasValue && SINumber.HasValue) { viewModel.ParentCommodityNameB = _commodityService.FindById(parentCommodityId.Value).Name; viewModel.ProjectCodeNameB = _projectCodeService.FindById(projectcode.Value).Value; viewModel.ShppingInstructionNumberB = _shippingInstructionService.FindById(SINumber.Value).Value; viewModel.QtBalance = _TransactionService.GetCommodityBalanceForStack(StoreId.Value, StackId.Value, parentCommodityId.Value, SINumber.Value, projectcode.Value); var store = _storeService.FindById(StoreId.Value); viewModel.StoreNameB = string.Format("{0} - {1}", store.Name, store.StoreManName); viewModel.StackNumberB = StackId.Value.ToString(); } return(PartialView(viewModel)); }
public ActionResult Commodity_Update([DataSourceRequest] DataSourceRequest request, CommodityViewModel commodityViewModel) { if (commodityViewModel != null && ModelState.IsValid) { var target = _commodityService.FindById(commodityViewModel.CommodityID); var commodity = CommodityViewModelBinder.BindCommodity(commodityViewModel, target); _commodityService.EditCommodity(commodity); } return(Json(new[] { commodityViewModel }.ToDataSourceResult(request, ModelState))); }
public JsonResult GetRation() { var ration = _rationService.Get(t => (bool)t.IsDefaultRation, null, "RationDetails").FirstOrDefault(); var rationViewModel = (from item in ration.RationDetails select new { _commodityService.FindById(item.CommodityID).Name, Value = item.Amount }); return(Json(rationViewModel, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(string receiptAllocationId, string grn) { if (grn != null) { return(View(ModeltoNewView(_receiveService.FindById(Guid.Parse(receiptAllocationId))))); } if (String.IsNullOrEmpty(receiptAllocationId)) { return(View()); } _receiptAllocationId = Guid.Parse(receiptAllocationId); var receiptAllocation = _receiptAllocationService.FindById(_receiptAllocationId); var user = _userProfileService.GetUser(User.Identity.Name); if (receiptAllocation == null || (user.DefaultHub == null || receiptAllocation.HubID != user.DefaultHub.Value)) { return(View()); } var viewModel = _receiveService.ReceiptAllocationToReceive(receiptAllocation); viewModel.CurrentHub = user.DefaultHub.Value; viewModel.UserProfileId = user.UserProfileID; var hubOwner = _hub.FindById(user.DefaultHub.Value); viewModel.IsTransporterDetailVisible = !hubOwner.HubOwner.Name.Contains("WFP"); viewModel.AllocationStatusViewModel = _receiveService.GetAllocationStatus(_receiptAllocationId); //var commodities = _commodityService.GetAllCommodityViewModelsByParent(receiptAllocation.CommodityID); //ViewData["commodities"] = commodities; //ViewData["units"] = _unitService.GetAllUnitViewModels(); //viewModel.ReceiveDetailNewViewModel.CommodityId = receiptAllocation.CommodityID; //since the commodity that comes from allocation is the child look for the parent for saving later. var parentCommodityId = _commodityService.FindById(receiptAllocation.CommodityID).ParentID ?? receiptAllocation.CommodityID; viewModel.ReceiveDetailNewViewModel = new ReceiveDetailNewViewModel { CommodityId = parentCommodityId, CommodityChildID = receiptAllocation.CommodityID, //UnitId=receiptAllocation.UnitID.GetValueOrDefault(), }; return(View(viewModel)); }
private RationDetailViewModel BindRationDetailViewModel(RationDetail rationDetail) { RationDetailViewModel rationViewModel = null; if (rationDetail != null) { rationViewModel = new RationDetailViewModel(); rationViewModel.Amount = rationDetail.Amount; rationViewModel.Commodity = _commodityService.FindById(rationDetail.CommodityID).Name; rationViewModel.CommodityID = rationDetail.CommodityID; rationViewModel.RationID = rationDetail.RationID; rationViewModel.RationDetailID = rationDetail.RationDetailID; rationViewModel.UnitID = rationDetail.UnitID.HasValue?rationDetail.UnitID.Value:-1; // rationViewModel.UnitID = rationDetail.UnitID; rationViewModel.RationName = _rationService.FindById(rationDetail.RationID).RefrenceNumber; } return(rationViewModel); }
public ActionResult FDPsCoveredByDonorsPostBack([DataSourceRequest] DataSourceRequest request) { var coveredFDPsList = new List <FDPsCoveredByDonors>(); var regionalPSNPPledges = _regionalPSNPPledgeService.GetAllRegionalPSNPPledge(); foreach (var regionalPSNPPledge in regionalPSNPPledges) { var coveredFDPs = new FDPsCoveredByDonors(); coveredFDPs.Donor = regionalPSNPPledge.Donor.Name; //var fdpObj = _fdpService.FindById(regionalPSNPPlanDetail.PlanedFDPID); //var woredaAdminUnit = _adminUnitService.FindById(fdpObj.AdminUnitID); //coveredFDPs.FDP = fdpObj.Name; //coveredFDPs.Woreda = woredaAdminUnit.Name; //coveredFDPs.Zone = woredaAdminUnit.AdminUnit2.Name; //coveredFDPs.Region = woredaAdminUnit.AdminUnit2.AdminUnit2.Name; coveredFDPs.Commodity = _commodityService.FindById(regionalPSNPPledge.Commodity.CommodityID).Name; var regionalPSNPPlan = _regionalPSNPPlanService.FindById(regionalPSNPPledge.RegionalPSNPPlanID); //var rationDetails = _rationDetailService.Get(t => t.RationID == regionalPSNPPlan.RationID); //var pledge = regionalPSNPPledge; //decimal neededQty = 0; //const string neededQtyUnit = ""; //foreach (var rationDetail in rationDetails.Where(rationDetail => rationDetail.CommodityID == pledge.Commodity.CommodityID)) //{ // neededQty = rationDetail.Amount; //} //coveredFDPs.NeededQty = neededQty.ToString(CultureInfo.InvariantCulture); //coveredFDPs.NeededQtyUnit = neededQtyUnit; coveredFDPs.PledgedQty = regionalPSNPPledge.Quantity.ToString(CultureInfo.InvariantCulture); coveredFDPs.PledgedQtyUnit = regionalPSNPPledge.Unit.Name; coveredFDPs.PledgeDate = regionalPSNPPledge.PledgeDate.ToString(CultureInfo.InvariantCulture); coveredFDPsList.Add(coveredFDPs); } return(Json(coveredFDPsList.ToDataSourceResult(request), JsonRequestBehavior.AllowGet)); }
public ActionResult Create(DispatchModel dispatchModel) { var user = _userProfileService.GetUser(User.Identity.Name); var insertCommodities = new List <DispatchDetailModel>(); var updateCommodities = new List <DispatchDetailModel>(); var prevCommodities = new List <DispatchDetailModel>(); if (dispatchModel.JSONPrev != null) { prevCommodities = GetSelectedCommodities(dispatchModel.JSONPrev); //Even though they are updated they are not saved so move them in to the inserted at the end of a succcessful submit int count = 0; foreach (var dispatchDetailAllViewModels in prevCommodities) { if (dispatchDetailAllViewModels.Id != null) { count--; dispatchDetailAllViewModels.DispatchDetailCounter = count; insertCommodities.Add(dispatchDetailAllViewModels); } else { updateCommodities.Add(dispatchDetailAllViewModels); } } ViewBag.ReceiveDetails = prevCommodities; ViewBag.SelectedCommodities = prevCommodities; dispatchModel.DispatchDetails = prevCommodities; //this check need's to be revisited if (!prevCommodities.Any()) { ModelState.AddModelError("DispatchDetails", @"Please add atleast one commodity to save this Dispatch"); } string errorMessage = null; foreach (var dispatchDetailViewModel in prevCommodities) { var validationContext = new ValidationContext(dispatchDetailViewModel, null, null); var validationResults = dispatchDetailViewModel.Validate(validationContext); errorMessage = validationResults.Aggregate(errorMessage, (current, v) => string.Format("{0}, {1}", current, v.ErrorMessage)); var comms = _commodityService.FindById(dispatchDetailViewModel.CommodityID); var commType = _commodityTypeService.FindById(dispatchModel.CommodityTypeID); if (dispatchModel.CommodityTypeID != comms.CommodityTypeID) { ModelState.AddModelError("DispatchDetails", comms.Name + @" is not of type " + commType.Name); } } if (errorMessage != null) { ModelState.AddModelError("DispatchDetails", errorMessage); } } else { ModelState.AddModelError("DispatchDetails", @"Please add atleast one commodity to save this Dispatch"); } if (dispatchModel.Type != 1) { ModelState.Remove("FDPID"); ModelState.Remove("RegionID"); ModelState.Remove("WoredaID"); ModelState.Remove("ZoneID"); ModelState.Remove("BidNumber"); dispatchModel.BidNumber = "00000"; //NOT really needed ModelState.Remove("Year"); ModelState.Remove("Month"); } else { ModelState.Remove("ToHubID"); } if (ModelState.IsValid && user != null) { if (dispatchModel.ChangeStoreManPermanently) { var storeTobeChanged = _storeService.FindById(dispatchModel.StoreID); if (storeTobeChanged != null && dispatchModel.ChangeStoreManPermanently) { storeTobeChanged.StoreManName = dispatchModel.DispatchedByStoreMan; } } var dispatch = dispatchModel.GenerateDipatch(user); //if (dispatch.DispatchID == null ) if (dispatchModel.DispatchID == null) { dispatchModel.DispatchDetails = prevCommodities; foreach (var gridCommodities in prevCommodities) { if (user.PreferedWeightMeasurment.Equals("qn")) { gridCommodities.DispatchedQuantityMT /= 10; gridCommodities.RequestedQuantityMT /= 10; } } //InsertDispatch(dispatchModel, user); _transactionService.SaveDispatchTransaction(dispatchModel, user); } else { // List<Models.DispatchDetailModel> insertCommodities = GetSelectedCommodities(dispatchModel.JSONInsertedCommodities); var deletedCommodities = GetSelectedCommodities(dispatchModel.JSONDeletedCommodities); // List<Models.DispatchDetailModel> updateCommodities = GetSelectedCommodities(dispatchModel.JSONUpdatedCommodities); dispatch.HubID = user.DefaultHub.HubID; dispatch.Update(GenerateDispatchDetail(insertCommodities), GenerateDispatchDetail(updateCommodities), GenerateDispatchDetail(deletedCommodities)); } return(RedirectToAction("Index")); } //List<Models.DispatchDetailModel> details = GetSelectedCommodities(dispatchModel.JSONInsertedCommodities); //Session["SELCOM"] = details; // BLL.UserProfile user = BLL.UserProfile.GetUser(User.Identity.Name); PrepareCreate(dispatchModel.Type); if (dispatchModel.FDPID != null) { PrepareFDPForEdit(dispatchModel.FDPID); dispatchModel.WoredaID = _fdpService.FindById(dispatchModel.FDPID.Value).AdminUnitID; } //PrepareEdit(dispatchModel.GenerateDipatch(), user,dispatchModel.Type); return(View(dispatchModel)); }
// // GET: /Commodity/Details/5 public ViewResult Details(int id) { Commodity commodity = _commodityService.FindById(id); return(View("Details", commodity)); }
public ActionResult Create(ReceiptAllocationViewModel receiptAllocationViewModel) { if (receiptAllocationViewModel.CommoditySourceID == BLL.CommoditySource.Constants.DONATION) { ModelState.Remove("SourceHubID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); } else if (receiptAllocationViewModel.CommoditySourceID == BLL.CommoditySource.Constants.LOCALPURCHASE) { ModelState.Remove("DonorID"); ModelState.Remove("SourceHubID"); } else { ModelState.Remove("DonorID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); } if (!(IsSIValid(receiptAllocationViewModel.SINumber, receiptAllocationViewModel.CommoditySourceID))) { ModelState.AddModelError("SINumber", ""); } if (ModelState.IsValid) { BLL.ReceiptAllocation receiptAllocation = receiptAllocationViewModel.GenerateReceiptAllocation(); //for creation make the giftCetificate null if it's from if (receiptAllocationViewModel.GiftCertificateDetailID == 0 || receiptAllocationViewModel.GiftCertificateDetailID == null ) { var GC = _giftCertificateService.FindBySINumber(receiptAllocationViewModel.SINumber); if (GC != null) { var GCD = GC.GiftCertificateDetails.FirstOrDefault( p => p.CommodityID == receiptAllocationViewModel.CommodityID); if (GCD != null) //&& GCD.GiftCertificateDetailID; { receiptAllocation.GiftCertificateDetailID = GCD.GiftCertificateDetailID; } } else { receiptAllocation.GiftCertificateDetailID = null; } } int typeOfGridToReload = receiptAllocation.CommoditySourceID; int commType = _commodityService.FindById(receiptAllocation.CommodityID).CommodityTypeID; //override to default hub BLL.UserProfile user = _userProfileService.GetUser(User.Identity.Name); receiptAllocation.HubID = user.DefaultHub.HubID; if (typeOfGridToReload != DRMFSS.BLL.CommoditySource.Constants.DONATION && typeOfGridToReload != DRMFSS.BLL.CommoditySource.Constants.LOCALPURCHASE) { typeOfGridToReload = DRMFSS.BLL.CommoditySource.Constants.LOAN; } _receiptAllocationService.AddReceiptAllocation(receiptAllocation); return(Json(new { gridId = typeOfGridToReload, CommodityTypeID = commType }, JsonRequestBehavior.AllowGet)); //return RedirectToAction("Index"); } //check this out later //return this.Create(receiptAllocationViewModel.CommoditySourceID); //ModelState.Remove("SINumber"); //TODO:Check if commenting out has any effect //================================================= //receiptAllocationViewModel.InitalizeViewModel(); //================================================ return(PartialView(receiptAllocationViewModel)); }