protected void rptYearlyExpenses_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.DataItem is CostType) { CostType type = (CostType)e.Item.DataItem; SailExpense expense = Module.ExpenseGetByDate(ActiveCruise, _yearDate); if (expense.Id < 0) { Module.SaveOrUpdate(expense); } else { IList costs = Module.ExpenseServiceGet(ActiveCruise, _yearDate, _yearDate, null, type); if (costs.Count > 0) { ExpenseService cost = costs[0] as ExpenseService; if (cost != null) { TextBox txtCost = (TextBox)e.Item.FindControl("txtCost"); HiddenField hiddenId = (HiddenField)e.Item.FindControl("hiddenId"); hiddenId.Value = cost.Id.ToString(); txtCost.Text = cost.Cost.ToString("#,0.#"); } } else { IList lastCosts = Module.ExpenseServiceGet(ActiveCruise, _yearDate.AddYears(-1), _yearDate.AddYears(-1), null, type); if (lastCosts.Count > 0) { ExpenseService cost = lastCosts[0] as ExpenseService; if (cost != null) { TextBox txtCost = (TextBox)e.Item.FindControl("txtCost"); Literal litName = (Literal)e.Item.FindControl("litName"); litName.Text = litName.Text + " (chưa lưu)"; txtCost.Text = cost.Cost.ToString("#,0.#"); } } } } } }
protected void rptBalance_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Header) { return; } #region -- Lấy control -- Literal litIncome = (Literal)e.Item.FindControl("litIncome"); Literal litReceivable = (Literal)e.Item.FindControl("litReceivable"); Literal litExpense = (Literal)e.Item.FindControl("litExpense"); Literal litPayable = (Literal)e.Item.FindControl("litPayable"); Literal litBalance = (Literal)e.Item.FindControl("litBalance"); #endregion #region -- Footer -- if (e.Item.ItemType == ListItemType.Footer) { litIncome.Text = _income.ToString("#,0.#"); litReceivable.Text = _income.ToString("#,0.#"); litExpense.Text = _outcome.ToString("#,0.#"); litPayable.Text = _payable.ToString("#,0.#"); litBalance.Text = (_income - _outcome).ToString("#,0.#"); return; } #endregion Literal litDate = (Literal)e.Item.FindControl("litDate"); if (e.Item.DataItem is SailExpense) { SailExpense expense = (SailExpense)e.Item.DataItem; litDate.Text = expense.Date.ToString("dd/MM/yyyy"); #region -- Income -- IList bookings = Module.BookingGetByStartDate(expense.Date, ActiveCruise, true); double income = 0; double receivable = 0; foreach (Booking booking in bookings) { if (UseVNDExpense) { if (booking.IsPaid) { if (booking.CurrencyRate > 0) { income += booking.PaidBase + booking.Paid * booking.CurrencyRate; } else { income += booking.PaidBase + booking.Paid * _currentRate.Rate; } } else { if (booking.CurrencyRate > 0) { income += booking.Value; } else { income += booking.Value; } } } else { income += booking.Value; } receivable += booking.TotalReceivable; } litIncome.Text = income.ToString("#,0.#"); litReceivable.Text = receivable.ToString("#,0.#"); #endregion double outcome = 0; if (ActiveCruise != null) { outcome = GetOutcome(expense, bookings); } else { foreach (SailsTrip cruise in Module.TripGetAll(true, UserIdentity)) { SailExpense ex = Module.ExpenseGetByDate(cruise, expense.Date); outcome += GetOutcome(ex, bookings); } } litExpense.Text = outcome.ToString("#,0.#"); litBalance.Text = (income - outcome).ToString("#,0.#"); _income += income; _outcome += outcome; _receivable += receivable; } else if (e.Item.DataItem is int) { int month = (int)e.Item.DataItem; int year = Convert.ToInt32(txtYear.Text); DateTime dateFrom = new DateTime(year, month, 1); DateTime dateTo = dateFrom.AddMonths(1).AddDays(-1); litDate.Text = string.Format("{0:00}/{1:0000}", month, year); double income; double receivable; Module.IncomeSum(dateFrom, dateTo, out income, out receivable); litIncome.Text = income.ToString("#,0.#"); litReceivable.Text = receivable.ToString("#,0.#"); double outcome; double payable; Module.OutcomeSum(dateFrom, dateTo, out outcome, out payable); litExpense.Text = outcome.ToString("#,0.#"); litPayable.Text = payable.ToString("#,0.#"); litBalance.Text = (income - outcome).ToString("#,0.#"); _income += income; _outcome += outcome; _receivable += receivable; _payable += payable; } }
private double GetOutcome(SailExpense expense, IList bookings) { double outcome = 0; #region -- Cộng tổng từng service -- foreach (ExpenseService service in expense.Services) { try { if (service.Type.IsMonthly || service.Type.IsYearly) { continue; } } catch { continue; } outcome += service.Cost; } #endregion if (PeriodExpenseAvg) { #region -- Chi phí theo nam/thang -- // Nếu có chạy hoặc là tháng chưa kết thúc if (bookings.Count > 0 && expense.Date.Month + expense.Date.Year * 12 >= DateTime.Today.Month + DateTime.Today.Year * 12) { // Tính chi phí tháng DateTime dateMonth = new DateTime(expense.Date.Year, expense.Date.Month, 1); int runcount; // Nếu là tháng chưa kết thúc if (dateMonth.AddMonths(1) > DateTime.Today) { runcount = dateMonth.AddMonths(1).Subtract(dateMonth).Days; } else { //runcount = Module.RunningDayCount(ActiveCruise, expense.Date.Year, expense.Date.Month); } if (!_monthExpense.ContainsKey(dateMonth)) { //SailExpense monthExpense = Module.ExpenseGetByDate(ActiveCruise, dateMonth); //if (monthExpense.Id < 0) //{ // Module.SaveOrUpdate(monthExpense); //} //double total = Module.CopyMonthlyCost(monthExpense); //_monthExpense.Add(dateMonth, total/runcount); } outcome += _monthExpense[dateMonth]; } // Nếu có chạy hoặc năm chưa kết thúc if (bookings.Count > 0 && expense.Date.Year >= DateTime.Today.Year) { // Tính chi phí năm DateTime dateYear = new DateTime(expense.Date.Year, 1, 1); int runcount; // Nếu là năm chưa kết thúc if (dateYear.AddYears(1) > DateTime.Today) { runcount = dateYear.AddYears(1).Subtract(dateYear).Days; } else { //runcount = Module.RunningDayCount(ActiveCruise, expense.Date.Year, 0); } if (!_yearExpense.ContainsKey(dateYear)) { //SailExpense yearExpense = Module.ExpenseGetByDate(ActiveCruise, dateYear); //if (yearExpense.Id < 0) //{ // Module.SaveOrUpdate(yearExpense); //} //double total = Module.CopyYearlyCost(yearExpense); //_yearExpense.Add(dateYear, total/runcount); } outcome += _yearExpense[dateYear]; } #endregion } return(outcome); }
/// <summary> /// Tính toán chi phí cho repeater item lưu thông tin expense /// </summary> /// <param name="e"></param> /// <returns></returns> private SailExpense ExpenseCalculate(RepeaterItemEventArgs e) { #region -- Thông tin chung của expense -- SailExpense expense = (SailExpense)e.Item.DataItem; // Khi tính chi phí thì chỉ tính theo khách đã check-in ICriterion criterion = Expression.And(Expression.Eq("StartDate", expense.Date.Date), Expression.Eq("Status", StatusType.Approved)); // Bỏ deleted và cả transfer criterion = Expression.And(Expression.Eq("Deleted", false), criterion); criterion = Expression.And(Expression.Eq("IsTransferred", false), criterion); // Nếu là trang báo cáo chi phí từng tàu thì chỉ lấy theo tàu đó if (ActiveCruise != null) { criterion = Expression.And(criterion, Expression.Eq("Cruise", ActiveCruise)); } IList bookings = Module.BookingGetByCriterion(criterion, null, 0, 0); int adult = 0; int child = 0; //int baby = 0; foreach (Booking booking in bookings) { adult += booking.Adult; child += booking.Child; } _pax += adult + child; #endregion if (ActiveCruise != null) { GetCurrentCruiseTable(expense.Date, ActiveCruise); } _currentTotal = 0; // Tổng cho ngày hiện tại // Chi phí tháng/năm chỉ được tính vào chi phí ngày nếu cho phép tính trung bình if (PeriodExpenseAvg) { #region -- Chi phí tháng -- // Nếu là tính chi phí cho một tàu thì chia chi phí bình thường if (expense.Cruise != null) { // Nếu có chạy hoặc là tháng chưa kết thúc if (bookings.Count > 0 || expense.Date.Month + expense.Date.Year * 12 >= DateTime.Today.Month + DateTime.Today.Year * 12) { // Tính chi phí tháng Literal litMonth = e.Item.FindControl("litMonth") as Literal; if (litMonth != null) { DateTime dateMonth = new DateTime(expense.Date.Year, expense.Date.Month, 1); if (!_monthExpense.ContainsKey(dateMonth)) { int runcount; // Số ngày tàu chạy trong tháng, chỉ phục vụ việc tính chi phí trung bình // Không cần tính lại trong mỗi lần lặp // Nếu là tháng chưa kết thúc if (dateMonth.AddMonths(1) > DateTime.Today) { runcount = dateMonth.AddMonths(1).Subtract(dateMonth).Days; } else { runcount = Module.RunningDayCount(expense.Cruise, expense.Date.Year, expense.Date.Month); } SailExpense monthExpense = Module.ExpenseGetByDate(expense.Cruise, dateMonth); if (monthExpense.Id < 0) { Module.SaveOrUpdate(monthExpense); } double total = Module.CopyMonthlyCost(monthExpense); _monthExpense.Add(dateMonth, total / runcount); } litMonth.Text = _monthExpense[dateMonth].ToString("#,0.#"); _month += _monthExpense[dateMonth]; _currentTotal += _monthExpense[dateMonth]; } } } else // Nếu là tính chi phí tổng hợp thì tính cho tất cả các tàu rồi cộng lại { IList cruises = Module.CruiseGetAll(); double monthAll = 0; // tổng chi phí tháng trung bình foreach (Cruise cruise in cruises) { DateTime dateMonth = new DateTime(expense.Date.Year, expense.Date.Month, 1); // Nếu chưa có bảng chi phí cho tàu hiện tại if (!_monthExpenseCruise.ContainsKey(cruise)) { _monthExpenseCruise.Add(cruise, new Dictionary <DateTime, double>()); // Tạo một từ điển trắng để lưu dữ liệu } // Nếu chưa có chi phí của tàu hiện tại trong tháng hiện tại if (!_monthExpenseCruise[cruise].ContainsKey(dateMonth)) { int runcount; // Nếu là tháng chưa kết thúc if (dateMonth.AddMonths(1) > DateTime.Today) { runcount = dateMonth.AddMonths(1).Subtract(dateMonth).Days; } else { runcount = Module.RunningDayCount(cruise, expense.Date.Year, expense.Date.Month); } SailExpense monthExpense = Module.ExpenseGetByDate(cruise, dateMonth); if (monthExpense.Id < 0) { Module.SaveOrUpdate(monthExpense); } double total = Module.CopyMonthlyCost(monthExpense); _monthExpenseCruise[cruise].Add(dateMonth, total / runcount); } bool isRun = false; if (dateMonth.AddMonths(1) <= DateTime.Today) { foreach (Booking booking in bookings) { if (booking.Cruise == cruise) { isRun = true; break; } } } else { isRun = true; // Nếu là tháng chưa kết thúc thì mặc định là mọi ngày tàu đều chạy } if (isRun) { monthAll += _monthExpenseCruise[cruise][dateMonth]; // cộng thêm chi phí cho tàu này, ngày này khi tàu có chạy } } _month += monthAll; Literal litMonth = e.Item.FindControl("litMonth") as Literal; if (litMonth != null) { litMonth.Text = monthAll.ToString("#,0.#"); } } #endregion #region -- Chi phí năm -- if (expense.Cruise != null) { // Nếu có chạy hoặc năm chưa kết thúc if (bookings.Count > 0 || expense.Date.Year >= DateTime.Today.Year) { // Tính chi phí năm Literal litYear = e.Item.FindControl("litYear") as Literal; if (litYear != null) { DateTime dateYear = new DateTime(expense.Date.Year, 1, 1); int runcount; // Nếu là năm chưa kết thúc if (dateYear.AddYears(1) > DateTime.Today) { runcount = dateYear.AddYears(1).Subtract(dateYear).Days; } else { runcount = Module.RunningDayCount(expense.Cruise, expense.Date.Year, 0); } if (!_yearExpense.ContainsKey(dateYear)) { SailExpense yearExpense = Module.ExpenseGetByDate(expense.Cruise, dateYear); if (yearExpense.Id < 0) { Module.SaveOrUpdate(yearExpense); } double total = Module.CopyYearlyCost(yearExpense); _yearExpense.Add(dateYear, total / runcount); } litYear.Text = _yearExpense[dateYear].ToString("#,0.#"); _year += _yearExpense[dateYear]; _currentTotal += _yearExpense[dateYear]; } } } else { IList cruises = Module.CruiseGetAll(); double yearAll = 0; // tổng chi phí tháng trung bình foreach (Cruise cruise in cruises) { DateTime dateYear = new DateTime(expense.Date.Year, 1, 1); // Nếu chưa có bảng chi phí cho tàu hiện tại if (!_yearExpenseCruise.ContainsKey(cruise)) { _yearExpenseCruise.Add(cruise, new Dictionary <DateTime, double>()); // Tạo một từ điển trắng để lưu dữ liệu } // Nếu chưa có chi phí của tàu hiện tại trong năm hiện tại if (!_yearExpenseCruise[cruise].ContainsKey(dateYear)) { int runcount; // Nếu là năm chưa kết thúc if (dateYear.AddYears(1) > DateTime.Today) { runcount = dateYear.AddYears(1).Subtract(dateYear).Days; } else { runcount = Module.RunningDayCount(cruise, expense.Date.Year, 0); } SailExpense yearExpense = Module.ExpenseGetByDate(cruise, dateYear); if (yearExpense.Id < 0) { Module.SaveOrUpdate(yearExpense); } double total = Module.CopyYearlyCost(yearExpense); _yearExpenseCruise[cruise].Add(dateYear, total / runcount); } bool isRun = false; if (dateYear.AddYears(1) <= DateTime.Today) { foreach (Booking booking in bookings) { if (booking.Cruise == cruise) { isRun = true; break; } } } else { isRun = true; // Nếu là năm chưa kết thúc thì mặc định là mọi ngày tàu đều chạy } if (isRun) { yearAll += _yearExpenseCruise[cruise][dateYear]; // cộng thêm chi phí cho tàu này, ngày này khi tàu có chạy } } _year += yearAll; Literal litYear = e.Item.FindControl("litYear") as Literal; if (litYear != null) { litYear.Text = yearAll.ToString("#,0.#"); } } #endregion } if (_cruiseTable == null && ActiveCruise != null) { throw new Exception("Hai phong cruise price table is out of valid"); } // Lấy về bảng giá đã tính _currentCostMap = expense.Calculate(AllCostTypes, GetCurrentTable, GetCurrentDailyTable, GetCurrentCruiseTable, expense.Cruise, bookings, Module, PartnershipManager); return(expense); }
protected void GetDataSource() { try { // Ngày bắt đầu và ngày két thúc 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); } txtFrom.Text = from.ToString("dd/MM/yyyy"); txtTo.Text = to.ToString("dd/MM/yyyy"); if (to.Subtract(from).Days > 100) { throw new Exception("Kỳ hạn hiển thị quá dài, có thể gây quá tải hệ thống"); } IList list = Module.ExpenseGetByDate(ActiveCruise, from, to); // Bổ sung các ngày còn thiếu if (from <= to && (list.Count == 0 || list.Count < to.Subtract(from).Days + 1)) { IDictionary <DateTime, SailExpense> dic = new Dictionary <DateTime, SailExpense>(); foreach (SailExpense expense in list) { if (!dic.ContainsKey(expense.Date)) { dic.Add(expense.Date, expense); } } DateTime current; current = from; // Bắt đầu từ ngày đầu tiên while (current <= to) { if (!dic.ContainsKey(current)) { SailExpense expense = new SailExpense(); expense.Date = current; expense.Cruise = ActiveCruise; Module.SaveOrUpdate(expense); } current = current.AddDays(1); } //Cuối cùng refresh lại danh sách là xong list = Module.ExpenseGetByDate(ActiveCruise, from, to); } rptBookingList.DataSource = list; rptBookingList.DataBind(); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } ShowError(ex.Message); } }
protected virtual void rptBookingList_ItemDataBound(object sender, RepeaterItemEventArgs e) { Control ctrl = e.Item.FindControl("plhPeriodExpense"); if (ctrl != null) { ctrl.Visible = PeriodExpenseAvg; } if (e.Item.DataItem is SailExpense) { #region -- Tính toán chi phí & hiển thị -- SailExpense expense = ExpenseCalculate(e); Plus(_currentCostMap); // Cộng bảng chi phí #region -- Show info -- Repeater rptServices = (Repeater)e.Item.FindControl("rptServices"); rptServices.DataSource = AllCostTypes; rptServices.DataBind(); Literal litTotal = e.Item.FindControl("litTotal") as Literal; if (litTotal != null) { litTotal.Text = _currentTotal.ToString("#,0.#"); } HyperLink hplDate = e.Item.FindControl("hplDate") as HyperLink; if (hplDate != null) { hplDate.Text = expense.Date.ToString("dd/MM/yyyy"); } #endregion return; #endregion } #region -- Header -- if (e.Item.ItemType == ListItemType.Header) { Repeater rptServices = (Repeater)e.Item.FindControl("rptServices"); rptServices.DataSource = AllCostTypes; rptServices.DataBind(); } #endregion #region -- Footer -- if (e.Item.ItemType == ListItemType.Footer) { Repeater rptServices = (Repeater)e.Item.FindControl("rptServices"); rptServices.DataSource = AllCostTypes; rptServices.DataBind(); double total = 0; foreach (CostType type in AllCostTypes) { total += _grandTotal[type]; } total += _month; total += _year; Literal litMonth = e.Item.FindControl("litMonth") as Literal; if (litMonth != null) { litMonth.Text = _month.ToString("#,0.#"); } Literal litYear = e.Item.FindControl("litYear") as Literal; if (litYear != null) { litYear.Text = _year.ToString("#,0.#"); } Literal litTotal = e.Item.FindControl("litTotal") as Literal; if (litTotal != null) { litTotal.Text = total.ToString("#,0.#"); } } #endregion }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["sheetId"] != null) { _currentSheet = Module.AnswerSheetGetById(Convert.ToInt32(Request.QueryString["sheetId"])); } else { _currentSheet = new AnswerSheet(); } if (!IsPostBack) { rptGroups.DataSource = Module.QuestionGroupGetAll(); rptGroups.DataBind(); //ddlCruises.DataSource = Module.CruiseGetAll(); //ddlCruises.DataTextField = "Name"; //ddlCruises.DataValueField = "Id"; //ddlCruises.DataBind(); ddlNationalities.DataSource = Module.NationalityGetAll(); ddlNationalities.DataTextField = "Name"; ddlNationalities.DataValueField = "Id"; ddlNationalities.DataBind(); ddlNationalities.Items.Insert(0, "-- Not available --"); if (Request.QueryString["startdate"] != null) { DateTime date = DateTime.FromOADate(Convert.ToDouble(Request.QueryString["startdate"])); txtStartDate.Text = date.ToString("dd/MM/yyyy"); ddlBookings.DataSource = Module.BookingGetByStartDate(date, null, false); ddlBookings.DataTextField = "BookingIdOS"; ddlBookings.DataValueField = "Id"; ddlBookings.DataBind(); } else if (Request.QueryString["bookingid"] != null) { Booking booking = Module.BookingGetById(Convert.ToInt32(Request.QueryString["bookingid"])); ddlBookings.DataSource = Module.BookingGetByStartDate(booking.StartDate, null, false); ddlBookings.DataTextField = "BookingIdOS"; ddlBookings.DataValueField = "Id"; ddlBookings.DataBind(); ddlBookings.SelectedValue = booking.Id.ToString(); //ddlCruises.SelectedValue = booking.Cruise.Id.ToString(); _currentSheet.Booking = booking; txtStartDate.Text = booking.StartDate.ToString("dd/MM/yyyy"); } if (_currentSheet.Booking != null) { Booking booking = _currentSheet.Booking; SailExpense expense = Module.ExpenseGetByDate(booking.Trip, booking.StartDate); txtGuide.Visible = false; txtDriver.Visible = false; ddlGuide.Items.Clear(); ddlDrivers.Items.Clear(); foreach (ExpenseService sv in expense.Services) { if (sv.Type.Id == SailsModule.GUIDE_COST) { if (sv.Supplier != null) { ddlGuide.Items.Add(sv.Supplier.Name); } } if (sv.Type.Id == 19) { if (string.IsNullOrEmpty(sv.Name)) { if (sv.Supplier != null) { ddlDrivers.Items.Add(sv.Supplier.Name); } } else { ddlDrivers.Items.Add(sv.Name); } } } ddlGuide.Items.Insert(0, "-- Not specified --"); ddlDrivers.Items.Insert(0, "-- Not specified --"); } else { ddlGuide.Visible = false; ddlDrivers.Visible = false; } ddlBookings.Items.Insert(0, "-- Not available --"); if (_currentSheet.Id > 0) { if (_currentSheet.Booking != null) { ddlBookings.SelectedValue = _currentSheet.Booking.Id.ToString(); if (!string.IsNullOrEmpty(_currentSheet.Guide)) { ddlGuide.SelectedValue = _currentSheet.Guide; } if (!string.IsNullOrEmpty(_currentSheet.Driver)) { ddlDrivers.SelectedValue = _currentSheet.Driver; } } else { txtGuide.Text = _currentSheet.Guide; txtDriver.Text = _currentSheet.Driver; } if (_currentSheet.Nationality != null) { ddlNationalities.SelectedValue = _currentSheet.Nationality.Id.ToString(); } //ddlCruises.SelectedValue = _currentSheet.Cruise.Id.ToString(); if (_currentSheet.Date.HasValue) { txtStartDate.Text = _currentSheet.Date.Value.ToString("dd/MM/yyyy"); } txtName.Text = _currentSheet.Name; txtEmail.Text = _currentSheet.Email; txtAddress.Text = _currentSheet.Address; txtRoomNumber.Text = _currentSheet.RoomNumber; } } }
protected void rptMonthlyExpenses_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.DataItem is CostType) { CostType type = (CostType)e.Item.DataItem; #region -- Xét group -- if (!string.IsNullOrEmpty(type.GroupName) && _header.ToLower() != type.GroupName.ToLower()) { if (!string.IsNullOrEmpty(_header)) { e.Item.FindControl("plhGroupFooter").Visible = true; TextBox txtFooter = e.Item.FindControl("txtFooter") as TextBox; if (txtFooter != null) { txtFooter.Text = _footer.ToString("#,0.#"); } } _header = type.GroupName; e.Item.FindControl("plhGroupHeader").Visible = true; Literal litHeader = e.Item.FindControl("litHeader") as Literal; if (litHeader != null) { litHeader.Text = _header; } _footer = 0; } #endregion SailExpense expense = Module.ExpenseGetByDate(ActiveCruise, _date); #region -- Tính và hiển thị -- if (expense.Id < 0) { Module.SaveOrUpdate(expense); } else { IList costs = Module.ExpenseServiceGet(ActiveCruise, _date, _date, null, type); if (costs.Count > 0) { ExpenseService cost = costs[0] as ExpenseService; if (cost != null) { TextBox txtCost = (TextBox)e.Item.FindControl("txtCost"); TextBox txtDetail = (TextBox)e.Item.FindControl("txtDetail"); HiddenField hiddenId = (HiddenField)e.Item.FindControl("hiddenId"); hiddenId.Value = cost.Id.ToString(); txtCost.Text = cost.Cost.ToString("#,0.#"); _total += cost.Cost; _footer += cost.Cost; txtDetail.Text = cost.Name; } } else { IList lastCosts = Module.ExpenseServiceGet(ActiveCruise, _date.AddMonths(-1), _date.AddMonths(-1), null, type); if (lastCosts.Count > 0) { ExpenseService cost = lastCosts[0] as ExpenseService; if (cost != null) { TextBox txtCost = (TextBox)e.Item.FindControl("txtCost"); TextBox txtDetail = (TextBox)e.Item.FindControl("txtDetail"); Literal litName = (Literal)e.Item.FindControl("litName"); litName.Text = string.Format("{0} ({1})", litName.Text, Resources.textUnsaved); txtCost.Text = cost.Cost.ToString("#,0.#"); _total += cost.Cost; _footer += cost.Cost; txtDetail.Text = cost.Name; } } } } #endregion } else if (e.Item.ItemType == ListItemType.Footer) { TextBox txtFooter = e.Item.FindControl("txtFooter") as TextBox; if (txtFooter != null) { txtFooter.Text = _footer.ToString("#,0.#"); } TextBox txtTotal = e.Item.FindControl("txtTotal") as TextBox; if (txtTotal != null) { txtTotal.Text = _total.ToString("#,0.#"); } } }
public static void Export(IList list, int count, IList expenseList, DateTime _date, string bookingFormat, HttpResponse Response, string templatePath, SailsTrip trip, SailsAdminBasePage page) { SailsModule module = page.Module; // Bắt đầu thao tác export ExcelFile excelFile = new ExcelFile(); excelFile.LoadXls(templatePath); // Số lệnh điều tua = số lượng group int numberOfGroup = -1; foreach (Booking booking in list) { if (booking.Group > numberOfGroup) { numberOfGroup = booking.Group; } } foreach (ExpenseService service in expenseList) { if (service.Group > numberOfGroup) { numberOfGroup = service.Group; } } if (numberOfGroup <= 0) { numberOfGroup = 1; // Tối thiểu là 1 group } #region -- sheet 0: Lệnh điều tour -- for (int ii = 0; ii <= numberOfGroup; ii++) { // Mở sheet 0 ExcelWorksheet originSheet = excelFile.Worksheets[0]; int numberOfBooking = 0; foreach (Booking booking in list) { if (booking.Group == ii) { numberOfBooking++; } } if (numberOfBooking == 0 && ii == 0) { continue; } ExcelWorksheet sheet = excelFile.Worksheets.AddCopy("LenhDieuTour" + ii, originSheet); #region -- Thông tin chung -- if (expenseList != null) { // Các thông tin chèn thêm foreach (ExpenseService service in expenseList) { if (service.Group != ii) { continue; } switch (service.Type.Id) { case SailsModule.GUIDE_COST: if (service.Type.IsCustomType || service.Supplier == null) { if (string.IsNullOrEmpty(service.Name) && service.Supplier != null) { sheet.Cells["C3"].Value = service.Supplier.Name; } else { sheet.Cells["C3"].Value = service.Name; } if (string.IsNullOrEmpty(service.Name) && service.Supplier != null) { sheet.Cells["F3"].Value = service.Supplier.Phone; } else { sheet.Cells["F3"].Value = service.Phone; } } else { sheet.Cells["C3"].Value = service.Supplier.Name; sheet.Cells["f3"].Value = service.Supplier.Phone; } break; case SailsModule.TRANSPORT: if (service.Type.IsCustomType || service.Supplier == null) { if (string.IsNullOrEmpty(service.Name) && service.Supplier != null) { sheet.Cells["C4"].Value = service.Supplier.Name; } else { sheet.Cells["C4"].Value = service.Name; } if (string.IsNullOrEmpty(service.Name) && service.Supplier != null) { sheet.Cells["F4"].Value = service.Supplier.Phone; } else { sheet.Cells["F4"].Value = service.Phone; } } else { sheet.Cells["C4"].Value = service.Supplier.Name; sheet.Cells["f4"].Value = service.Supplier.Phone; } break; case SailsModule.HOTEL: if (service.Supplier != null) { sheet.Cells["C7"].Value = service.Supplier.Name; } else { sheet.Cells["C7"].Value = service.Name; } break; } } } sheet.Cells["D1"].Value = _date; // Tính tổng pax int adult = 0; int child = 0; int baby = 0; int pAdult = 0; int pChild = 0; int pBaby = 0; foreach (Booking booking in list) { if (booking.StartDate == _date && booking.Group == ii) { adult += booking.Adult; child += booking.Child; baby += booking.Baby; } else if (booking.Group == ii) { pAdult += booking.Adult; pChild += booking.Child; pBaby += booking.Baby; } } int pax = adult + child + pAdult + pChild; sheet.Cells["C5"].Value = page.UserIdentity.FullName; sheet.Cells["C6"].Value = pax; sheet.Cells["C12"].Value = adult; sheet.Cells["D12"].Value = child; sheet.Cells["E12"].Value = baby; sheet.Cells["C18"].Value = pAdult; sheet.Cells["D18"].Value = pChild; sheet.Cells["E18"].Value = pBaby; #endregion #region -- Sao chép các dòng -- // Sao chép dòng đầu theo số lượng booking // Dòng đầu tiên là dòng 11 const int firstrow = 10; // Đếm số book trong ngày int curr = 0; foreach (Booking booking in list) { if (booking.StartDate == _date && booking.Group == ii) { curr += 1; } } sheet.Rows[16].InsertCopy(count - curr - 1, sheet.Rows[firstrow]); if (curr > 0) { sheet.Rows[firstrow].InsertCopy(curr - 1, sheet.Rows[firstrow]); } int firstProw = 16 + curr; #endregion #region -- Thông tin từng booking -- // Ghi vào file excel theo từng dòng int crow = firstrow; int cProw = firstProw - 1; foreach (Booking booking in list) { if (booking.Group != ii) { continue; } sheet.Cells["D2"].Value = string.Format("{0}{1:ddMMyy}-{2:00}", booking.Trip.TripCode, booking.StartDate, booking.Group); int current; int index; if (booking.StartDate != _date) { // Dòng previous hiện tại current = cProw; // Index = cột previous hiện tại - previous đầu tiên index = cProw - firstProw + 2; cProw++; } else { current = crow; index = crow - firstrow + 1; crow++; } sheet.Cells[current, 0].Value = index; // Cột index string name = booking.CustomerName.Replace("<br/>", "\n"); if (name.Length > 0) { name = name.Remove(name.Length - 1); } sheet.Cells[current, 1].Value = name; // Cột name sheet.Cells[current, 2].Value = booking.Adult; // Cột adult sheet.Cells[current, 3].Value = booking.Child; // Cột child sheet.Cells[current, 4].Value = booking.Baby; // Cột baby sheet.Cells[current, 5].Value = booking.Trip.TripCode; // Cột trip code sheet.Cells[current, 6].Value = booking.PickupAddress; // Cột pickup address sheet.Cells[current, 7].Value = booking.SpecialRequest; // Cột special request sheet.Cells[current, 9].Style.Borders.SetBorders(MultipleBorders.Outside, System.Drawing.Color.Black, LineStyle.Thin); if (booking.Agency != null) { sheet.Cells[current, 8].Value = booking.Agency.Name; // Cột agency if (!string.IsNullOrEmpty(booking.AgencyCode)) { sheet.Cells[current, 9].Value = booking.AgencyCode; // Chỉ hiển thị nếu có agency (cột TA COde) } else { if (booking.CustomBookingId > 0) { sheet.Cells[current, 9].Value = string.Format(bookingFormat, booking.CustomBookingId); } else { sheet.Cells[current, 9].Value = string.Format(bookingFormat, booking.Id); } } } else { sheet.Cells[current, 8].Value = SailsModule.NOAGENCY; // Hiển thị oriental nếu ko có agency if (booking.CustomBookingId > 0) { sheet.Cells[current, 9].Value = string.Format(bookingFormat, booking.CustomBookingId); } else { sheet.Cells[current, 9].Value = string.Format(bookingFormat, booking.Id); } } if (booking.PickupTime != null) { sheet.Cells[current, 10].Value = booking.PickupTime.Value.ToString("HH:mm"); } if (booking.SeeoffTime != null) { sheet.Cells[current, 11].Value = booking.SeeoffTime.Value.ToString("HH:mm"); } if (trip.Name.ToLower() != "airport transfer") { sheet.Columns[11].Delete(); } if (trip.Name.ToLower() != "airport transfer") { sheet.Columns[10].Delete(); } } #endregion // Mở sheet 1 originSheet = excelFile.Worksheets[1]; ExcelWorksheet budget = excelFile.Worksheets.AddCopy("Budget" + ii, originSheet); budget.Cells["C3"].Value = sheet.Cells["C3"].Value; budget.Cells["C4"].Value = sheet.Cells["C4"].Value; budget.Cells["A1"].Value = sheet.Cells["D1"].Value; budget.Cells["C5"].Value = page.UserIdentity.FullName; budget.Cells["C6"].Value = sheet.Cells["C6"].Value; budget.Cells["A1"].Value = string.Format("{0}{1:ddMMyyyy}", trip.TripCode, _date); // Các chi phí xuất ra bao gồm chi phí theo ngày và chi phí theo khách ExpenseCalculator calculator = new ExpenseCalculator(module, true); SailExpense expense = module.ExpenseGetByDate(trip, _date); IList expenses = module.ExpenseServiceGet(trip, _date, _date, null, null, null, null, false, null, 0, ""); CostingTable cost = calculator.GetCurrentTable(_date, trip, TripOption.Option1); IList costTypes = new ArrayList(); foreach (KeyValuePair <CostType, double> entry in module.CostTypeGetAutoDailyBase()) { costTypes.Add(entry.Key); } Dictionary <CostType, Costing> unitPrices = cost.GetCostMap(costTypes); const int first = 8; curr = first; foreach (ExpenseService entry in expenses) { if (entry.Group != ii) { continue; } if (entry.Type.IsPayNow) { if (entry.Type.IsDailyInput)// Nếu là chi phí nhập tay { if (entry.Cost == 0) { continue; } budget.Rows[curr].InsertCopy(1, budget.Rows[curr]); budget.Cells[curr, 0].Value = curr - first + 1; budget.Cells[curr, 1].Value = _date; if (entry.Type.Name.ToLower().Contains("others")) { budget.Cells[curr, 2].Value = entry.Name; } else { budget.Cells[curr, 2].Value = entry.Type.Name; } budget.Cells[curr, 3].Value = entry.Cost; // chi phí dành cho cả đoàn budget.Cells[curr, 4].Value = entry.Cost; curr++; } else if (!entry.Type.IsMonthly && !entry.Type.IsYearly) { double value = unitPrices[entry.Type].Adult * adult; if (value > 0) { budget.Rows[curr].InsertCopy(1, budget.Rows[curr]); budget.Cells[curr, 0].Value = curr - first + 1; budget.Cells[curr, 1].Value = _date; budget.Cells[curr, 2].Value = entry.Type.Name + " (adult)"; budget.Cells[curr, 3].Value = unitPrices[entry.Type].Adult; // giá adult budget.Cells[curr, 4].Value = value; curr++; } value = unitPrices[entry.Type].Child * child; if (value > 0) { budget.Rows[curr].InsertCopy(1, budget.Rows[curr]); budget.Cells[curr, 0].Value = curr - first + 1; budget.Cells[curr, 1].Value = _date; budget.Cells[curr, 2].Value = entry.Type.Name + " (child)"; budget.Cells[curr, 3].Value = unitPrices[entry.Type].Child; // giá adult budget.Cells[curr, 4].Value = value; curr++; } value = unitPrices[entry.Type].Baby * baby; if (value > 0) { budget.Rows[curr].InsertCopy(1, budget.Rows[curr]); budget.Cells[curr, 0].Value = curr - first + 1; budget.Cells[curr, 1].Value = _date; budget.Cells[curr, 2].Value = entry.Type.Name + " (baby)"; budget.Cells[curr, 3].Value = unitPrices[entry.Type].Baby; // giá adult budget.Cells[curr, 4].Value = value; curr++; } } } } } #endregion #region -- sheet 1: //if (excelFile.Worksheets.Count == 1) //{ // goto end; //} //ExcelWorksheet budget = excelFile.Worksheets[1]; #endregion end: #region -- Trả dữ liệu về cho người dùng -- Response.Clear(); Response.Buffer = true; Response.ContentType = "application/vnd.ms-excel"; Response.AppendHeader("content-disposition", "attachment; filename=" + string.Format("Lenhdieutour{0:dd_MMM}.xls", _date)); MemoryStream m = new MemoryStream(); excelFile.SaveXls(m); Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); m.Close(); Response.End(); #endregion }