public static TransportRequisitionViewModel BindTransportRequisitionViewModel(TransportRequisition transportRequisition,List<WorkflowStatus> statuses,string datePrefrence,List<UserInfo> users  )
 {
     TransportRequisitionViewModel transportRequisitionViewModel = null;
     if (transportRequisition != null)
     {
         transportRequisitionViewModel = new TransportRequisitionViewModel();
         transportRequisitionViewModel.CertifiedBy =users.First(t=>t.UserProfileID==transportRequisition.CertifiedBy).FullName;
         transportRequisitionViewModel.CertifiedDate = transportRequisition.CertifiedDate;
         transportRequisitionViewModel.DateCertified = transportRequisition.CertifiedDate.ToCTSPreferedDateFormat(datePrefrence);
         //EthiopianDate.GregorianToEthiopian(transportRequisition.CertifiedDate);
         transportRequisitionViewModel.Remark = transportRequisition.Remark;
         transportRequisitionViewModel.RequestedBy = users.First(t => t.UserProfileID == transportRequisition.RequestedBy).FullName;
         transportRequisitionViewModel.RequestedDate = transportRequisition.RequestedDate;
         transportRequisitionViewModel.DateRequested = transportRequisition.RequestedDate.ToCTSPreferedDateFormat(datePrefrence);
         //EthiopianDate.GregorianToEthiopian( transportRequisition.RequestedDate);
         transportRequisitionViewModel.Status = statuses.First(t=>t.StatusID==transportRequisition.Status).Description;
         transportRequisitionViewModel.StatusID = transportRequisition.Status;
         transportRequisitionViewModel.TransportRequisitionID = transportRequisition.TransportRequisitionID;
         transportRequisitionViewModel.TransportRequisitionNo = transportRequisition.TransportRequisitionNo;
         transportRequisitionViewModel.Program = transportRequisition.Program.Name;
         transportRequisitionViewModel.Month =
             RequestHelper.MonthName(
                 transportRequisition.TransportRequisitionDetails.FirstOrDefault().ReliefRequisition.Month);
         transportRequisitionViewModel.Round =transportRequisition.TransportRequisitionDetails.FirstOrDefault().ReliefRequisition.Round;
         transportRequisitionViewModel.Date = DateTime.Now.ToCTSPreferedDateFormat(datePrefrence);
     }
     return transportRequisitionViewModel;
 }
        private TransportRequisitionViewModel BindTransportRequisitionViewModel(TransportRequisition transportRequisition)
        {
            string userPreference = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).DatePreference;

            TransportRequisitionViewModel transportRequisitionViewModel = null;
            if (transportRequisition != null)
            {
                var transportRequisitionObj =
                    _transportRequisitionService.FindById(transportRequisition.TransportRequisitionID);
                transportRequisitionViewModel = new TransportRequisitionViewModel();
                transportRequisitionViewModel.CertifiedBy = _userAccountService.FindById(transportRequisitionObj.CertifiedBy).FullName;
                transportRequisitionViewModel.CertifiedDate = transportRequisitionObj.CertifiedDate;
                transportRequisitionViewModel.DateCertified = transportRequisitionObj.CertifiedDate.ToCTSPreferedDateFormat(userPreference);
                //EthiopianDate.GregorianToEthiopian(transportRequisition.CertifiedDate);
                transportRequisitionViewModel.Remark = transportRequisitionObj.Remark;
                transportRequisitionViewModel.RequestedBy = _userAccountService.FindById(transportRequisitionObj.RequestedBy).FullName;
                transportRequisitionViewModel.RequestedDate = transportRequisitionObj.RequestedDate;
                transportRequisitionViewModel.DateRequested = transportRequisitionObj.RequestedDate.ToCTSPreferedDateFormat(userPreference);
                //EthiopianDate.GregorianToEthiopian( transportRequisition.RequestedDate);
                transportRequisitionViewModel.Status = _workflowStatusService.GetStatusName(WORKFLOW.TRANSPORT_REQUISITION, transportRequisitionObj.Status);
                transportRequisitionViewModel.StatusID = transportRequisitionObj.Status;
                transportRequisitionViewModel.TransportRequisitionID = transportRequisitionObj.TransportRequisitionID;
                transportRequisitionViewModel.TransportRequisitionNo = transportRequisitionObj.TransportRequisitionNo;
                transportRequisitionViewModel.Region = _adminUnitService.FindById(transportRequisitionObj.RegionID).Name;
                transportRequisitionViewModel.Program = _programService.FindById(transportRequisitionObj.ProgramID).Name;

            }
            return transportRequisitionViewModel;
        }
        private TransportRequisition BindTransportRequisition(TransportRequisitionViewModel transportRequisitionViewModel)
        {
            string userPreference = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).DatePreference;

            TransportRequisition transportRequisition = null;
            if (transportRequisitionViewModel != null)
            {
                transportRequisition = new TransportRequisition();
                var firstOrDefault = _userAccountService.FindBy(t => t.UserName == transportRequisitionViewModel.CertifiedBy).FirstOrDefault();
                if (firstOrDefault != null)
                    transportRequisition.CertifiedBy = firstOrDefault.UserProfileID;
                transportRequisition.CertifiedDate = transportRequisitionViewModel.CertifiedDate;
                transportRequisition.CertifiedDate = transportRequisitionViewModel.CertifiedDate;
                //EthiopianDate.GregorianToEthiopian(transportRequisition.CertifiedDate);
                transportRequisition.Remark = transportRequisition.Remark;

                var firstOrDefault1 = _userAccountService.FindBy(t => t.UserName == transportRequisitionViewModel.RequestedBy).FirstOrDefault();
                if (firstOrDefault1 != null)
                    transportRequisition.RequestedBy = firstOrDefault1.UserProfileID;

                transportRequisition.RequestedDate = transportRequisitionViewModel.RequestedDate;
                transportRequisition.RequestedDate = transportRequisitionViewModel.RequestedDate;
                //EthiopianDate.GregorianToEthiopian( transportRequisition.RequestedDate);
                transportRequisition.Status = transportRequisitionViewModel.StatusID;
                transportRequisition.TransportRequisitionID = transportRequisitionViewModel.TransportRequisitionID;
                transportRequisition.TransportRequisitionNo = transportRequisitionViewModel.TransportRequisitionNo;
                transportRequisition.RegionID = transportRequisitionViewModel.RegionID;
                transportRequisition.AdminUnit = _adminUnitService.FindById(transportRequisitionViewModel.RegionID);
                transportRequisition.ProgramID = transportRequisitionViewModel.ProgramID;
                transportRequisition.Program = _programService.FindById(transportRequisitionViewModel.ProgramID);

            }
            return transportRequisition;
        }
        public ActionResult PrintSummary(int id)
        {
            var reportPath = Server.MapPath("~/Report/Logisitcs/TransportRequisitionSummary.rdlc");
            var transportR = _transportRequisitionService.FindBy(t=>t.TransportRequisitionID==id);

            var transportRequisitonViewModel = new TransportRequisitionViewModel();
            var headerInfo = new List<TransportRequisitionViewModel>();
            headerInfo.Add(transportRequisitonViewModel);

            var datePref = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).DatePreference;
            var statuses = _workflowStatusService.GetStatus(WORKFLOW.TRANSPORT_REQUISITION);
            var users = _userAccountService.GetUsers();
            var transportRequisition = _transportRequisitionService.FindById(id);

            transportRequisitonViewModel = TransportRequisitionViewModelBinder.
                                            BindTransportRequisitionViewModel(
                                            transportRequisition,
                                            statuses,
                                            datePref,
                                            users
                                            );

            //transportRequisitonViewModel.TransportRequisitionDetailViewModels = GetDetail(transportRequisition.TransportRequisitionDetails.ToList());
            //var transportRequisition = _transportRequisitionService.FindById(id);

            var details = GetDetail(transportRequisition.TransportRequisitionDetails.ToList());
            var header = (from requisition in headerInfo
                         select new
                            {
                                //TransportRequisitionID=requisition.TransportRequisitionNo,
                                //requisition.Remark,
                                //DateRequested=requisition.RequestedDate,
                                //DateRecieved = requisition.CertifiedDate,
                                //requisition.RequestedBy,
                                //requisition.CertifiedBy
                                requisition.TransportRequisitionNo,
                                requisition.Remark,
                                DateRequested=requisition.RequestedDate,
                                DateRecieved = requisition.CertifiedDate,
                                RequestedBy = requisition.RequestedBy,
                                CertifiedBy = requisition.CertifiedBy
                            });

            var requisitionsSummary =
                (from transportRequisitionDetail in details
                 select new
                     {
                         Commodity = transportRequisitionDetail.CommodityName,
                         RequisitionNumber = transportRequisitionDetail.RequisitionNo,
                         Amount = transportRequisitionDetail.QuanityInQtl,
                         Warehouse = transportRequisitionDetail.OrignWarehouse,
                         Region = transportRequisitionDetail.Region,
                         Zone = transportRequisitionDetail.Zone,
                         Donor = "WFP",
                         transportRequisitionDetail.RequisitionID,
                         fromSIPC = (from projectCodeAllocation in _projectCodeAllocationService.FindBy(p => p.HubAllocationID == 3/*_hubAllocationService.GetAllocatedHubId(transportRequisitionDetail.RequisitionID)*/)
                                     select new
                                         {
                                             CommodityName = transportRequisitionDetail.CommodityName,
                                             fromSIPC = projectCodeAllocation.Amount_FromSI,
                                             //fromSIPCKEy = projectCodeAllocation.ProjectCodeAllocationID
                                         }
                                     )
                     }
                );

            var detailsT =
                        (
                            from requisition in requisitionsSummary
                            select requisition.fromSIPC
                        );

               //foreach (var detail in details)
               //{
               //    var hubAllocationID = _hubAllocationService.GetAllocatedHubId(detail.RequisitionID);
               //    var projectCodeAllocations = _projectCodeAllocationService.FindBy(p=>p.HubAllocationID==hubAllocationID);
               //    var ds = from projectCodeAllocation in projectCodeAllocations
               //             select new
               //             {
               //                 CommodityName = detail.CommodityName,
               //                 fromSIPC = projectCodeAllocation.Amount_FromSI,
               //                 fromSIPCKEy = projectCodeAllocation.ProjectCodeAllocationID
               //             }
               //}
             /*
              var detail =
               (from projectCodeAllocation in _projectCodeAllocationService.FindBy(
                        p =>
                        p.HubAllocationID ==
                        _hubAllocationService.GetAllocatedHubId(transportRequisitionDetail.RequisitionID))
                select new
                    {
                        CommodityName = transportRequisitionDetail.CommodityName,
                        fromSIPC = projectCodeAllocation.Amount_FromSI,
                        fromSIPCKEy = projectCodeAllocation.ProjectCodeAllocationID
                    }
               );

               //var data = (from requisition in transportRequisition
               //            select new
               //                {
               //                    requisition.TransportRequisitionID,
               //                    requisition.Remark,
               //                    requisition.RequestedDate,
               //                    requisition.CertifiedDate,
               //                    requisition.RequestedBy,
               //                    requisition.CertifiedBy,
               //                    requisitionsSummary = (from transportRequisitionDetail in GetDetail(requisition.TransportRequisitionDetails.ToList())
               //                                           select new
               //                                               {
               //                                                   Commodity = transportRequisitionDetail.CommodityName,
               //                                                   RequisitionNumber = transportRequisitionDetail.RequisitionNo,
               //                                                   Amount = transportRequisitionDetail.QuanityInQtl,
               //                                                   Warehouse = transportRequisitionDetail.OrignWarehouse,
               //                                                   Region = transportRequisitionDetail.Region,
               //                                                   Zone = transportRequisitionDetail.Zone,
               //                                                   Donor = "WFP",
               //                                                   RecievedDate = DateTime.Now,
               //                                                   DateofRequisition = DateTime.Now,
               //                                                   fromSIPC = (from projectCodeAllocation in _projectCodeAllocationService.FindBy(p => p.HubAllocationID == _hubAllocationService.GetAllocatedHubId(transportRequisitionDetail.RequisitionID))
               //                                                               select new
               //                                                                   {
               //                                                                       CommodityName = transportRequisitionDetail.CommodityName,
               //                                                                       fromSIPC = projectCodeAllocation.Amount_FromSI,
               //                                                                       fromSIPCKEy = projectCodeAllocation.ProjectCodeAllocationID
               //                                                                   }
               //                                                              )
               //                                               }
               //                                          )

               //                }
               //           );

               var reportData = (from detail in details
                             select new
                             {
                                 Commodity = detail.CommodityName,
                                 RequisitionNumber = detail.RequisitionNo,
                                 Amount = detail.QuanityInQtl,
                                 Warehouse = detail.OrignWarehouse,
                                 Region = detail.Region,
                                 Zone= detail.Zone,
                                 Donor = "WFP",
                                 RecievedDate= DateTime.Now,
                                 DateofRequisition = DateTime.Now,
                                 Remark = transportRequisition.Remark,
                                 RequestedBy = transportRequisition.RequestedBy,
                                 CertifiedBy = transportRequisition.CertifiedBy,
                                 //fromSIPCAllocations = detail.
                             });*/

            //var dataSourceName = "RequisitionsSummary";
            //var dataSourceName2 = "Header";
            //var dataSourceName3 = "details";

            var dataSources = new string[3];
            // dataSources[0] = "";
            dataSources[0] = "Header";
            dataSources[1] = "RequisitionsSummary";
            dataSources[2] = "details";

            var reportData = new IEnumerable[3];
            reportData[0] = header;
            reportData[1] = requisitionsSummary;
            reportData[2] = detailsT;

            var result = ReportHelper.PrintReport(reportPath, reportData, dataSources);
            return File(result.RenderBytes, result.MimeType);
        }
 public ActionResult Edit(TransportRequisitionViewModel transportRequisitionViewModel)
 {
     if (!ModelState.IsValid)
     {
         return View(transportRequisitionViewModel);
     }
     //var transportRequisition = BindTransportRequisition(transportRequisitionViewModel);
     var transportRequisition = _transportRequisitionService.FindById(transportRequisitionViewModel.TransportRequisitionID);
     transportRequisition.CertifiedBy = int.Parse(transportRequisitionViewModel.CertifiedBy);
     transportRequisition.CertifiedDate = transportRequisitionViewModel.CertifiedDate;
     transportRequisition.RequestedBy = int.Parse(transportRequisitionViewModel.RequestedBy);
     transportRequisition.RequestedDate = transportRequisitionViewModel.RequestedDate;
     transportRequisition.TransportRequisitionNo = transportRequisitionViewModel.TransportRequisitionNo;
     transportRequisition.Remark = transportRequisitionViewModel.Remark;
     _transportRequisitionService.EditTransportRequisition(transportRequisition);
     return RedirectToAction("Index","TransportRequisition");
 }
        public ActionResult Details(int id)
        {
            ViewBag.RequisistionId = id;

            var transportRequisitonViewModel = new TransportRequisitionViewModel();
            try
            {

            var datePref = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).DatePreference;
            var statuses = _workflowStatusService.GetStatus(WORKFLOW.TRANSPORT_REQUISITION);
            var users = _userAccountService.GetUsers();

            var transportRequisition = _transportRequisitionService.FindById(id);
            transportRequisitonViewModel = TransportRequisitionViewModelBinder.BindTransportRequisitionViewModel(transportRequisition, statuses, datePref, users);
            transportRequisitonViewModel.TransportRequisitionDetailViewModels =
            GetDetail(transportRequisition.TransportRequisitionDetails.ToList());

            foreach (var transportRequisitionDetailViewModel in transportRequisitonViewModel.TransportRequisitionDetailViewModels)
            {
                var count =
                    _reliefRequisitionDetailService.FindBy(
                        t => t.RequisitionID == transportRequisitionDetailViewModel.RequisitionID).Count;
                transportRequisitionDetailViewModel.DestinationsCount = count;
            }
            }

            catch(Exception ex)
            {
                var log = new Logger();
                log.LogAllErrorsMesseges(ex, _log);
                transportRequisitonViewModel.TransportRequisitionDetailViewModels = new List<TransportRequisitionDetailViewModel>();

                ViewBag.Error = "An error has occured: Check Detail.";
                ModelState.AddModelError("Errors", ViewBag.Error);
            }
               // Session["transport_requisiton_return_id"]=id;
            return View(transportRequisitonViewModel);
        }