public virtual ActionResult _ReceivePartial(string grnNo) { var commodities=_commodityService.GetAllCommodity().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var commodityGrades=_commodityGradeService.GetAllCommodityGrade().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var transporters=_transporterService.GetAllTransporter().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var commoditySources=_commoditySourceService.GetAllCommoditySource().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var commodityTypes=_commodityTypeService.GetAllCommodityType().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var programs=_programService.GetAllProgram().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var donors=_donorService.GetAllDonor().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var units = _unitService.GetAllUnit().OrderBy(o => o.Name).ToList(); BLL.UserProfile user = _userProfileService.GetUser(User.Identity.Name); var hubs = _hubService.GetAllWithoutId(user.DefaultHub.HubID).DefaultIfEmpty().OrderBy(o => o.Name).ToList(); BLL.Receive receive = BLL.Receive.GetReceiveByGRN(grnNo); if (receive != null && (receive.HubID == user.DefaultHub.HubID)) { return PartialView("_ReceivePartial", ReceiveViewModel.GenerateReceiveModel(receive,commodities,commodityGrades,transporters,commodityTypes,commoditySources,programs,donors,hubs,user)); } else if (receive != null && (receive.HubID != user.DefaultHub.HubID)) { ViewBag.Message = string.Format("The selected GRN Number {0} doesn't exist in your default warehouse. Try changing your default warehouse.",grnNo); } ViewBag.Stacks = new SelectList(Enumerable.Empty<SelectListItem>()); List<Models.ReceiveDetailViewModel> ReceiveCommodities = new List<Models.ReceiveDetailViewModel>(); ViewBag.ReceiveCommodities = ReceiveCommodities; var viewmode = new Models.ReceiveViewModel(commodities,commodityGrades,transporters,commodityTypes,commoditySources,programs,donors,hubs,user); // viewmode.GRN = grnNo; return PartialView("_ReceivePartial", viewmode); }
// // GET: /Receive/Create public virtual ActionResult Create(string receiveId) { BLL.UserProfile user = _userProfileService.GetUser(User.Identity.Name); var commodities = _commodityService.GetAllCommodity().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var commodityGrades = _commodityGradeService.GetAllCommodityGrade().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var transporters = _transporterService.GetAllTransporter().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var commoditySources = _commoditySourceService.GetAllCommoditySource().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var commodityTypes = _commodityTypeService.GetAllCommodityType().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var programs = _programService.GetAllProgram().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var donors = _donorService.GetAllDonor().DefaultIfEmpty().OrderBy(o => o.Name).ToList(); var units = _unitService.GetAllUnit().OrderBy(o => o.Name).ToList(); var hubs = _hubService.GetAllWithoutId(user.DefaultHub.HubID).DefaultIfEmpty().OrderBy(o => o.Name).ToList(); if (receiveId != "" && receiveId != null) { BLL.Receive receive = _receiveService.FindById(Guid.Parse(receiveId)); var stacks = new List<AdminUnitItem>(); if (receive != null && (receive.HubID == user.DefaultHub.HubID)) { var rViewModel= ReceiveViewModel.GenerateReceiveModel(receive, commodities, commodityGrades, transporters, commodityTypes, commoditySources, programs, donors, hubs, user); //TODO:=====================================Refactored from viewmodel needs refactor============================ if (rViewModel.StoreID != 0) { BLL.Store store = _storeService.FindById(rViewModel.StoreID); foreach (var i in store.Stacks) { stacks.Add(new AdminUnitItem { Name = i.ToString(), Id = i }); } } rViewModel.Stacks = stacks; //=============================================================================================================== return View("Create", rViewModel); } else if (receive != null && (receive.HubID != user.DefaultHub.HubID)) { ViewBag.Message = string.Format( "The selected GRN Number {0} doesn't exist in your default warehouse. Try changing your default warehouse.", receive.GRN); } } // Hack ViewBag.Stacks = new SelectList(Enumerable.Empty<SelectListItem>()); List<Models.ReceiveDetailViewModel> receiveCommodities = new List<Models.ReceiveDetailViewModel>(); ViewBag.ReceiveCommodities = receiveCommodities; //TODO:Stacks shuld be sent basend storeID var receiveViewModel = new Models.ReceiveViewModel(commodities, commodityGrades, transporters, commodityTypes, commoditySources, programs, donors, hubs, user); if (Request["type"] != null) { receiveViewModel.CommoditySourceID = Convert.ToInt32(Request["type"]); } else { receiveViewModel.CommoditySourceID = 1; } //receiveViewModel.SINumber = Request["SINumber"]; if (Request["ReceiptAllocationID"] != null) { Guid receiptAllocationID = Guid.Parse(Request["ReceiptAllocationID"]); //Added (p.HubID == user.DefaultHub.HubID) check to load allocation only for the current user's defalt Hub //get populate using allocation by current hub,comsource and and si number,and not closed //TODO use the merge function to have swap,repay,..and others //var rAllocation = repository.ReceiptAllocation.GetAllByTypeMerged(receiveViewModel.CommoditySourceID) // .FirstOrDefault(p => p.SINumber == receiveViewModel.SINumber && p.HubID == user.DefaultHub.HubID // && p.IsClosed == false); //TODO we can load all the sub-commodites here //var rAllocation = repository.ReceiptAllocation.FindBySINumber(receiveViewModel.SINumber).FirstOrDefault( // p => p.CommoditySourceID == receiveViewModel.CommoditySourceID && p.HubID == user.DefaultHub.HubID && p.IsClosed == false); var rAllocation = _receiptAllocationService.FindById(receiptAllocationID); if (rAllocation != null) { //Only for loading Waybill no var gCertificate = _giftCertificateService.FindBySINumber(rAllocation.SINumber); if (gCertificate != null) { var giftCertificateDetail = gCertificate.GiftCertificateDetails.FirstOrDefault(); if (giftCertificateDetail != null) { receiveViewModel.WayBillNo = giftCertificateDetail.BillOfLoading; } receiveViewModel.PortName = gCertificate.PortName; receiveViewModel.VesselName = gCertificate.Vessel; } if (rAllocation.HubID == user.DefaultHub.HubID) { //if the allocation is for the current hub allocation receiveViewModel.ReceiptAllocationID = rAllocation.ReceiptAllocationID; receiveViewModel.SINumber = rAllocation.SINumber; receiveViewModel.ProjectNumber = rAllocation.ProjectNumber; receiveViewModel.ProgramID = rAllocation.ProgramID; receiveViewModel.CommodityTypeID = rAllocation.Commodity.CommodityTypeID; receiveViewModel.ResponsibleDonorID = rAllocation.DonorID; //receiveViewModel.CommoditySourceID = rAllocation.DonorID; receiveViewModel.SupplierName = rAllocation.SupplierName; receiveViewModel.SourceHubID = rAllocation.SourceHubID; receiveViewModel.PurchaseOrder = rAllocation.PurchaseOrder; if (rAllocation.Commodity.ParentID != null) { //TODO if we were to load multiple commoditites don't forget to derecement the allocation id in the neative direction receiveCommodities.Add(new ReceiveDetailViewModel() {ReceiveDetailID = null, ReceiveDetailCounter = -1, CommodityID = rAllocation.CommodityID}); receiveViewModel.JSONPrev = JsonConvert.SerializeObject(receiveCommodities); } } else { ViewBag.Message = string.Format( "The selected Receipt Allocation {0} doesn't exist in your default warehouse. Try changing your default warehouse.", rAllocation.ReceiptAllocationID); } } } return View("Create", receiveViewModel); }