private void CalculateCostIncurred(Ticket ticket)
        {
            var ticketPrice = FlightForBooking.GetPrice(ticket.Schedule, ticket.CabinType);

            double costIncurred            = 100;
            var    timeBeforeFlightTakeoff = (ticket.Schedule.Date + ticket.Schedule.Time) - DateTime.Now;

            if (timeBeforeFlightTakeoff.TotalHours < 12)
            {
                MessageBox.Show("This ticket cann't be canceled! See cancel ticket policy for more information.", "Message", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else if (timeBeforeFlightTakeoff.TotalDays >= 3 && timeBeforeFlightTakeoff.TotalDays <= 5)
            {
                costIncurred = 20;
            }
            else if (timeBeforeFlightTakeoff.TotalDays > 5 && timeBeforeFlightTakeoff.TotalDays <= 7)
            {
                costIncurred = 10;
            }
            else
            {
                costIncurred = 0;
            }

            costIncurred = (ticketPrice * costIncurred / 100);

            tblReturn.Text       = (ticketPrice - costIncurred).ToString("C2");
            tblCostIncurred.Text = costIncurred.ToString("C2");
        }
        private double UpdateRevenue(List <Ticket> tickets)
        {
            double revenue = 0;

            foreach (var item in tickets)
            {
                revenue += FlightForBooking.GetPrice(item.Schedule, item.CabinType);
            }

            return(revenue);
        }
        private void LoadChartForAllCabinTypes()
        {
            DeleteSeriesOfChartRevenueFromTickets();

            chartRevenueFromTicket.Series[0].ChartType = SeriesChartType.Column;

            var cabins  = Db.Context.CabinTypes.ToList();
            var tickets = Tickets;

            if (ViewMode == "rdbByTime")
            {
                chartRevenueFromTicket.Titles[0].Text = $"Revenue detail for all Cabin types on {TimeOrMonthOrQuarterOrYear}";
            }
            else if (ViewMode == "rdbByWeek")
            {
                chartRevenueFromTicket.Titles[0].Text = $"Revenue detail for all Cabin types on {TimeOrMonthOrQuarterOrYear} this week";
            }
            else if (ViewMode == "rdbByMonth")
            {
                chartRevenueFromTicket.Titles[0].Text = $"Revenue detail for all Cabin types on {TimeOrMonthOrQuarterOrYear} {Year}";
            }
            else if (ViewMode == "rdbByQuarter")
            {
                chartRevenueFromTicket.Titles[0].Text = $"Revenue detail for all Cabin types in {TimeOrMonthOrQuarterOrYear} {Year}";
            }
            else if (ViewMode == "rdbByYear")
            {
                chartRevenueFromTicket.Titles[0].Text = $"Revenue detail for all Cabin types in {Year}";
            }

            int i = 0;

            foreach (var item in cabins)
            {
                string value;

                if (CbTicketViewType.Text == "Revenue")
                {
                    chartRevenueFromTicket.Series[0].Name = "Revenue";
                    value = FlightForBooking.GetPrice(tickets.Where(t => t.CabinTypeID == item.ID).ToList(), item.ID).ToString("C0");
                }
                else
                {
                    chartRevenueFromTicket.Series[0].Name = "Quantity";
                    value = tickets.Count(t => t.CabinTypeID == item.ID).ToString();
                }

                chartRevenueFromTicket.Series[0].Points.AddXY(item.Name, value);
                chartRevenueFromTicket.Series[0].Points[i].Label = value;

                i++;
            }
        }
Пример #4
0
        private double UpdateCommission(List <Ticket> tickets)
        {
            double revenue = 0;

            revenue += FlightForBooking.GetPrice(tickets.Where(t => t.CabinTypeID == 1).ToList(), 1);
            revenue += FlightForBooking.GetPrice(tickets.Where(t => t.CabinTypeID == 2).ToList(), 2);
            revenue += FlightForBooking.GetPrice(tickets.Where(t => t.CabinTypeID == 3).ToList(), 3);

            revenue += tickets.Sum(t => t.AmenitiesTickets.Sum(k => (int)k.Price));

            return(revenue * 0.003);
        }
        private List <FlightForBooking> IndirectFlight2(string from, string to, bool isChecked, DateTime date)
        {
            List <FlightForBooking> results = new List <FlightForBooking>();
            var before = date.AddDays(-3);

            before = before < DateTime.Now.Date ? DateTime.Now.Date : before;

            var after = date.AddDays(3);
            var sch1  = Db.Context.Schedules.Where(t => t.Date >= before && t.Date <= after && t.Route.Airport.IATACode == from && t.Route.Airport1.IATACode != from && t.Route.Airport1.IATACode != to && t.Confirmed).ToList();

            if (!isChecked)
            {
                sch1 = sch1.Where(t => t.Date == date).ToList();
            }

            foreach (var s1 in sch1)
            {
                var arrivalTime = (s1.Date + s1.Time).AddMinutes(s1.Route.FlightTime + 60);
                var sch2        = Db.Context.Schedules.Where(t => t.Route.Airport.IATACode == s1.Route.Airport1.IATACode && t.Route.Airport1.IATACode != from && t.Route.Airport1.IATACode != to && t.Confirmed).ToList();

                var limitTime = arrivalTime.AddHours(24);
                sch2 = sch2.Where(t => t.Date + t.Time >= arrivalTime && t.Date + t.Time <= limitTime).ToList();

                foreach (var s2 in sch2)
                {
                    arrivalTime = (s2.Date + s2.Time).AddMinutes(s2.Route.FlightTime + 60);
                    var sch3 = Db.Context.Schedules.Where(t => t.Route.Airport.IATACode == s2.Route.Airport1.IATACode && t.Route.Airport1.IATACode == to && t.Confirmed).ToList();

                    limitTime = arrivalTime.AddHours(24);
                    sch3      = sch3.Where(t => t.Date + t.Time >= arrivalTime && t.Date + t.Time <= limitTime).ToList();

                    foreach (var s3 in sch3)
                    {
                        results.Add(new FlightForBooking()
                        {
                            From    = from,
                            To      = to,
                            Price   = FlightForBooking.GetPrice(s1, cbCabinType.SelectedItem as CabinType) + FlightForBooking.GetPrice(s2, cbCabinType.SelectedItem as CabinType) + FlightForBooking.GetPrice(s3, cbCabinType.SelectedItem as CabinType),
                            Flights = new List <Schedule>()
                            {
                                s1, s2, s3
                            },
                            NumberOfStop  = 2,
                            FirstFlight   = s1,
                            FlightNumbers = $"[{s1.FlightNumber}] - [{s2.FlightNumber}] - [{ s3.FlightNumber }]",
                        });
                    }
                }
            }

            return(results);
        }
Пример #6
0
        private void CalculateCosts(Ticket ticket)
        {
            var payed = FlightForBooking.GetPrice(ticket.Schedule, ticket.CabinType);
            var total = currentFlight == null?FlightForBooking.GetPrice(ticket.Schedule, cabins[cbCabinType.SelectedIndex]) : FlightForBooking.GetPrice(currentFlight.Schedule, cabins[cbCabinType.SelectedIndex]);

            tblTotalAfterChange.Text = total.ToString("C2");
            tblTotalPayed.Text       = payed.ToString("C2");
            tblTotalPayable.Text     = (total - payed + costIncurred).ToString("C2");
            if (total - payed < 0)
            {
                tblTotalPayable.Text += " (return for passenger)";
            }
        }
        private double RevenueFromTickets(List <Ticket> tickets)
        {
            //double revenue = Flight.GetPrice(tickets.Where(t => t.CabinTypeID == 1).ToList(), 1);
            //revenue += Flight.GetPrice(tickets.Where(t => t.CabinTypeID == 2).ToList(), 2);
            //revenue += Flight.GetPrice(tickets.Where(t => t.CabinTypeID == 3).ToList(), 3);
            double revenue = 0;

            foreach (var item in tickets)
            {
                revenue += FlightForBooking.GetPrice(item.Schedule, item.CabinType);
            }

            return(revenue);
        }
Пример #8
0
        private void DisplayTickets()
        {
            dgTickets.ItemsSource = null;
            newTickets            = new List <NewTicket>();

            foreach (var item in tickets)
            {
                newTickets.Add(new NewTicket()
                {
                    Ticket   = item,
                    FullName = item.Firstname + " " + item.Lastname,
                    Price    = FlightForBooking.GetPrice(item.Schedule, item.CabinType),
                    Route    = item.Schedule.Route.Airport.IATACode + " - " + item.Schedule.Route.Airport1.IATACode
                });
            }

            dgTickets.ItemsSource = newTickets;
        }
        private List <FlightForBooking> LoadData(DataGrid dg, string from, string to, bool?isChecked, DateTime date)
        {
            dg.ItemsSource = null;
            List <FlightForBooking> flights = new List <FlightForBooking>();

            var before = date.AddDays(-3);

            before = before < DateTime.Now.Date ? DateTime.Now.Date : before;

            var after = date.AddDays(3);
            var sch1  = Db.Context.Schedules.Where(t => t.Date >= before && t.Date <= after && t.Route.Airport.IATACode == from && t.Route.Airport1.IATACode == to && t.Confirmed).ToList();

            if (!isChecked.Value)
            {
                sch1 = sch1.Where(t => t.Date == date).ToList();
            }

            foreach (var item in sch1)
            {
                flights.Add(new FlightForBooking()
                {
                    From         = from,
                    To           = to,
                    FirstFlight  = item,
                    NumberOfStop = 0,
                    Price        = FlightForBooking.GetPrice(item, cbCabinType.SelectedItem as CabinType),
                    Flights      = new List <Schedule>()
                    {
                        item
                    },
                    FlightNumbers = $"[{item.FlightNumber}]"
                });
            }

            flights.AddRange(IndirectFlight1(from, to, isChecked.Value, date));
            flights.AddRange(IndirectFlight2(from, to, isChecked.Value, date));
            dg.ItemsSource = flights;

            return(flights);
        }
Пример #10
0
        private void CalculateCostIncurred(Ticket ticket)
        {
            var ticketPrice = FlightForBooking.GetPrice(ticket.Schedule, ticket.CabinType);

            costIncurred = 0;
            var timeBeforeFlightTakeoff = (ticket.Schedule.Date + ticket.Schedule.Time) - DateTime.Now;

            if (timeBeforeFlightTakeoff.TotalHours <= 3)
            {
                costIncurred = 20;
            }
            else if (timeBeforeFlightTakeoff.TotalHours > 3 && timeBeforeFlightTakeoff.TotalHours <= 24)
            {
                costIncurred = 15;
            }
            else if (timeBeforeFlightTakeoff.TotalDays > 1 && timeBeforeFlightTakeoff.TotalDays <= 3)
            {
                costIncurred = 10;
            }

            costIncurred         = (ticketPrice * costIncurred / 100);
            tblCostIncurred.Text = costIncurred.ToString("C2");
        }
        private void LoadChartForOneCabinType()
        {
            DeleteSeriesOfChartRevenueFromTickets();

            chartRevenueFromTicket.Series[0].ChartType   = SeriesChartType.Line;
            chartRevenueFromTicket.Series[0].BorderWidth = 2;

            var cabinId = (cbCabinType.SelectedItem as CabinType).ID;
            var tickets = Tickets.Where(t => t.CabinTypeID == cabinId).ToList();

            if (ViewMode == "rdbByMonth")
            {
                chartRevenueFromTicket.Titles[0].Text = $"Revenue detail for cabin type: {cbCabinType.Text} on {TimeOrMonthOrQuarterOrYear} {Year}";

                var month = DateTime.Parse(TimeOrMonthOrQuarterOrYear + " " + Year).Date;

                int pointIndex = 0;
                for (DateTime date = month; date < month.AddMonths(1); date = date.AddDays(1))
                {
                    string value;

                    if (CbTicketViewType.Text == "Revenue")
                    {
                        chartRevenueFromTicket.Series[0].Name = "Revenue";
                        value = FlightForBooking.GetPrice(tickets.Where(t => t.Schedule.Date == date).ToList(), cabinId).ToString("C0");
                    }
                    else
                    {
                        chartRevenueFromTicket.Series[0].Name = "Quantity";
                        value = tickets.Count(t => t.Schedule.Date == date).ToString();
                    }

                    chartRevenueFromTicket.Series[0].Points.AddXY(date.ToString("dd/MM/yyyy"), value);
                    chartRevenueFromTicket.Series[0].Points[pointIndex].Label = value;

                    pointIndex++;
                }
            }
            else if (ViewMode == "rdbByQuarter")
            {
                chartRevenueFromTicket.Titles[0].Text = $"Revenue detail for cabin type: {cbAmenities.Text} in {TimeOrMonthOrQuarterOrYear} {Year}";

                var quarter = int.Parse(TimeOrMonthOrQuarterOrYear.Last().ToString());
                var from    = (quarter * 2) + (quarter - 2);
                var to      = quarter * 3;

                int poinIndex = 0;
                for (int j = from; j <= to; j++)
                {
                    var    month = new DateTime(2018, j, 1).ToString("MMMM");
                    string value;

                    if (CbTicketViewType.Text == "Revenue")
                    {
                        chartRevenueFromTicket.Series[0].Name = "Revenue";
                        value = FlightForBooking.GetPrice(tickets.Where(t => t.Schedule.Date.Month == j).ToList(), cabinId).ToString("C0");
                    }
                    else
                    {
                        chartRevenueFromTicket.Series[0].Name = "Quantity";
                        value = tickets.Count(t => t.Schedule.Date.Month == j).ToString();
                    }

                    chartRevenueFromTicket.Series[0].Points.AddXY(month, value);
                    chartRevenueFromTicket.Series[0].Points[poinIndex].Label = value;

                    poinIndex++;
                }
            }
            else if (ViewMode == "rdbByYear")
            {
                chartRevenueFromTicket.Titles[0].Text = $"Revenue detail for cabin type: {cbAmenities.Text} in {Year}";

                int pointIndex = 0;
                for (int j = 1; j < 13; j++)
                {
                    var    month = new DateTime(2018, j, 1).ToString("MMMM");
                    string value;

                    if (CbTicketViewType.Text == "Revenue")
                    {
                        value = FlightForBooking.GetPrice(tickets.Where(t => t.Schedule.Date.Month == j).ToList(), cabinId).ToString("C0");
                    }
                    else
                    {
                        value = tickets.Count(t => t.Schedule.Date.Month == j).ToString();
                    }

                    chartRevenueFromTicket.Series[0].Points.AddXY(month, value);
                    chartRevenueFromTicket.Series[0].Points[pointIndex].Label = value;

                    pointIndex++;
                }
            }
        }