Ejemplo n.º 1
0
        protected IList GetData(out int count)
        {
            ICriterion criterion = SailsModule.IncomeCriterion();

            if (String.IsNullOrEmpty(Request.QueryString["ps"]))
            {
                criterion = Expression.And(criterion, Expression.Eq("DriverCollected", false));
            }

            criterion = Expression.And(criterion, Expression.Or(Expression.Gt("DriverCollect", 0d), Expression.Gt("DriverCollectVND", 0d)));
            DateTime from;
            DateTime to;

            if (string.IsNullOrEmpty(txtFrom.Text) || string.IsNullOrEmpty(txtTo.Text))
            {
                from = DateTime.Today.AddDays(-DateTime.Today.Day + 1);
                to   = from.AddMonths(1).AddDays(-1);
            }
            else
            {
                from = DateTime.ParseExact(txtFrom.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                to   = DateTime.ParseExact(txtTo.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }

            if (Request.QueryString["mode"] != "all") // Nếu không phải là mode all thì thêm điều kiện về thời gian
            {
                txtFrom.Text = from.ToString("dd/MM/yyyy");
                txtTo.Text   = to.ToString("dd/MM/yyyy");
                criterion    = Expression.And(criterion,
                                              Expression.And(Expression.Ge(Booking.STARTDATE, from),
                                                             Expression.Le(Booking.STARTDATE, to)));
            }
            else
            {
                criterion = Expression.And(criterion, Expression.Eq("IsPaid", false));
            }

            if (Request.QueryString["paidon"] != null)
            {
                criterion = Expression.And(criterion, Expression.Ge("PaidDate", DateTime.FromOADate(Convert.ToDouble(Request.QueryString["paidon"]))));
                criterion = Expression.And(criterion, Expression.Lt("PaidDate", DateTime.FromOADate(Convert.ToDouble(Request.QueryString["paidon"])).AddDays(1)));
            }

            ICriterion agencyCrit = SetCriterion(GetAgencies());

            if (agencyCrit != null)
            {
                criterion = Expression.And(criterion, agencyCrit);
            }

            if (UserIdentity.HasPermission(AccessLevel.Administrator) || Module.PermissionCheck("VIEW_ALLBOOKINGGUIDECOLLECT", UserIdentity))
            {
                // Nếu có quyền xem hết thì mới để ý đến tham số saleid
                if (Request.QueryString["saleid"] != null)
                {
                    int saleid = Convert.ToInt32(Request.QueryString["saleid"]);
                    if (saleid > 0)
                    {
                        criterion = Expression.And(criterion, Expression.Eq("agency.Sale", Module.UserGetById(saleid)));
                    }
                    else
                    {
                        criterion = Expression.And(criterion, Expression.IsNull("agency.Sale"));
                    }
                }
            }
            else
            {
                criterion = Expression.And(criterion, Expression.Eq("agency.Sale", UserIdentity));
            }

            if (Request.QueryString["bookingcode"] != null)
            {
                string code = Request.QueryString["bookingcode"];
                criterion = SailsModule.AddBookingCodeCriterion(criterion, code);
            }

            bool tripped = false;

            if (Request.QueryString["tripid"] != null)
            {
                criterion = Expression.And(criterion,
                                           Expression.Eq("Trip.Id", Convert.ToInt32(Request.QueryString["tripid"])));
                tripped = true;
            }

            if (Request.QueryString["orgid"] != null)
            {
                criterion = Expression.And(criterion,
                                           Expression.Eq("trip.Organization", Module.OrganizationGetById(Convert.ToInt32(Request.QueryString["orgid"]))));
                tripped = true;
            }

            if (Request.QueryString["ps"] != null)
            {
                switch (Request.QueryString["ps"])
                {
                case "notpaid":
                    criterion = Expression.And(criterion, Expression.Eq("DriverCollected", false));
                    break;

                case "paid":
                    criterion = Expression.And(criterion, Expression.Eq("DriverCollected", true));
                    break;
                }
            }

            var bookings          = Module.BookingGetByCriterion(criterion, Order.Asc(Booking.STARTDATE), out count, 0, 0, tripped, UserIdentity);
            var bookingFilterList = new List <Booking>();

            if (Request.QueryString["drivername"] != null)
            {
                foreach (Booking booking in bookings)
                {
                    var            sailDate = Module.ExpenseGetByDate(booking.Trip, booking.StartDate);
                    ExpenseService driver   = null;
                    foreach (ExpenseService service in sailDate.Services)
                    {
                        if (service.Type.Name.ToUpper() == "TRANSPORT" && service.Group == booking.Group)
                        {
                            driver = service;
                            if (driver != null && driver.Supplier != null)
                            {
                                if (driver.Name.Contains(Request.QueryString["drivername"]))
                                {
                                    bookingFilterList.Add(booking);
                                }
                            }
                        }
                    }
                }
                bookings = bookingFilterList;
            }

            var bookingDriverFilterList = new List <Booking>();

            if (Request.QueryString["supplierid"] != null)
            {
                var agencyId = Convert.ToInt32(Request.QueryString["supplierid"]);
                foreach (Booking booking in bookings)
                {
                    var            sailDate = Module.ExpenseGetByDate(booking.Trip, booking.StartDate);
                    ExpenseService driver   = null;
                    foreach (ExpenseService service in sailDate.Services)
                    {
                        if (service.Type.Name.ToUpper() == "TRANSPORT" && service.Group == booking.Group)
                        {
                            driver = service;
                            if (driver != null && driver.Supplier != null)
                            {
                                if (driver.Supplier.Id == agencyId)
                                {
                                    bookingDriverFilterList.Add(booking);
                                }
                            }
                        }
                    }
                }
                bookings = bookingDriverFilterList;
            }

            return(bookings);
        }
        protected IList GetData(out int count, params Order[] orders)
        {
            ICriterion criterion = SailsModule.IncomeCriterion();
            DateTime   from;
            DateTime   to;

            if (string.IsNullOrEmpty(txtFrom.Text) || string.IsNullOrEmpty(txtTo.Text))
            {
                from = DateTime.Today.AddDays(-DateTime.Today.Day + 1);
                to   = from.AddMonths(1).AddDays(-1);
            }
            else
            {
                from = DateTime.ParseExact(txtFrom.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                to   = DateTime.ParseExact(txtTo.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            //if (Request.QueryString["mode"] != "all") // Nếu không phải là mode all thì thêm điều kiện về thời gian
            //{
            txtFrom.Text = from.ToString("dd/MM/yyyy");
            txtTo.Text   = to.ToString("dd/MM/yyyy");
            criterion    = Expression.And(criterion,
                                          Expression.And(Expression.Ge(Booking.STARTDATE, from),
                                                         Expression.Le(Booking.STARTDATE, to)));
            //}
            //else
            //{
            //criterion = Expression.And(criterion, Expression.Not(Expression.Eq("ComPaid", true)));
            ICriterion commissionCriterion = Expression.Or(Expression.Gt("Commission", (double)0), Expression.Gt("CommissionVND", (double)0));

            criterion = Expression.And(criterion, commissionCriterion);
            //}

            if (Request.QueryString["paidon"] != null)
            {
                criterion = Expression.And(criterion, Expression.Ge("PaidDate", DateTime.FromOADate(Convert.ToDouble(Request.QueryString["paidon"]))));
                criterion = Expression.And(criterion, Expression.Lt("PaidDate", DateTime.FromOADate(Convert.ToDouble(Request.QueryString["paidon"])).AddDays(1)));
            }

            ICriterion agencyCrit = SetCriterion(GetAgencies());

            if (agencyCrit != null)
            {
                criterion = Expression.And(criterion, agencyCrit);
            }

            if (UserIdentity.HasPermission(AccessLevel.Administrator) || Module.PermissionCheck("VIEW_ALLBOOKINGRECEIVABLE", UserIdentity))
            {
                // Nếu có quyền xem hết thì mới để ý đến tham số saleid
                if (Request.QueryString["saleid"] != null)
                {
                    int saleid = Convert.ToInt32(Request.QueryString["saleid"]);
                    if (saleid > 0)
                    {
                        criterion = Expression.And(criterion, Expression.Eq("agency.Sale", Module.UserGetById(saleid)));
                    }
                    else
                    {
                        criterion = Expression.And(criterion, Expression.IsNull("agency.Sale"));
                    }
                }
            }
            else
            {
                criterion = Expression.And(criterion, Expression.Eq("agency.Sale", UserIdentity));
            }

            if (Request.QueryString["bookingcode"] != null)
            {
                string code = Request.QueryString["bookingcode"];
                criterion = SailsModule.AddBookingCodeCriterion(criterion, code);
            }

            Order order = Order.Asc(Booking.STARTDATE);

            if (orders.Length > 0)
            {
                order = orders[0];
            }

            return(Module.BookingGetByCriterion(criterion, order, out count, 0, 0, false, UserIdentity));
        }
Ejemplo n.º 3
0
        protected void rptBookingList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Dictionary <SailsTrip, double> incomes = new Dictionary <SailsTrip, double>(AllTrips.Count);
            double total = 0;

            foreach (SailsTrip trip in AllTrips)
            {
                incomes.Add(trip, 0);
            }

            if (e.Item.DataItem is DateTime)
            {
                DateTime  date    = (DateTime)e.Item.DataItem;
                HyperLink hplDate = (HyperLink)e.Item.FindControl("hplDate");
                if (hplDate != null)
                {
                    hplDate.Text        = date.ToString("dd/MM/yyyy");
                    hplDate.NavigateUrl = string.Format("BookingReport.aspx?NodeId={0}&SectionId={1}&Date={2}", Node.Id,
                                                        Section.Id, date.ToOADate());
                }

                #region -- Counting --
                int count;
                // Khi tính income thì chỉ tính theo khách đã check-in
                ICriterion criterion = Expression.And(Expression.Eq(Booking.STARTDATE, date),
                                                      SailsModule.IncomeCriterion());
                // Bỏ deleted và cả transfer
                criterion = Expression.And(Expression.Eq("Deleted", false), criterion);
                criterion = Expression.And(Expression.Eq("IsTransferred", false), criterion);

                if (ActiveCruise != null)
                {
                    criterion = Expression.And(Expression.Eq("Cruise", ActiveCruise), criterion);
                }

                IList bookings =
                    Module.BookingGetByCriterion(criterion, null, out count, 0, 0, false, UserIdentity);
                int pax = 0;

                foreach (Booking booking in bookings)
                {
                    if (booking.Status == StatusType.Approved)
                    {
                        // Số khách trong cả book, bao gồm cả trẻ em và trẻ sơ sinh
                        int inBook = 0;
                        inBook += booking.Adult;
                        foreach (BookingRoom room in booking.BookingRooms)
                        {
                            if (room.HasChild)
                            {
                                inBook++;
                            }
                            if (room.HasBaby)
                            {
                                inBook++;
                            }
                        }
                        pax += inBook;
                    }
                    _total += booking.Value;
                    total  += booking.Value;
                    incomes[booking.Trip]  += booking.Value;
                    _incomes[booking.Trip] += booking.Value;
                }
                _pax += pax;
                Literal litTotalPax = (Literal)e.Item.FindControl("litTotalPax");
                Literal litTotal    = (Literal)e.Item.FindControl("litTotal");
                litTotalPax.Text = pax.ToString();
                litTotal.Text    = (total).ToString("#,0");

                #endregion

                _currentIncomes = incomes;
                Repeater rptTrip = (Repeater)e.Item.FindControl("rptTrip");
                rptTrip.DataSource = AllTrips;
                rptTrip.DataBind();

                if (ActiveCruise != null)
                {
                    BarRevenue bar    = Module.BarRevenueGetByDate(ActiveCruise, date);
                    Literal    litBar = e.Item.FindControl("litBar") as Literal;
                    if (litBar != null)
                    {
                        litBar.Text = bar.Revenue.ToString("0");
                        _bar       += bar.Revenue;
                    }
                }
                else
                {
                    double  bar    = Module.SumBarByDate(date);
                    Literal litBar = e.Item.FindControl("litBar") as Literal;
                    if (litBar != null)
                    {
                        litBar.Text = bar.ToString("0");
                        _bar       += bar;
                    }
                }
            }
            else if (e.Item.ItemType == ListItemType.Footer)
            {
                Literal  litTotalPax = (Literal)e.Item.FindControl("litTotalPax");
                Literal  litTotal    = (Literal)e.Item.FindControl("litTotal");
                Repeater rptTrip     = (Repeater)e.Item.FindControl("rptTrip");
                rptTrip.DataSource = AllTrips;
                rptTrip.DataBind();
                litTotalPax.Text = _pax.ToString();
                litTotal.Text    = _total.ToString("#,0");

                Literal litBar = e.Item.FindControl("litBar") as Literal;
                if (litBar != null)
                {
                    litBar.Text = _bar.ToString("0");
                }
            }
            else if (e.Item.ItemType == ListItemType.Header)
            {
                Repeater rptTrip = (Repeater)e.Item.FindControl("rptTrip");
                rptTrip.DataSource = AllTrips;
                rptTrip.DataBind();
            }
        }