Example #1
0
        protected void btnExport3Day_Click(object sender, EventArgs e)
        {
            IList list;
            int   count = GetData(out list, false);

            if (count == 0)
            {
                ShowErrors(Resources.errorNoBookingSave);
                return;
            }
            DateTime date = DateTime.ParseExact(txtDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);

            IList <ExpenseService> expenseList       = new List <ExpenseService>();
            IList <ExpenseService> expenseListExport = new List <ExpenseService>();

            foreach (RepeaterItem rptItem in rptCruiseExpense.Items)
            {
                HiddenField hiddenId = (HiddenField)rptItem.FindControl("hiddenId");
                Cruise      cruise   = Module.CruiseGetById(Convert.ToInt32(hiddenId.Value));
                Expense     expense  = Module.ExpenseGetByDate(cruise, date);
                Module.SaveOrUpdate(expense);
                Repeater rptServices = (Repeater)rptItem.FindControl("rptServices");
                expenseList = rptServicesToIList(rptServices);

                if (String.IsNullOrEmpty(Request.QueryString["cruiseid"]))
                {
                    for (int i = 0; i < rptServicesToIList(rptServices).Count; i++)
                    {
                        expenseListExport.Add(rptServicesToIList(rptServices)[i]);
                    }
                }
                else
                {
                    expenseListExport = rptServicesToIList(rptServices);
                }
                foreach (ExpenseService service in expenseList)
                {
                    service.Expense = expense;
                    if (service.IsRemoved)
                    {
                        if (service.Id > 0)
                        {
                            expense.Services.Remove(service);
                        }
                    }
                    else
                    {
                        // Phải có tên hoặc giá thì mới lưu
                        if (!string.IsNullOrEmpty(service.Name) || service.Cost > 0 ||
                            service.Type.Id == SailsModule.GUIDE_COST)
                        {
                            Module.SaveOrUpdate(service);
                        }
                    }
                }

                Module.SaveOrUpdate(expense);
            }

            if (Cruise != null)
            {
                DayNote note = Module.DayNoteGetByDay(Cruise, date);

                if (!string.IsNullOrEmpty(note.Note) || note.Id > 0)
                {
                    Module.SaveOrUpdate(note);
                }
            }

            LoadService(date);

            if (Cruise != null)
            {
                BarRevenue bar = Module.BarRevenueGetByDate(Cruise, date);
                Module.SaveOrUpdate(bar);
            }

            string tplPath = Server.MapPath("/Modules/Sails/Admin/ExportTemplates/Lenhdieutour_dayboat.xls");

            if (String.IsNullOrEmpty(Request.QueryString["cruiseid"]))
            {
                TourCommand.Export2(list, count, expenseListExport, _date, BookingFormat, Response, tplPath, null);
            }
            else
            {
                var cruise = Module.GetObject <Cruise>(Convert.ToInt32(Request.QueryString["cruiseid"]));
                TourCommand.Export2(list, count, expenseListExport, _date, BookingFormat, Response, tplPath, cruise);
            }
        }
Example #2
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();
            }
        }