public Task <List <PassengerDto> > GetAllPassengersInTrip(Guid VehicleTripId)
        {
            var passengers = from pass in _seatManagementService.GetAll()
                             join route in _routerepo.GetAll()
                             on pass.RouteId equals route.Id
                             where pass.VehicleTripRegistrationId == VehicleTripId

                             select new PassengerDto
            {
                Amount = pass.Amount,
                BookingReferenceCode = pass.BookingReferenceCode,
                FullName             = pass.FullName,
                Gender      = pass.Gender,
                PhoneNumber = pass.PhoneNumber,
                SeatNumber  = pass.SeatNumber,
                Route       = route.Name
            };

            return(Task.FromResult(passengers.ToList()));
        }
Exemple #2
0
        public Task <SalesSummaryDTO> GetSalesSummary()
        {
            var today       = DateTime.Now.Date;
            var currentDate = DateTime.Now;

            var todaysSales = _seatManagementService.GetAll().Where(p => p.BookingStatus == BookingStatus.Approved &&
                                                                    (p.CreationTime > today && p.CreationTime < currentDate))?.Sum(p => p.Amount);
            var yesterdaysSales = _seatManagementService.GetAll().Where(p => p.BookingStatus == BookingStatus.Approved &&
                                                                        (p.CreationTime > today.AddDays(-1) && p.CreationTime < currentDate.AddDays(-1)))?.Sum(p => p.Amount);
            var todaysBookings = _seatManagementService.GetAll().Where(p => p.BookingStatus == BookingStatus.Approved &&
                                                                       (p.CreationTime > today && p.CreationTime < currentDate))?.Count();
            var summary = new SalesSummaryDTO
            {
                TodaysSales    = todaysSales,
                LastSales      = yesterdaysSales,
                TodaysBookings = todaysBookings
            };

            return(Task.FromResult(summary));
        }
        public Task <ManifestDetailDTO> GetManifestPassengersByVehicleTripIdAsync(Guid vehicleTripId)
        {
            var seatBooking = new List <Tuple <int, int, bool> >();

            var vehiclemanifest = _repository.GetAllIncluding(x => x.VehicleModel)
                                  .Where(s => s.VehicleTripRegistrationId == vehicleTripId && s.VehicleModelId != null);

            var vehicletrip = _vehicleTripRepo.GetAll().Where(s => s.Id == vehicleTripId);

            var terminalCashBookings = _seatManagemengtSvc.GetAll()
                                       .Where(s => s.VehicleTripRegistrationId == vehicleTripId && s.BookingType == BookingTypes.Terminal && s.PaymentMethod == PaymentMethod.Cash);

            var partCashBookings = _seatManagemengtSvc.GetAll()
                                   .Where(s => s.VehicleTripRegistrationId == vehicleTripId && s.BookingType == BookingTypes.Terminal && s.PaymentMethod == PaymentMethod.CashAndPos);


            var rescheduleFee = _seatManagemengtSvc.GetAll()
                                .Where(s => s.VehicleTripRegistrationId == vehicleTripId && s.IsRescheduled && s.RescheduleStatus == RescheduleStatus.PayAtTerminal);

            var rerouteFee = _seatManagemengtSvc.GetAll()
                             .Where(s => s.VehicleTripRegistrationId == vehicleTripId && s.IsRerouted && s.RerouteStatus == RerouteStatus.PayAtTerminal);

            //RerouteFee = rerouteFee.Sum(i => i.RerouteFeeDiff),

            var allBookings = _seatManagemengtSvc.GetAll()
                              .Where(s => s.VehicleTripRegistrationId == vehicleTripId && s.BookingStatus == BookingStatus.Approved);
            List <int>            bookingTypes      = new List <int>();
            List <int>            seatsBooking      = new List <int>();
            List <int>            seatClashes       = new List <int>();
            List <bool>           ticketPrintStatus = new List <bool>();
            List <int>            remainingSeat     = new List <int>();
            Dictionary <int, int> bookedSeat        = new Dictionary <int, int>();
            Dictionary <int, int> clashedSeat       = new Dictionary <int, int>();

            foreach (var booking in allBookings)
            {
                bookingTypes.Add((int)booking.BookingType);
                ticketPrintStatus.Add(booking.IsPrinted);
                seatsBooking.Add(booking.SeatNumber);
                if (!bookedSeat.ContainsValue(booking.SeatNumber))
                {
                    bookedSeat.Add(booking.SeatNumber, booking.SeatNumber);
                }
                else
                {
                    clashedSeat.Add(booking.SeatNumber, booking.SeatNumber);
                    seatClashes.Add(booking.SeatNumber);
                }
            }


            string modelname = string.Empty;

            if (vehiclemanifest.FirstOrDefault() != null)
            {
                modelname = vehiclemanifest.FirstOrDefault().VehicleModel.Name;
                for (int j = 1; j <= vehiclemanifest.FirstOrDefault().VehicleModel.NumberOfSeats; j++)
                {
                    if (!bookedSeat.ContainsKey(j) && (modelname == "Hiace Super Ex" || modelname == "Hiace Ex") && j == 2)
                    {
                        continue;
                    }
                    else if (!bookedSeat.ContainsKey(j) && (j == 5 || j == 14) && modelname == "Hiace Super Ex")
                    {
                        continue;
                    }
                    else if (!bookedSeat.ContainsKey(j))
                    {
                        remainingSeat.Add(j);
                    }
                }
            }
            else
            {
                if (vehicletrip.FirstOrDefault() != null)
                {
                    modelname = vehicletrip.FirstOrDefault().VehicleModel.Name;
                    for (int j = 1; j <= vehicletrip.FirstOrDefault().VehicleModel.NumberOfSeats; j++)
                    {
                        if (!bookedSeat.ContainsKey(j) && (modelname == "Hiace Super Ex" || modelname == "Hiace Ex") && j == 2)
                        {
                            continue;
                        }
                        else if (!bookedSeat.ContainsKey(j) && (j == 5 || j == 14) && modelname == "Hiace Super Ex")
                        {
                            continue;
                        }
                        else if (!bookedSeat.ContainsKey(j))
                        {
                            remainingSeat.Add(j);
                        }
                    }
                }
            }

            var manifestManagements =
                from manifestManagement in _repository.GetAll()
                join vehicleTripRegistration in _vehicleTripRepo.GetAll() on manifestManagement.VehicleTripRegistrationId equals vehicleTripRegistration.Id

                let selectedSeats = _seatManagemengtSvc.GetAll()
                                    .Where(s => s.VehicleTripRegistrationId == vehicleTripId && s.BookingStatus == BookingStatus.Approved)

                                    let captain = _driverRepo.GetAll().Where(s => s.Code == vehicleTripRegistration.DriverCode)
                                                  let originalcaptain = _driverRepo.GetAll().Where(s => s.Code == vehicleTripRegistration.OriginalDriverCode)

                                                                        where manifestManagement.VehicleTripRegistrationId == vehicleTripId

                                                                        select new ManifestDetailDTO
            {
                Id                        = manifestManagement.Id,
                NumberOfSeats             = manifestManagement.NumberOfSeats,
                IsPrinted                 = manifestManagement.IsPrinted,
                DispatchSource            = manifestManagement.DispatchSource,
                PrintedBy                 = manifestManagement.Employee,
                TotalSeats                = vehiclemanifest.FirstOrDefault() != null?vehiclemanifest.FirstOrDefault().VehicleModel.NumberOfSeats : vehicleTripRegistration.VehicleModel.NumberOfSeats,
                DepartureDate             = vehicleTripRegistration.DepartureDate,
                DepartureTime             = vehicleTripRegistration.Trip.DepartureTime,
                VehicleTripRegistrationId = vehicleTripId,
                Route                     = vehicleTripRegistration.Trip.Route.Name,
                TotalSold                 = terminalCashBookings.Sum(i => i.Amount - i.Discount) + partCashBookings.Sum(i => i.PartCash),
                RescheduleFee             = rescheduleFee.Count() * 500,
                RerouteFee                = rerouteFee.Where(i => i.RerouteFeeDiff >= 0).Sum(i => i.RerouteFeeDiff) + rerouteFee.Count() * 500,
                Dispatch                  = manifestManagement.Dispatch,

                VehicleModel = manifestManagement.VehicleModel.Name ?? vehicleTripRegistration.VehicleModel.Name,

                DriverCode        = captain.Any() && captain.FirstOrDefault().DriverType == DriverType.Virtual ? vehicleTripRegistration.OriginalDriverCode : vehicleTripRegistration.DriverCode,
                DriverName        = captain.Any() && captain.FirstOrDefault().DriverType == DriverType.Virtual ? originalcaptain.FirstOrDefault().Name      : captain.FirstOrDefault().Name,
                DriverPhone       = captain.Any() && captain.FirstOrDefault().DriverType == DriverType.Virtual ? originalcaptain.FirstOrDefault().Phone1    : captain.FirstOrDefault().Phone1,
                RemainingSeat     = remainingSeat,
                BookSeat          = seatsBooking,
                ClashingSeats     = seatClashes,
                TicketPrintStatus = ticketPrintStatus,
                BookingTypes      = bookingTypes,

                RemainingSeatCount    = vehicletrip.FirstOrDefault().VehicleModel.NumberOfSeats - selectedSeats.Count(),
                Amount                = manifestManagement.Amount,
                BusRegistrationNumber = vehicleTripRegistration.PhysicalBusRegistrationNumber,
                Passengers            = selectedSeats.Select(s => new SeatManagementDTO
                {
                    Id                        = s.Id,
                    SeatNumber                = s.SeatNumber,
                    BookingReferenceCode      = s.BookingReferenceCode,
                    NextOfKinName             = s.NextOfKinName,
                    NextOfKinPhoneNumber      = s.NextOfKinPhoneNumber,
                    IsPrinted                 = s.IsPrinted,
                    PhoneNumber               = s.PhoneNumber,
                    FullName                  = s.FullName,
                    PassengerType             = s.PassengerType,
                    Gender                    = s.Gender,
                    VehicleTripRegistrationId = s.VehicleTripRegistrationId,
                    Amount                    = s.Amount ?? manifestManagement.Amount,
                    PartCash                  = s.PartCash,
                    POSReference              = s.POSReference,
                    Discount                  = s.Discount,
                    RouteId                   = s.RouteId ?? vehicleTripRegistration.Trip.RouteId,
                    RouteName                 = vehicleTripRegistration.Trip.Route.Name,
                    PaymentMethod             = s.PaymentMethod,
                    BookingType               = s.BookingType,
                    SubRouteId                = s.SubRouteId,
                    SubRouteName              = s.SubRoute.Name ?? s.Route.Name,
                    DateCreated               = s.CreationTime,
                    DateModified              = s.LastModificationTime,
                    TravelStatus              = s.TravelStatus,
                    RescheduleStatus          = s.RescheduleStatus,
                    IsRescheduled             = s.IsRescheduled,
                    RerouteStatus             = s.RerouteStatus,
                    IsRerouted                = s.IsRerouted,
                    IsUpgradeDowngrade        = s.IsUpgradeDowngrade,
                    UpgradeDowngradeDiff      = s.UpgradeDowngradeDiff,
                    UpgradeType               = s.UpgradeType,
                    RerouteFeeDiff            = s.RerouteFeeDiff,
                    CreatedBy                 = s.CreatedBy,
                    PickUpPointId             = s.PickUpPointId,
                    PickupStatus              = s.PickupStatus,
                    LastModificationTime      = s.LastModificationTime,
                    IsGhanaRoute              = s.IsGhanaRoute,
                    PassportType              = s.PassportType,
                    PassportId                = s.PassportId,
                    PlaceOfIssue              = s.PlaceOfIssue,
                    IssuedDate                = s.IssuedDate,
                    ExpiredDate               = s.ExpiredDate,
                    Nationality               = s.Nationality
                }).OrderByDescending(e => e.LastModificationTime)
            };

            return(manifestManagements.AsNoTracking().FirstOrDefaultAsync());
        }