Пример #1
0
 public static TransportOrderViewModel BindTransportOrderViewModel(TransportOrder transportOrder, string datePref,List<WorkflowStatus> statuses )
 {
     TransportOrderViewModel transportOrderViewModel = null;
     if (transportOrder != null)
     {
         transportOrderViewModel = new TransportOrderViewModel();
         transportOrderViewModel.BidDocumentNo = transportOrder.BidDocumentNo;
         transportOrderViewModel.OrderDate = transportOrder.OrderDate;
         transportOrderViewModel.OrderDateET =
            transportOrder.OrderDate.ToCTSPreferedDateFormat(datePref);
         transportOrderViewModel.ContractNumber = transportOrder.ContractNumber;
         transportOrderViewModel.PerformanceBondReceiptNo = transportOrder.PerformanceBondReceiptNo;
         transportOrderViewModel.OrderExpiryDate = transportOrder.OrderExpiryDate;
         transportOrderViewModel.OrderExpiryDateET = transportOrder.OrderExpiryDate.ToCTSPreferedDateFormat(datePref);
         transportOrderViewModel.Transporter = transportOrder.Transporter.Name;
         transportOrderViewModel.RequestedDispatchDate = transportOrder.RequestedDispatchDate;
         transportOrderViewModel.RequestedDispatchDateET = transportOrder.RequestedDispatchDate.ToCTSPreferedDateFormat(datePref);
         transportOrderViewModel.TransporterID = transportOrder.TransporterID;
         transportOrderViewModel.TransportOrderNo = transportOrder.TransportOrderNo;
         transportOrderViewModel.TransportOrderID = transportOrder.TransportOrderID;
         transportOrderViewModel.StatusID = transportOrder.StatusID;
         transportOrderViewModel.StartDate = transportOrder.OrderExpiryDate.ToCTSPreferedDateFormat(datePref);
         transportOrderViewModel.EndDate = transportOrder.OrderExpiryDate.ToCTSPreferedDateFormat(datePref);
         transportOrderViewModel.Status =transportOrder.StatusID.HasValue?
         statuses.Find(t => t.StatusID == transportOrder.StatusID.Value).Description:string.Empty;
     }
     return transportOrderViewModel;
 }
Пример #2
0
        public bool ApproveTransportOrder(TransportOrder transportOrder)
        {
            if (transportOrder != null)
            {
                try
                {
                    var hubId = new List<int>();
                    var transport = transportOrder.TransportOrderDetails.Select(c => c.SourceWarehouseID).ToList().Distinct();
                    {
                        hubId.AddRange(transport);
                    }
                    AddToNotification(transportOrder.TransportOrderID, transportOrder.TransportOrderNo,hubId);
                }
                catch
                {

                }

                transportOrder.StatusID = (int)TransportOrderStatus.Approved;
                _unitOfWork.TransportOrderRepository.Edit(transportOrder);
                _unitOfWork.Save();

                return true;
            }
            return false;
        }
Пример #3
0
        public int DaysToStart(TransportOrder transportOrder)
        {
            var days = -1;

            if ((int)(transportOrder.StartDate - DateTime.Now).TotalDays < 0)
            {
                days = (int)(DateTime.Now - transportOrder.StartDate).TotalDays;
            }
            return days;
        }
Пример #4
0
        public int DaysLeft( TransportOrder transportOrder)
        {
            var days = -1;

            if ((int)(transportOrder.StartDate - DateTime.Now).TotalDays>0)
            {
                days = (int) (transportOrder.EndDate - DateTime.Now).TotalDays;
            }
            return days;
        }
Пример #5
0
        public bool ApproveTransportOrder(TransportOrder transportOrder)
        {
            if (transportOrder != null)
            {
                try
                {
                    AddToNotification(transportOrder.TransportOrderID, transportOrder.TransportOrderNo);
                }
                catch
                {

                }

                transportOrder.StatusID = (int)TransportOrderStatus.Approved;
                _unitOfWork.TransportOrderRepository.Edit(transportOrder);
                _unitOfWork.Save();

                return true;
            }
            return false;
        }
Пример #6
0
 public bool AddTransportOrder(TransportOrder transportOrder)
 {
     _unitOfWork.TransportOrderRepository.Add(transportOrder);
     _unitOfWork.Save();
     return true;
 }
