Ejemplo n.º 1
0
        public string Guide_AgencyGetAllByRole(string d, string ri, string w)
        {
            DateTime?date = null;

            try
            {
                date = DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            catch { }
            var routeId = -1;

            try
            {
                routeId = Int32.Parse(ri);
            }
            catch { }
            var way            = w;
            var route          = TransferRequestByDateBLL.RouteGetById(routeId);
            var role           = TransferRequestByDateBLL.RoleGetByName("Guides");
            var listGuide      = TransferRequestByDateBLL.AgencyGetAllByRole(role).Future().ToList();
            var listGuideInDay = TransferRequestByDateBLL.Guide_AgencyGetAllGuideInDay(role, date, route).Future().ToList();
            var listGuideDTO   = new List <AgencyDTO>();

            listGuide.ForEach(guide =>
            {
                var guideInDay            = listGuideInDay.Where(x => x.Id == guide.Id).FirstOrDefault();
                Expense guideExpenseInDay = null;
                if (guideInDay != null)
                {
                    guideExpenseInDay = TransferRequestByDateBLL.ExpenseGetAllByCriterion(guide, date, route)
                                        .Future().SingleOrDefault();
                }
                var guideDTO = new AgencyDTO()
                {
                    Id    = guide.Id,
                    Name  = guideExpenseInDay != null ? guideExpenseInDay.Guide.Name + " - " + guideExpenseInDay.Cruise.Code : guide.Name,
                    Group = guideInDay != null ? "Guide in day" : null,
                };
                listGuideDTO.Add(guideDTO);
            });
            if (way == "Back")
            {
                var listGuideDayBefore = TransferRequestByDateBLL.Guide_AgencyGetAllGuideInDay(role, date.Value.AddDays(-1), route).Future().ToList();
                listGuideDayBefore.ForEach(guideDayBefore =>
                {
                    var guideDTO = new AgencyDTO()
                    {
                        Id    = guideDayBefore.Id,
                        Name  = guideDayBefore.Name,
                        Group = guideDayBefore != null ? "Guide day before" : null,
                    };
                    listGuideDTO.Add(guideDTO);
                });
            }
            Dispose();
            return(JsonConvert.SerializeObject(listGuideDTO));
        }
Ejemplo n.º 2
0
        public void SaveDriverExpense()
        {
            var driverCost = 0.0;

            try
            {
                driverCost = Double.Parse(txtDriverCost.Text);
            }
            catch { }
            var driverExpenseId = -1;

            try
            {
                driverExpenseId = Int32.Parse(hidExpenseDriverId.Value);
            }
            catch { }
            var driverExpense = TransferRequestByDateBLL.ExpenseGetById(driverExpenseId);

            if (driverExpense == null)
            {
                driverExpense = new Expense();
            }
            driverExpense.BusByDate = BusByDate;
            driverExpense.Name      = txtDriverName.Text;
            driverExpense.Phone     = txtDriverPhone.Text;
            driverExpense.Cost      = driverCost;
            driverExpense.Type      = "Drivers";
            driverExpense.Date      = Date.HasValue ? Date.Value : DateTime.Today;
            TransferRequestByDateBLL.ExpenseSaveOrUpdate(driverExpense);
            var expenseService = TransferRequestByDateBLL.ExpenseServiceGetByExpenseId(driverExpenseId);

            if (expenseService == null)
            {
                expenseService = new ExpenseService();
            }
            var listCostType    = TransferRequestByDateBLL.CostTypeGetAll().Future().ToList();
            var expenseTypeNull = TransferRequestByDateBLL.ExpenseGetAllByCriterion(BusByDate.Date).Where(z => z.Type == null).FutureValue().Value;

            expenseService.Cost         = driverExpense.Cost;
            expenseService.Name         = driverExpense.BusByDate != null ? driverExpense.BusByDate.Driver_Name : "";
            expenseService.Type         = listCostType.Where(z => z.Name == "Driver").FirstOrDefault();
            expenseService.Expense      = expenseTypeNull;
            expenseService.ExpenseIdRef = driverExpense.Id;
            TransferRequestByDateBLL.ExpenseServiceSaveOrUpdate(expenseService);
            BusByDate.Driver_Name  = txtDriverName.Text;
            BusByDate.Driver_Phone = txtDriverPhone.Text;
            TransferRequestByDateBLL.BusByDateSaveOrUpdate(BusByDate);
        }
Ejemplo n.º 3
0
        public void ExportTour(ExcelPackage excelPackage, BusByDate busByDate)
        {
            var listBookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(busByDate).Future().ToList();
            var listBooking          = listBookingBusByDate.Select(x => x.Booking).ToList();
            var listCustomer         = listBooking.SelectMany(x => x.Customers).ToList();
            var shortRouteName       = StringUtil.GetFirstLetter(busByDate.Route.Name);
            var sheet = excelPackage.Workbook.Worksheets.Copy("Tour Command", "TC" + "-"
                                                              + shortRouteName.Replace(" ", "").Replace("-", "_") + "-" + busByDate.BusType.Name + "-G" + busByDate.Group);

            sheet.Cells["I1"].Value = "Group " + busByDate.Group;
            sheet.Cells["E1"].Value = (busByDate.Date.HasValue ? busByDate.Date.Value.ToLongDateString() : "");
            //Điền guide vào lệnh điều tour
            var startRow         = 3;
            var currentRow       = startRow;
            var templateGuideRow = currentRow;
            var listGuide        = busByDate.BusByDatesGuides.Where(x => x.Guide != null).Select(x => x.Guide).ToList();

            sheet.InsertRow(currentRow, listGuide.Count - 1, templateGuideRow);
            FillGuide(listGuide, sheet, ref currentRow);
            //--
            //Điền driver vào lệnh điều tour
            var templateDriverRow = currentRow;
            var listBusByDate     = new List <BusByDate>();

            listBusByDate.Add(busByDate);
            sheet.InsertRow(currentRow, listBusByDate.Count - 1, templateDriverRow);
            FillDriver(listBusByDate, sheet, ref currentRow);
            //--
            //Điền opt vào lệnh điều tour
            var listGuideExpense = new List <Expense>();

            foreach (var guide in listGuide)
            {
                var guideExpense = TransferRequestByDateBLL.ExpenseGetAllByCriterion(guide, busByDate.Date, busByDate.Route)
                                   .Future().ToList().FirstOrDefault();
                if (guideExpense != null)
                {
                    listGuideExpense.Add(guideExpense);
                }
            }
            var templateOptRow = currentRow;
            //Lấy danh sách opt
            var listOpt          = listGuideExpense.Select(x => x.Operator);
            var listOpt_Distinct = listOpt.Distinct().DefaultIfEmpty(new User()).ToList();//Lấy danh sách Opt không lặp

            sheet.InsertRow(currentRow, listOpt_Distinct.Count - 1, templateOptRow);
            FillOpt(listOpt_Distinct, sheet, ref currentRow);
            //--
            //Export booking trong ngày
            currentRow = currentRow + 2;//Chuyển current row đến templaterow booking
            int templateRow = currentRow;
            int totalRow    = templateRow + listBooking.Count();
            int index       = 1;

            currentRow++;//Chuyển current row đến trước template row để bắt đầu coppyrow
            sheet.InsertRow(currentRow, listBooking.Count, templateRow);
            for (int i = 0; i < listBooking.Count; i++)
            {
                var booking = listBooking[i] as Booking;
                if (booking != null)
                {
                    var name = booking.CustomerNameFull.Replace("<br/>", "\r\n").ToUpper();
                    sheet.Cells[currentRow, 1].Value = index;
                    sheet.Cells[currentRow, 2, currentRow, 3].Merge = true;
                    sheet.Cells[currentRow, 2].Value  = name;
                    sheet.Cells[currentRow, 4].Value  = booking.Adult;
                    sheet.Cells[currentRow, 5].Value  = booking.Child;
                    sheet.Cells[currentRow, 6].Value  = booking.Baby;
                    sheet.Cells[currentRow, 7].Value  = booking.Trip.TripCode;
                    sheet.Cells[currentRow, 8].Value  = booking.PickupAddress;
                    sheet.Cells[currentRow, 9].Value  = booking.SpecialRequest;
                    sheet.Cells[currentRow, 11].Value = "OS" + booking.Id;
                    sheet.Cells[currentRow, 26].Value = name;//Work around cho cột merged name không hiển thị hết khi nội dung quá dài
                    currentRow++;
                    index++;
                }
            }
            sheet.DeleteRow(templateRow);
            sheet.Cells[totalRow, 4].Value = listBooking.Sum(x => x.Adult);
            sheet.Cells[totalRow, 5].Value = listBooking.Sum(x => x.Child);
            sheet.Cells[totalRow, 6].Value = listBooking.Sum(x => x.Baby);
            sheet.Cells["I3"].Value        = "Total number of pax: " + (listBooking.Sum(x => x.Adult) + listBooking.Sum(x => x.Child));
            //--
        }