Exemple #1
0
        public ActionResult Create(string 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();
            return(View(viewModel));
        }
Exemple #2
0
        public ReceiveNewViewModel ModeltoNewView(Receive receive) //string receiveId, string grn)
        {
            var receiptAllocation = _receiptAllocationService.FindById(receive.ReceiptAllocationID.GetValueOrDefault());

            var user = _userProfileService.GetUser(User.Identity.Name);

            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(receive.ReceiptAllocationID.GetValueOrDefault());
            //var commodities = _commodityService.GetAllCommodityViewModelsByParent(receiptAllocation.CommodityID);
            //ViewData["commodities"] = commodities;
            //ViewData["units"] = _unitService.GetAllUnitViewModels();


            viewModel.Grn                 = receive.GRN;
            viewModel.ReceiptDate         = receive.ReceiptDate;
            viewModel.SiNumber            = receiptAllocation.SINumber;
            viewModel.ReceiptDate         = viewModel.ReceiptDate;
            viewModel.ReceiptAllocationId = receive.ReceiptAllocationID.GetValueOrDefault();
            viewModel.ReceiveId           = receive.ReceiveID;

            //viewModel.StackNumber
            viewModel.WayBillNo   = receive.WayBillNo;
            viewModel.SiNumber    = receiptAllocation.SINumber;
            viewModel.ProjectCode = receiptAllocation.ProjectNumber;
            //viewModel.Program = .FindById(receiptAllocation.ProgramID).Name;
            viewModel.ProgramId = receiptAllocation.ProgramID;
            //viewModel.CommodityType = _CommodityTypeRepository.FindById(receiptAllocation.Commodity.CommodityTypeID).Name,
            viewModel.CommodityTypeId       = receiptAllocation.Commodity.CommodityTypeID;
            viewModel.CommoditySourceTypeId = receiptAllocation.CommoditySourceID;


            if (CommoditySource.Constants.LOAN == receiptAllocation.CommoditySourceID ||
                CommoditySource.Constants.SWAP == receiptAllocation.CommoditySourceID ||
                CommoditySource.Constants.TRANSFER == receiptAllocation.CommoditySourceID ||
                CommoditySource.Constants.REPAYMENT == receiptAllocation.CommoditySourceID)
            {
                if (receiptAllocation.SourceHubID.HasValue)
                {
                    viewModel.SourceHub = _hub.FindById(receiptAllocation.SourceHubID.GetValueOrDefault(0)).Name;
                }
            }

            if (CommoditySource.Constants.LOCALPURCHASE == receiptAllocation.CommoditySourceID)
            {
                viewModel.SupplierName  = receiptAllocation.SupplierName;
                viewModel.PurchaseOrder = receiptAllocation.PurchaseOrder;
            }

            viewModel.CommoditySource       = receiptAllocation.CommoditySource.Name;
            viewModel.CommoditySourceTypeId = receiptAllocation.CommoditySourceID;
            viewModel.ReceivedByStoreMan    = receive.ReceivedByStoreMan;
            ReceiveDetail receivedetail = receive.ReceiveDetails.FirstOrDefault();

            viewModel.StoreId     = receive.StoreId.GetValueOrDefault();
            viewModel.StackNumber = receive.StackNumber.GetValueOrDefault();
            viewModel.ReceiveDetailNewViewModel = new ReceiveDetailNewViewModel
            {
                CommodityId          = receivedetail.CommodityID,
                CommodityChildID     = receivedetail.CommodityChildID,
                ReceivedQuantityInMt =
                    receivedetail.QuantityInMT,
                ReceivedQuantityInUnit =
                    receivedetail.QuantityInUnit,
                SentQuantityInMt   = receivedetail.SentQuantityInMT,
                SentQuantityInUnit = receivedetail.SentQuantityInUnit,
                UnitId             = receivedetail.UnitID,
                Description        = receivedetail.Description,
                ReceiveId          = receivedetail.ReceiveID,
                ReceiveDetailId    = receivedetail.ReceiveDetailID,
            };

            viewModel.WeightBridgeTicketNumber = receive.WeightBridgeTicketNumber;
            viewModel.WeightBeforeUnloading    = receive.WeightBeforeUnloading;
            viewModel.WeightAfterUnloading     = receive.WeightAfterUnloading;
            viewModel.TransporterId            = receive.TransporterID;
            viewModel.DriverName     = receive.DriverName;
            viewModel.PlateNoPrime   = receive.PlateNo_Prime;
            viewModel.PlateNoTrailer = receive.PlateNo_Trailer;
            viewModel.PortName       = receive.PortName;
            viewModel.Remark         = receive.Remark;

            return(viewModel);
        }
        public ActionResult Edit(String allocationId)
        {
            var receiptAllocation = _receiptAllocationService.FindById(Guid.Parse(allocationId));

            BLL.UserProfile user = _userProfileService.GetUser(User.Identity.Name);
            var             receiptAllocationViewModel = BindReceiptAllocaitonViewModel();

            if (receiptAllocation != null) // && receiptAllocation.IsCommited == false)
            {
                receiptAllocationViewModel.IsCommited          = receiptAllocation.IsCommited;
                receiptAllocationViewModel.ReceiptAllocationID = receiptAllocation.ReceiptAllocationID;
                receiptAllocationViewModel.PartitionID         = receiptAllocation.PartitionID;
                receiptAllocationViewModel.ProjectNumber       = receiptAllocation.ProjectNumber;
                receiptAllocationViewModel.CommodityID         = receiptAllocation.CommodityID;
                //LOAD THE respective type and
                //TODO remove the other Types
                receiptAllocationViewModel.CommodityTypeID = receiptAllocation.Commodity.CommodityTypeID;

                receiptAllocationViewModel.SINumber     = receiptAllocation.SINumber;
                receiptAllocationViewModel.QuantityInMT = receiptAllocation.QuantityInMT;
                if (receiptAllocation.QuantityInUnit == null)
                {
                    receiptAllocationViewModel.QuantityInUnit = 0;
                }
                else
                {
                    receiptAllocationViewModel.QuantityInUnit = receiptAllocation.QuantityInUnit.Value;
                }
                receiptAllocationViewModel.HubID   = receiptAllocation.HubID;
                receiptAllocationViewModel.ETA     = receiptAllocation.ETA;
                receiptAllocationViewModel.DonorID = receiptAllocation.DonorID;
                receiptAllocationViewModel.GiftCertificateDetailID = receiptAllocation.GiftCertificateDetailID;
                receiptAllocationViewModel.ReceiptAllocationID     = receiptAllocation.ReceiptAllocationID;
                receiptAllocationViewModel.ProgramID             = receiptAllocation.ProgramID;
                receiptAllocationViewModel.CommoditySourceID     = receiptAllocation.CommoditySourceID;
                receiptAllocationViewModel.SourceHubID           = receiptAllocation.SourceHubID;
                receiptAllocationViewModel.PurchaseOrder         = receiptAllocation.PurchaseOrder;
                receiptAllocationViewModel.SupplierName          = receiptAllocation.SupplierName;
                receiptAllocationViewModel.OtherDocumentationRef = receiptAllocation.OtherDocumentationRef;
                receiptAllocationViewModel.Remark = receiptAllocation.Remark;


                GiftCertificate GC = _giftCertificateService.FindBySINumber(receiptAllocationViewModel.SINumber);
                if (GC != null && receiptAllocation.CommoditySourceID == BLL.CommoditySource.Constants.DONATION)
                {
                    receiptAllocationViewModel.Commodities.Clear();
                    receiptAllocationViewModel.Donors.Clear();
                    receiptAllocationViewModel.Programs.Clear();
                    foreach (GiftCertificateDetail giftCertificateDetail in GC.GiftCertificateDetails)
                    {
                        receiptAllocationViewModel.Commodities.Add(giftCertificateDetail.Commodity);
                    }
                    //Commodity commodity = receiptAllocationViewModel.Commodities.FirstOrDefault();
                    //if (commodity != null) receiptAllocationViewModel.CommodityID = commodity.CommodityID;
                    receiptAllocationViewModel.Donors.Add(GC.Donor);
                    receiptAllocationViewModel.DonorID = GC.DonorID;
                    receiptAllocationViewModel.Programs.Add(GC.Program);
                    receiptAllocationViewModel.ProgramID = GC.ProgramID;
                    receiptAllocationViewModel.CommoditySources.Clear();
                    receiptAllocationViewModel.CommoditySources.Add(
                        _commoditySourceService.FindById(BLL.CommoditySource.Constants.DONATION));
                    receiptAllocationViewModel.CommoditySourceID = BLL.CommoditySource.Constants.DONATION;
                }
                //else
                //{
                int sourceType = receiptAllocation.CommoditySourceID;

                if (BLL.CommoditySource.Constants.DONATION == sourceType)

                {
                    receiptAllocationViewModel.CommoditySources.Clear();
                    receiptAllocationViewModel.CommoditySources.Add(
                        _commoditySourceService.FindById(BLL.CommoditySource.Constants.DONATION));
                }
                //else if (BLL.CommoditySource.Constants.TRANSFER == sourceType)
                //{
                //    receiptAllocationViewModel.CommoditySources.Clear();
                //    receiptAllocationViewModel.CommoditySources.Add(
                //        _commoditySourceService.FindById(BLL.CommoditySource.Constants.TRANSFER));
                //}
                else if (BLL.CommoditySource.Constants.LOCALPURCHASE == sourceType)
                {
                    receiptAllocationViewModel.CommoditySources.Clear();
                    receiptAllocationViewModel.CommoditySources.Add(
                        _commoditySourceService.FindById(BLL.CommoditySource.Constants.LOCALPURCHASE));
                }
                else if (BLL.CommoditySource.Constants.TRANSFER == sourceType ||
                         BLL.CommoditySource.Constants.REPAYMENT == sourceType ||
                         BLL.CommoditySource.Constants.LOAN == sourceType ||
                         BLL.CommoditySource.Constants.SWAP == sourceType)
                {
                    receiptAllocationViewModel.CommoditySources.Clear();
                    receiptAllocationViewModel.CommoditySources.Add(
                        _commoditySourceService.FindById(BLL.CommoditySource.Constants.REPAYMENT));
                    receiptAllocationViewModel.CommoditySources.Add(
                        _commoditySourceService.FindById(BLL.CommoditySource.Constants.LOAN));
                    receiptAllocationViewModel.CommoditySources.Add(
                        _commoditySourceService.FindById(BLL.CommoditySource.Constants.SWAP));
                    receiptAllocationViewModel.CommoditySources.Add(
                        _commoditySourceService.FindById(BLL.CommoditySource.Constants.TRANSFER));
                }
                // }
            }
            ViewBag.CommoditySourceType = receiptAllocation != null
                                              ? receiptAllocation.CommoditySourceID
                                              : BLL.CommoditySource.Constants.DONATION;

            if (receiptAllocation != null && receiptAllocation.Receives.Any())
            {
                ViewBag.receiveUnderAllocation = true;
            }

            return(PartialView("Edit", receiptAllocationViewModel));
        }