Пример #7
0
        public bool ReAssignTransporter(IEnumerable<TransportRequisitionWithoutWinnerModel> transReqWithTransporter, int transporterID)
        {
            if (transReqWithTransporter != null && transporterID != 0)
            {

                var transportOrder = new TransportOrder();
                transportOrder.TransporterID = transporterID;
                transportOrder.OrderDate = DateTime.Today;
                transportOrder.StartDate = DateTime.Today;
                transportOrder.EndDate = DateTime.Today;
                transportOrder.TransportOrderNo = Guid.NewGuid().ToString();
                transportOrder.OrderExpiryDate = DateTime.Today.AddDays(10);
                var currentBid = _unitOfWork.ApplicationSettingRepository.FindBy(t => t.SettingName == "CurrentBid");
                var transporterName = _unitOfWork.TransporterRepository.FindById(transportOrder.TransporterID).Name;
                if (currentBid != null)
                {
                    var bidID = int.Parse(currentBid[0].SettingValue);
                    transportOrder.BidDocumentNo = _unitOfWork.BidRepository.FindById(bidID).BidNumber;
                }
                else
                {
                    transportOrder.BidDocumentNo = "Bid-Number";

                }
                transportOrder.PerformanceBondReceiptNo = "PERFORMANCE-BOND-NO";
                //var transporterName = _unitOfWork.TransporterRepository.FindById(transporter).Name;
                transportOrder.ContractNumber = Guid.NewGuid().ToString();
                //string.Format("{0}/{1}/{2}/{3}", "LTCD", DateTime.Today.day, DateTime.Today.Year, transporterName.Substring(0, 1));
                transportOrder.TransporterSignedDate = DateTime.Today;
                transportOrder.RequestedDispatchDate = DateTime.Today;
                transportOrder.ConsignerDate = DateTime.Today;
                transportOrder.StatusID = (int)TransportOrderStatus.Draft;
                var lastOrder = _unitOfWork.TransportOrderRepository.GetAll();
                if (lastOrder.Count!=0)
                {
                    transportOrder.TransportOrderNo = string.Format("TRN-ORD-{0}", lastOrder.Last().TransportOrderID + 1);
                }
                else
                {
                    transportOrder.TransportOrderNo = string.Format("TRN-ORD-{0}", 1);
                }
                transportOrder.ContractNumber = string.Format("{0}/{1}/{2}/{3}", "LTCD", DateTime.Today.Day,
                                                              DateTime.Today.Year, transporterName.Substring(0, 3));
                foreach (var detail in transReqWithTransporter)
                {
                    var transportOrderDetail = new TransportOrderDetail();
                    transportOrderDetail.CommodityID = detail.CommodityID;
                    transportOrderDetail.FdpID = detail.FdpID;
                    transportOrderDetail.RequisitionID = detail.RequisitionID;
                    transportOrderDetail.QuantityQtl = detail.QuantityQtl;
                    //since users don't specify tariff value
                    transportOrderDetail.TariffPerQtl = 0;
                    transportOrderDetail.SourceWarehouseID = detail.HubID;
                    transportOrder.TransportOrderDetails.Add(transportOrderDetail);
                }
                bool isSaved = _unitOfWork.TransportOrderRepository.Add(transportOrder);
                _unitOfWork.Save();
                if (isSaved)
                {
                    foreach (var item in transReqWithTransporter)
                    {
                        var withoutTransporter =
                            _unitOfWork.TransReqWithoutTransporterRepository.FindById(item.TransReqWithoutTransporterID);
                        withoutTransporter.IsAssigned = true;
                        _unitOfWork.TransReqWithoutTransporterRepository.Edit(withoutTransporter);
                        _unitOfWork.Save();
                    }

                }

                return true;
            }
            return false;
        }
Пример #8
0
 public bool DeleteTransportOrder(TransportOrder transportOrder)
 {
     if (transportOrder == null) return false;
     _unitOfWork.TransportOrderRepository.Delete(transportOrder);
     _unitOfWork.Save();
     return true;
 }
Пример #9
0
        private IEnumerable<TransportOrderDetailViewModel> GetTransportContract(TransportOrder transportOrder)
        {
            var transportContractDetail = transportOrder.TransportOrderDetails;
            return (from detail in transportContractDetail
                    select new TransportOrderDetailViewModel()
                    {
                        TransportOrderID = detail.TransportOrderID,
                        CommodityID = detail.CommodityID,
                        SourceWarehouseID = detail.SourceWarehouseID,
                        QuantityQtl = detail.QuantityQtl.ToPreferedWeightUnit(),
                        RequisitionID = detail.RequisitionID,
                        TariffPerQtl = detail.TariffPerQtl,
                        Commodity = detail.Commodity.Name,
                        OriginWarehouse = detail.Hub.Name,
                        HubID = detail.Hub.HubID,
                        Woreda = detail.FDP.AdminUnit.Name,
                        FDP = detail.FDP.Name,
                        RequisitionNo = detail.ReliefRequisition.RequisitionNo

                    });

            // return transportContractDetail;
        }
Пример #10
0
        private TransportContractViewModel GetTransportOrder(TransportOrder transportOrder)
        {
            var datePref = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).DatePreference;
            var transportContract = new TransportContractViewModel()
            {
                TransportOrderID = transportOrder.TransportOrderID,
                TransportOrderNo = transportOrder.TransportOrderNo,
                TransporterID = transportOrder.TransporterID,
                RequisitionNo = transportOrder.TransportOrderDetails.First().ReliefRequisition.RequisitionNo,
                Transporter = transportOrder.Transporter.Name,
                BidDocumentNo = transportOrder.BidDocumentNo,
                ConsignerName = transportOrder.ConsignerName,
                ContractNumber = transportOrder.ContractNumber,
                OrderDate = transportOrder.OrderDate.ToCTSPreferedDateFormat(datePref),
                OrderExpiryDate = transportOrder.OrderExpiryDate.ToCTSPreferedDateFormat(datePref),
                RequestedDispatchDate = transportOrder.RequestedDispatchDate.ToCTSPreferedDateFormat(datePref),
                ConsignerDate = transportOrder.ConsignerDate.ToCTSPreferedDateFormat(datePref),
                PerformanceBondReceiptNo = transportOrder.PerformanceBondReceiptNo,
                TransporterSignedDate = transportOrder.TransporterSignedDate.ToCTSPreferedDateFormat(datePref),
                TransporterSignedName = transportOrder.TransporterSignedName,
                StatusID = transportOrder.StatusID,
                Zone = transportOrder.TransportOrderDetails.First().FDP.AdminUnit.AdminUnit2.Name,
                Region = transportOrder.TransportOrderDetails.First().FDP.AdminUnit.AdminUnit2.AdminUnit2.Name

            };
            return transportContract;
        }
Пример #11
0
        private IEnumerable<TransportOrderDetailViewModel> GetTransportContract(TransportOrder transportOrder)
        {
            var datePref = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).DatePreference;
            var hubId = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).DefaultHub.HasValue ? _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).DefaultHub.Value : 0;
            var transportContractDetail = transportOrder.TransportOrderDetails.Where(m=>m.SourceWarehouseID==hubId);
            return (from detail in transportContractDetail
                    select new TransportOrderDetailViewModel()
                    {
                        TransportOrderID = detail.TransportOrderID,
                        CommodityID = detail.CommodityID,
                        SourceWarehouseID = detail.SourceWarehouseID,
                        QuantityQtl = detail.QuantityQtl.ToPreferedWeightUnit(),
                        RequisitionID = detail.RequisitionID,
                        TariffPerQtl = detail.TariffPerQtl,
                        Commodity = detail.Commodity.Name,
                        OriginWarehouse = detail.Hub.Name,
                        HubID = detail.Hub.HubID,
                        Woreda = detail.FDP.AdminUnit.Name,
                        FDP = detail.FDP.Name,
                        RequisitionNo = detail.ReliefRequisition.RequisitionNo

                    });

            // return transportContractDetail;
        }
Пример #12
0
        private TransportContractReportViewModel GetTransportOrderReport(TransportOrder transportOrder)
        {
            var datePref = UserAccountHelper.GetUser(User.Identity.Name).DatePreference;
            var transportOrderReport = new TransportContractReportViewModel()
            {
                TransportOrderID = transportOrder.TransportOrderID,
                TransportOrderNo = transportOrder.TransportOrderNo,
                TransporterID = transportOrder.TransporterID,
                RequisitionNo = transportOrder.TransportOrderDetails.First().ReliefRequisition.RequisitionNo,
                TransporterName = transportOrder.Transporter.Name,
                BidDocumentNo = transportOrder.BidDocumentNo,
                ConsignerName = transportOrder.ConsignerName,
                ContractNumber = transportOrder.ContractNumber,
                OrderDate = transportOrder.OrderDate.ToCTSPreferedDateFormat(datePref),
                OrderExpiryDate = transportOrder.OrderExpiryDate.ToCTSPreferedDateFormat(datePref),
                RequestedDispatchDate = transportOrder.RequestedDispatchDate.ToCTSPreferedDateFormat(datePref),
                ConsignerDate = transportOrder.ConsignerDate.ToCTSPreferedDateFormat(datePref),
                PerformanceBondReceiptNo = transportOrder.PerformanceBondReceiptNo,
                TransporterSignedDate = transportOrder.TransporterSignedDate.ToCTSPreferedDateFormat(datePref),
                TransporterSignedName = transportOrder.TransporterSignedName,
                ZoneName = transportOrder.TransportOrderDetails.First().FDP.AdminUnit.AdminUnit2.Name,
                ZoneID = transportOrder.TransportOrderDetails.First().FDP.AdminUnit.AdminUnit2.AdminUnitID,
                RegionName = transportOrder.TransportOrderDetails.First().FDP.AdminUnit.AdminUnit2.AdminUnit2.Name,
                CommodityID = transportOrder.TransportOrderDetails.First().CommodityID,
                CommodityName = transportOrder.TransportOrderDetails.First().Commodity.Name,
                RequisitionID = transportOrder.TransportOrderDetails.First().FDP.AdminUnit.AdminUnit2.AdminUnit2.AdminUnitID

            };
            return transportOrderReport;
        }
Пример #13
0
 public ActionResult Edit(TransportOrder transportOrder)
 {
     if (ModelState.IsValid)
     {
         var target = _transportOrderService.FindById(transportOrder.TransportOrderID);
         target.TransportOrderNo = transportOrder.TransportOrderNo;
         target.ContractNumber = transportOrder.ContractNumber;
         target.OrderDate = transportOrder.OrderDate;
         target.OrderExpiryDate = transportOrder.OrderExpiryDate;
         target.RequestedDispatchDate = transportOrder.RequestedDispatchDate;
         target.PerformanceBondReceiptNo = transportOrder.PerformanceBondReceiptNo;
         target.PerformanceBondAmount = transportOrder.PerformanceBondAmount;
         target.BidDocumentNo = transportOrder.BidDocumentNo;
         target.TransporterSignedDate = transportOrder.TransporterSignedDate;
         target.TransporterSignedName = transportOrder.TransporterSignedName;
         target.ConsignerDate = transportOrder.ConsignerDate;
         target.ConsignerName = transportOrder.ConsignerName;
         _transportOrderService.EditTransportOrder(target);
         return RedirectToAction("Index", "TransportOrder");
     }
     return View(transportOrder);
 }
Пример #14
0
        public ActionResult ChangeTransporters([DataSourceRequest] DataSourceRequest request, List<SubstituteTransporterOrder> listOfSubTransporterOrders, int changedTransportOrderID)
        {
            var changedTransportOrderObj = _transportOrderService.FindById(changedTransportOrderID);
            var returnedObj = new List<TransportOrder>();
            foreach (var subTransporterOrders in listOfSubTransporterOrders)
            {
                var transporterCount = subTransporterOrders.TransportersStandingList.Count();

                foreach (var transporter in subTransporterOrders.TransportersStandingList)
                {
                    changedTransportOrderObj = _transportOrderService.FindById(changedTransportOrderID);
                    var transporterObj = _transporterService.FindById(transporter.TransporterID);
                    var transportOrder =
                        _transportOrderService.Get(t => t.TransporterID == transporterObj.TransporterID &&
                                                        t.StatusID == (int)TransportOrderStatus.Draft).
                            FirstOrDefault();
                    if (transportOrder != null)
                    {
                        foreach (var transportOrderDetail in changedTransportOrderObj.TransportOrderDetails.ToList())
                        {
                            if (transportOrderDetail.FDP.AdminUnitID == subTransporterOrders.WoredaID)
                            {
                                var transportOrderDetailObj = new TransportOrderDetail
                                {
                                    CommodityID = transportOrderDetail.CommodityID,
                                    FdpID = transportOrderDetail.FdpID,
                                    RequisitionID = transportOrderDetail.RequisitionID,
                                    QuantityQtl = transportOrderDetail.QuantityQtl.ToPreferedWeightUnit() / transporterCount,
                                    TariffPerQtl = transportOrderDetail.TariffPerQtl,
                                    SourceWarehouseID = transportOrderDetail.Hub.HubID,
                                    //transportOrderDetailObj.ZoneID = transportOrderDetail.ReliefRequisition.ZoneID;
                                };
                                transportOrder.TransportOrderDetails.Add(transportOrderDetailObj);
                                _transportOrderService.EditTransportOrder(transportOrder);
                            }
                        }

                        returnedObj.Add(transportOrder);
                    }
                    else
                    {
                        var transportOrderObj = new TransportOrder
                        {
                            TransporterID = transporter.TransporterID,
                            OrderDate = DateTime.Today,
                            TransportOrderNo = Guid.NewGuid().ToString(),
                            OrderExpiryDate = DateTime.Today.AddDays(10),
                            BidDocumentNo = "BID-DOC-No",
                            PerformanceBondReceiptNo = "PERFORMANCE-BOND-NO",
                            ContractNumber = Guid.NewGuid().ToString(),
                            TransporterSignedDate = DateTime.Today,
                            RequestedDispatchDate = DateTime.Today,
                            ConsignerDate = DateTime.Today,
                            StatusID = (int)TransportOrderStatus.Draft,
                            StartDate = DateTime.Today,
                            EndDate = DateTime.Today.AddDays(10),
                        };
                        _transportOrderService.AddTransportOrder(transportOrderObj);
                        var transporterName = _transporterService.FindById(transportOrderObj.TransporterID).Name;
                        transportOrderObj.TransportOrderNo = string.Format("TRN-ORD-{0}", transportOrderObj.TransportOrderID);
                        transportOrderObj.ContractNumber = string.Format("{0}/{1}/{2}/{3}", "LTCD", DateTime.Today.Day, DateTime.Today.Year, transporterName.Substring(0, 2));
                        _transportOrderService.EditTransportOrder(transportOrderObj);
                        //var transportOrderDetailList = subTransporterOrders.TransportOrderDetails;
                        foreach (var transportOrderDetail in changedTransportOrderObj.TransportOrderDetails.ToList())
                        {
                            if (transportOrderDetail.FDP.AdminUnitID == subTransporterOrders.WoredaID)
                            {
                                var transportOrderDetailObj = new TransportOrderDetail
                                    {
                                        TransportOrderID = transportOrderObj.TransportOrderID,
                                        CommodityID = transportOrderDetail.CommodityID,
                                        FdpID = transportOrderDetail.FdpID,
                                        RequisitionID = transportOrderDetail.RequisitionID,
                                        QuantityQtl =
                                            transportOrderDetail.QuantityQtl.ToPreferedWeightUnit() / transporterCount,
                                        TariffPerQtl = transportOrderDetail.TariffPerQtl,
                                        SourceWarehouseID = transportOrderDetail.Hub.HubID
                                    };
                                //transportOrderDetail.ZoneID = reliefRequisitionDetail.ReliefRequisition.ZoneID;
                                _transportOrderDetailService.AddTransportOrderDetail(transportOrderDetailObj);
                            }
                        }

                        returnedObj.Add(transportOrderObj);

                    }
                }
            }
            changedTransportOrderObj.StatusID = (int)TransportOrderStatus.Failed;
            _transportOrderService.EditTransportOrder(changedTransportOrderObj);
            return RedirectToAction("Index", "TransportOrder", returnedObj);
            //return Json(returnedObj.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
Пример #15
0
        public bool SignTransportOrder(TransportOrder transportOrder)
        {
            if (transportOrder != null)
            {
                transportOrder.StatusID = (int)TransportOrderStatus.Signed;
                _unitOfWork.TransportOrderRepository.Edit(transportOrder);
                _unitOfWork.Save();

                return true;
            }
            return false;
        }
Пример #16
0
        private int AddToCurrentTransport(IEnumerable<TransportRequisitionWithoutWinnerModel> transReqWithTransporter, int transporterId)
        {
            try
               {

               var transportOrder =new TransportOrder();

               var transReq = transReqWithTransporter as List<TransportRequisitionWithoutWinnerModel> ?? transReqWithTransporter.ToList();
               foreach (var detail in transReq)
               {
                   var transportReq = _unitOfWork.TransReqWithoutTransporterRepository.FindById(detail.TransReqWithoutTransporterID);
                   //transportOrder =
                   //    _unitOfWork.TransportOrderDetailRepository.FindBy(
                   //        t => t.RequisitionID == transportReq.ReliefRequisitionDetail.RequisitionID && t.TransportOrder.TransporterID == transporterId &&
                   //    t.TransportOrder.StatusID == (int)TransportOrderStatus.Draft).Select(
                   //            t => t.TransportOrder).FirstOrDefault();
                   TransportRequisitionWithoutWinnerModel detail1 = detail;
                   transportOrder =
                     _unitOfWork.TransportOrderDetailRepository.FindBy(t=>t.TransportOrder.TransporterID == transporterId && t.TransportOrder.TransportRequiqsitionId == transportReq.TransportRequisitionDetail.TransportRequisitionID  &&
                     t.TransportOrder.StatusID == (int)TransportOrderStatus.Draft).Select(
                             t => t.TransportOrder).FirstOrDefault();

                   if (transportOrder == null) continue;
                   var transportOrderDetail = new TransportOrderDetail
                                                  {
                                                      CommodityID = detail.CommodityID,
                                                      FdpID = detail.FdpID,
                                                      RequisitionID = detail.RequisitionID,
                                                      QuantityQtl = detail.QuantityQtl,
                                                      TariffPerQtl = 0,
                                                      SourceWarehouseID = detail.HubID,
                                                      WinnerAssignedByLogistics = true
                                                  };
                   transportOrder.TransportOrderDetails.Add(transportOrderDetail);

               }

               bool isSaved = _unitOfWork.TransportOrderRepository.Edit(transportOrder);
               _unitOfWork.Save();
               if (isSaved)
               {

                   foreach (var item in transReq)

                   {
                       var withoutTransporter =
                           _unitOfWork.TransReqWithoutTransporterRepository.FindById(item.TransReqWithoutTransporterID);
                       withoutTransporter.IsAssigned = true;
                       _unitOfWork.TransReqWithoutTransporterRepository.Edit(withoutTransporter);
                       _unitOfWork.Save();
                   }

               }
               if (transportOrder != null) return transportOrder.TransportOrderID;
               return -1;
               }
               catch (Exception)
               {

               return -1;
               }
        }
Пример #17
0
        //TODO:Factor Out  to single responiblity Principle
        public bool CreateTransportOrder(int transportRequisitionId)
        {
            //var requId=_unitOfWork.TransportRequisitionDetailRepository.FindBy(t=>t.TransportRequisitionID==)
            var transporterAssignedRequisionDetails = AssignTransporterForEachWoreda(transportRequisitionId);

            var transporters = (from item in transporterAssignedRequisionDetails select item.TransporterID).Distinct().ToList();

            //If we reached here all location got transporter
            var transportOrders = new List<TransportOrder>();

            foreach (var transporter in transporters)
            {
                //TODO:Check what all number should come from and implement
                var transportOrder = new TransportOrder();
                transportOrder.TransporterID = transporter;
                transportOrder.OrderDate = DateTime.Today;
                transportOrder.StartDate = DateTime.Today;
                transportOrder.EndDate = DateTime.Today;
                transportOrder.TransportOrderNo = Guid.NewGuid().ToString();
                transportOrder.OrderExpiryDate = DateTime.Today.AddDays(10);

                transportOrder.PerformanceBondReceiptNo = "PERFORMANCE-BOND-NO";
                //var transporterName = _unitOfWork.TransporterRepository.FindById(transporter).Name;
                transportOrder.ContractNumber = Guid.NewGuid().ToString();
                //string.Format("{0}/{1}/{2}/{3}", "LTCD", DateTime.Today.day, DateTime.Today.Year, transporterName.Substring(0, 1));
                transportOrder.TransporterSignedDate = DateTime.Today;
                transportOrder.RequestedDispatchDate = DateTime.Today;
                transportOrder.ConsignerDate = DateTime.Today;
                transportOrder.StartDate = DateTime.Today.AddDays(3);
                transportOrder.EndDate = DateTime.Today.AddDays(13);
                transportOrder.StatusID = (int)TransportOrderStatus.Draft;
                var transportLocations = transporterAssignedRequisionDetails.FindAll(t => t.TransporterID == transporter).Distinct();

                foreach (var transporterRequisition in transportLocations)
                {
                    //var currentBid = _unitOfWork.BidRepository.FindBy(t => t.StatusID == int.Parse(BidStatus.Active.ToString())).FirstOrDefault();
                    var transReq = transporterRequisition;
                    //var activeBidStatusID = int.Parse(BidStatus.Active.ToString());
                    var bidWinner =
                    _unitOfWork.BidWinnerRepository.Get(
                        t => t.SourceID == transReq.HubID && t.DestinationID == transReq.WoredaID && t.Position == 1 &&
                            t.Bid.StatusID == 5).FirstOrDefault();
                    if (bidWinner != null)
                    {
                        transportOrder.BidDocumentNo = _unitOfWork.BidRepository.FindById(bidWinner.BidID).BidNumber;
                    }
                    else
                    {
                        transportOrder.BidDocumentNo = "Bid-Number";
                        //_unitOfWork.BidWinnerRepository.FindById(transporter).Bid.BidNumber;
                    }

                    var requisionsDetails =
                        _unitOfWork.ReliefRequisitionDetailRepository.Get(
                            t =>
                            t.RequisitionID == transReq.RequisitionID &&
                            t.FDP.AdminUnitID == transReq.WoredaID, null, "ReliefRequisition").ToList();

                    foreach (var reliefRequisitionDetail in requisionsDetails)
                    {
                        var transportOrderDetail = new TransportOrderDetail();
                        //transportOrderDetail.ZoneID = reliefRequisitionDetail.ReliefRequisition.ZoneID;
                        transportOrderDetail.CommodityID = reliefRequisitionDetail.CommodityID;
                        transportOrderDetail.FdpID = reliefRequisitionDetail.FDPID;
                        transportOrderDetail.RequisitionID = reliefRequisitionDetail.RequisitionID;
                        transportOrderDetail.QuantityQtl = reliefRequisitionDetail.Amount;
                        transportOrderDetail.TariffPerQtl = transReq.TariffPerQtl;
                        transportOrderDetail.SourceWarehouseID = transReq.HubID;
                        transportOrder.TransportOrderDetails.Add(transportOrderDetail);
                    }

                }
                _unitOfWork.TransportOrderRepository.Add(transportOrder);
                transportOrders.Add(transportOrder);

            }

            var requisition = _unitOfWork.TransportRequisitionRepository.Get(t => t.TransportRequisitionID == transportRequisitionId).FirstOrDefault();

            requisition.Status = (int)TransportRequisitionStatus.Closed;

            var transportRequisitionDetails =
                _unitOfWork.TransportRequisitionDetailRepository.Get(t => t.TransportRequisitionID == transportRequisitionId).ToList();
            foreach (var transportRequisitionDetail in transportRequisitionDetails)
            {
                var reliefRequisition =
                    _unitOfWork.ReliefRequisitionRepository.Get(
                        t => t.RequisitionID == transportRequisitionDetail.RequisitionID).FirstOrDefault();
                reliefRequisition.Status = (int)ReliefRequisitionStatus.TransportOrderCreated;
            }

            _unitOfWork.Save();
            //TODO:Identity if Transport order number to be auto generated , and where to get contract number.

            foreach (var transportOrder in transportOrders)
            {
                var transporterName = _unitOfWork.TransporterRepository.FindById(transportOrder.TransporterID).Name;
                transportOrder.TransportOrderNo = string.Format("TRN-ORD-{0}", transportOrder.TransportOrderID);
                transportOrder.ContractNumber = string.Format("{0}/{1}/{2}/{3}", "LTCD", DateTime.Today.Day, DateTime.Today.Year, transporterName.Substring(0, 2));
            }

            _unitOfWork.Save();

            return true;
        }
Пример #18
0
        public ActionResult ChangeTransporters([DataSourceRequest] DataSourceRequest request, List<SubstituteTransporterOrder> listOfSubTransporterOrders, int changedTransportOrderID)
        {
            var orderDetails = new List<TransportOrderDetail>();
            var weightPref = UserAccountHelper.GetUser(User.Identity.Name).PreferedWeightMeasurment;
            var changedTransportOrderObj = _transportOrderService.FindById(changedTransportOrderID);
            var returnedObj = new List<TransportOrder>();
            var tempContratNo = string.Empty;
               foreach (var subTransporterOrders in listOfSubTransporterOrders)
            {
                if (subTransporterOrders.TransportersStandingList.All(t => t.IsChecked == false))
                    continue; // No transporter is checked
                var filteredTransporterList = from transporters in subTransporterOrders.TransportersStandingList
                                               where transporters.IsChecked
                                               select transporters;

                var transportBidQuotationViewModels = filteredTransporterList as List<TransportBidQuotationViewModel> ?? filteredTransporterList.ToList();
                var transporterCount = transportBidQuotationViewModels.Count();

                foreach (var transporter in transportBidQuotationViewModels)
                {
                    changedTransportOrderObj = _transportOrderService.FindById(changedTransportOrderID);
                    var transporterObj = _transporterService.FindById(transporter.TransporterID);
                    //var transportOrder =
                    //    _transportOrderService.Get(t => t.TransporterID == transporterObj.TransporterID &&
                    //                                    t.StatusID == (int)TransportOrderStatus.Draft).
                    //        FirstOrDefault();

                    SubstituteTransporterOrder orders = subTransporterOrders;
                    TransportOrder transportOrderOld = null;

                    var transportOrder = _transportOrderService.FindBy(t=>t.TransporterID == transporterObj.TransporterID && t.StatusID == (int) TransportOrderStatus.Draft).Distinct();
                    var transportOrders = transportOrder as List<TransportOrder> ?? transportOrder.ToList();
                    foreach (var order in transportOrders)
                    {
                        if (tempContratNo!=string.Empty)
                        {
                            if (_transportOrderService.GetTransportRequisitionNo(order.ContractNumber) == _transportOrderService.GetTransportRequisitionNo(tempContratNo))
                          {
                              transportOrderOld = order;
                          }
                        }
                        //else if (_transportOrderService.GetTransportRequisitionNo(order.ContractNumber) == _transportOrderService.GetTransportRequisitionNo(changedTransportOrderObj.ContractNumber))
                        //{
                        //    transportOrderOld = order;
                        //}
                    }
                    if (transportOrderOld != null)
                    {
                        foreach (var transportOrderDetail in changedTransportOrderObj.TransportOrderDetails.ToList())
                        {
                            if (transportOrderDetail.FDP.AdminUnitID == subTransporterOrders.WoredaID)
                            {
                                //var qty = weightPref == "QTL"
                                //                  ? transportOrderDetail.QuantityQtl.ToMetricTone()/transporterCount
                                //                  : transportOrderDetail.QuantityQtl/transporterCount;

                                var transportOrderDetailObj = new TransportOrderDetail
                                {
                                    CommodityID = transportOrderDetail.CommodityID,
                                    FdpID = transportOrderDetail.FdpID,
                                    RequisitionID = transportOrderDetail.RequisitionID,
                                    QuantityQtl = transportOrderDetail.QuantityQtl / transporterCount,
                                    TariffPerQtl = transportOrderDetail.TariffPerQtl,
                                    SourceWarehouseID = transportOrderDetail.Hub.HubID,
                                    BidID = transportOrderDetail.BidID
                                    //transportOrderDetailObj.ZoneID = transportOrderDetail.ReliefRequisition.ZoneID;
                                };
                                _transportOrderService.UpdateTransporterOrder(transportOrderDetail.TransportOrderID,subTransporterOrders.WoredaID);
                                transportOrderOld.TransportOrderDetails.Add(transportOrderDetailObj);
                                _transportOrderService.EditTransportOrder(transportOrderOld);
                                orderDetails.Add(transportOrderDetailObj);
                            }
                        }
                        //_transportOrderService.DeleteTransportOrderDetails(orderDetails); // Delete details from the previous TO
                        returnedObj.Add(transportOrderOld);
                    }
                    else
                    {

                        var transportOrderObj = new TransportOrder
                        {
                            TransporterID = transporter.TransporterID,
                            OrderDate = DateTime.Today,
                            TransportOrderNo = Guid.NewGuid().ToString(),
                            OrderExpiryDate = DateTime.Today.AddDays(10),
                            BidDocumentNo = "BID-DOC-No",
                            PerformanceBondReceiptNo = "PERFORMANCE-BOND-NO",
                            ContractNumber = Guid.NewGuid().ToString(),
                            TransporterSignedDate = DateTime.Today,
                            RequestedDispatchDate = DateTime.Today,
                            ConsignerDate = DateTime.Today,
                            StatusID = (int)TransportOrderStatus.Draft,
                            StartDate = DateTime.Today,
                            EndDate = DateTime.Today.AddDays(10),
                        };
                        _transportOrderService.AddTransportOrder(transportOrderObj);
                        //var transporterName = _transporterService.FindById(transportOrderObj.TransporterID).Name;
                        transportOrderObj.TransportOrderNo = string.Format("TRN-ORD-{0}", transportOrderObj.TransportOrderID);
                        transportOrderObj.ContractNumber = string.Format("{0}/{1}",changedTransportOrderObj.ContractNumber,"N");
                        tempContratNo = transportOrderObj.ContractNumber;
                        _transportOrderService.EditTransportOrder(transportOrderObj);
                        //var transportOrderDetailList = subTransporterOrders.TransportOrderDetails;
                        foreach (var transportOrderDetail in changedTransportOrderObj.TransportOrderDetails.ToList())
                        {
                            if (transportOrderDetail.FDP.AdminUnitID == subTransporterOrders.WoredaID)
                            {
                                var qty =
                                    _transportOrderService.CheckIfCommodityIsDipatchedToThisFdp(
                                        transportOrderDetail.FdpID, transportOrderDetail.TransportOrder.BidDocumentNo,
                                        transportOrderDetail.TransportOrder.TransporterID,
                                        transportOrderDetail.TransportOrderID,transportOrderDetail.CommodityID);
                                if (qty == null)
                                {
                                    var transportOrderDetailObj = new TransportOrderDetail
                                    {
                                        TransportOrderID = transportOrderObj.TransportOrderID,
                                        CommodityID = transportOrderDetail.CommodityID,
                                        FdpID = transportOrderDetail.FdpID,
                                        RequisitionID = transportOrderDetail.RequisitionID,
                                        QuantityQtl = transportOrderDetail.QuantityQtl,
                                        TariffPerQtl = transportOrderDetail.TariffPerQtl,
                                        SourceWarehouseID = transportOrderDetail.Hub.HubID,
                                        BidID = transportOrderDetail.BidID,
                                        WinnerAssignedByLogistics = true
                                    };
                                    _transportOrderService.UpdateTransporterOrder(transportOrderDetail.TransportOrderID, subTransporterOrders.WoredaID);
                                    //transportOrderDetail.ZoneID = reliefRequisitionDetail.ReliefRequisition.ZoneID;
                                    _transportOrderDetailService.AddTransportOrderDetail(transportOrderDetailObj);
                                }
                                else if (qty <= 0)
                                {
                                    continue;
                                }

                                //var qty = weightPref == "QTL"
                                //                 ? transportOrderDetail.QuantityQtl.ToMetricTone() / transporterCount
                                //                 : transportOrderDetail.QuantityQtl / transporterCount;

                            }
                        }

                        returnedObj.Add(transportOrderObj);

                    }
                }
            }
            //changedTransportOrderObj.StatusID = (int)TransportOrderStatus.Failed;
            _transportOrderService.EditTransportOrder(changedTransportOrderObj);
            return RedirectToAction("Index", "TransportOrder", returnedObj);
            //return Json(returnedObj.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }