Esempio n. 1
0
        public IEnumerable <TruckViewModel> GetTruckForAutosuggestByType(string value, string type)
        {
            var truck = from a in _truckRepository.GetAllQueryable()
                        join b in _driverRepository.GetAllQueryable() on new { a.DriverC }
            equals new { b.DriverC } into t1
            from b in t1.DefaultIfEmpty()
            join c in _partnerRepository.GetAllQueryable() on new { a.PartnerMainC, a.PartnerSubC }
            equals new { c.PartnerMainC, c.PartnerSubC } into t2
            from c in t2.DefaultIfEmpty()
            where ((a.TruckC.Contains(value) || a.RegisteredNo.Contains(value)) &&
                   a.PartnerI == type && a.IsActive == "1"
                   )
            select new TruckViewModel()
            {
                TruckC       = a.TruckC,
                RegisteredNo = a.RegisteredNo,
                RegisteredD  = a.RegisteredD,
                DepC         = a.DepC,
                DriverC      = a.DriverC,
                DriverN      = b != null ? b.LastN + " " + b.FirstN : "",
                DriverFirstN = b != null ? b.FirstN : "",
                PartnerMainC = a.PartnerMainC,
                PartnerSubC  = a.PartnerSubC,
                PartnerN     = c != null ? c.PartnerN : "",
                AssistantC   = a.AssistantC,
                AssistantN   = ""
            };

            truck = truck.OrderBy("RegisteredNo asc");
            var truckList = truck.ToList();
            var count     = truckList.Count;

            for (var i = 0; i < count; i++)
            {
                string assC   = truckList[i].AssistantC;
                var    driver = _driverRepository.Query(p => p.DriverC == assC).FirstOrDefault();
                truckList[i].AssistantN = driver != null ? driver.LastN + " " + driver.FirstN : "";
            }
            return(truckList);
        }
Esempio n. 2
0
        public List <GpsViewModel> GetGpsLocationList()
        {
            var dt         = new DateTime(2018, 08, 01);
            var today      = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            var listDriver = _driverRepository.GetAllQueryable().ToList();
            var listTruck  = _truckRepository.GetAllQueryable().ToList();
            var listAllGps = _gpsLocationRepository.GetAllQueryable().ToList();
            var listGps    = (from driver in listDriver
                              join gps in listAllGps on driver.DriverC equals gps.DriverC
                              into o
                              from gps in o.DefaultIfEmpty()
                              join dispatch in _dispatchRepository.GetAllQueryable() on driver.DriverC equals dispatch.DriverC
                              where driver.IsActive == Constants.ACTIVE && dispatch.DispatchStatus == Constants.DISPATCH &&
                              (dispatch.TransportD != null && dispatch.TransportD <= today) &&
                              (((dispatch.Location1DT != null && dispatch.Location1DT >= today) || (dispatch.Location1DT == null && ((dispatch.Location2DT != null && dispatch.Location2DT >= today) || (dispatch.Location3DT != null && dispatch.Location3DT >= today)))) ||
                               ((dispatch.Location2DT != null && dispatch.Location2DT >= today) || (dispatch.Location2DT == null && ((dispatch.Location1DT != null && dispatch.Location1DT >= today) || (dispatch.Location3DT != null && dispatch.Location3DT >= today)))) ||
                               ((dispatch.Location3DT != null && dispatch.Location3DT >= today) || (dispatch.Location3DT == null && ((dispatch.Location2DT != null && dispatch.Location2DT >= today) || (dispatch.Location1DT != null && dispatch.Location1DT >= today)))) ||
                               ((dispatch.Location1DT == null && (string.IsNullOrEmpty(dispatch.Operation1C) || dispatch.Operation1C == "0")) && (dispatch.Location2DT == null && (string.IsNullOrEmpty(dispatch.Operation2C) || dispatch.Operation2C == "0")) && (dispatch.Location3DT == null && (string.IsNullOrEmpty(dispatch.Operation3C) || dispatch.Operation3C == "0"))))
                              select new GpsViewModel()
            {
                DriverC = driver.DriverC,
                FirstN = driver.FirstN,
                LastN = driver.LastN,
                PhoneNumber = driver.PhoneNumber,
                Latitude = (gps != null) ? gps.Latitude : 0,
                Longitude = (gps != null) ? gps.Longitude : 0,
                UpdateD = (gps != null) ? gps.UpdateD : DateTime.Now,
                DriverDispatch = dispatch,
                IsTruckEmpty = (dispatch != null) ? 3 : 2,
                IsTruckGoBack = (dispatch != null) ? 3 : 2
            }).ToList();
            var joinByTruck = (from truck in listTruck
                               join gps in listGps on truck.TruckC equals gps.DriverDispatch.TruckC
                               into o
                               from gps in o.DefaultIfEmpty()
                               where truck.IsActive == Constants.ACTIVE
                               select new GpsViewModel()
            {
                DriverC = (gps != null) ? gps.DriverC : (truck.DriverC ?? ""),
                FirstN = (gps != null) ? gps.FirstN : "",
                LastN = (gps != null) ? gps.LastN : "",
                RegisteredNo = truck.RegisteredNo ?? "",
                TruckC = truck.TruckC ?? "",
                DepC = truck.DepC ?? "",
                GrossWeight = truck.GrossWeight ?? 0,
                ModelC = truck.ModelC ?? "",
                PhoneNumber = (gps != null) ? gps.PhoneNumber : "",
                Latitude = (gps != null) ? gps.Latitude : 0,
                Longitude = (gps != null) ? gps.Longitude : 0,
                UpdateD = (gps != null) ? gps.UpdateD : null,
                IsDriverDefault = (gps != null) ? 0 : 1,
                DispatchStatus = (gps != null) ? 1 : 0,
                DriverDispatch = (gps != null) ? gps.DriverDispatch : null,
                IsTruckEmpty = (gps != null) ? gps.IsTruckEmpty : 3,
                IsTruckGoBack = (gps != null) ? gps.IsTruckGoBack : 3
            }).ToList();
            //Group by DriverC
            var groupByTruck = (from p in joinByTruck
                                group p by new
            {
                p.DriverC,
                p.FirstN,
                p.LastN,
                p.TruckC,
                p.DepC,
                p.GrossWeight,
                p.ModelC,
                p.RegisteredNo,
                p.PhoneNumber,
                p.Latitude,
                p.Longitude,
                p.UpdateD,
                p.DispatchStatus,
                p.IsDriverDefault,
                p.IsTruckEmpty,
                p.IsTruckGoBack
            } into g
                                select new GpsViewModel()
            {
                DriverC = g.Key.DriverC,
                FirstN = g.Key.FirstN,
                LastN = g.Key.LastN,
                RegisteredNo = g.Key.RegisteredNo,
                TruckC = g.Key.TruckC,
                DepC = g.Key.DepC,
                GrossWeight = g.Key.GrossWeight,
                ModelC = g.Key.ModelC,
                PhoneNumber = g.Key.PhoneNumber,
                Latitude = g.Key.Latitude,
                Longitude = g.Key.Longitude,
                UpdateD = g.Key.UpdateD,
                IsDriverDefault = g.Key.IsDriverDefault,
                DispatchStatus = g.Key.DispatchStatus,
                TargetDispatch = g.ToList().Count,
                ListDispatchViewModels = g.ToList(),
                IsTruckEmpty = g.Key.IsTruckEmpty,
                IsTruckGoBack = g.Key.IsTruckGoBack
            }).ToList();
            var listModel = _modelRepository.GetAllQueryable().ToList();
            var listDep   = _departmentRepository.GetAllQueryable().ToList();

            //Find target dispatch of array dispatch for display in screen
            foreach (var item in groupByTruck)
            {
                if (!string.IsNullOrEmpty(item.DepC))
                {
                    var dep = listDep.FirstOrDefault(d => d.DepC.Equals(item.DepC));
                    if (dep != null)
                    {
                        item.DepName = dep.DepN ?? "";
                    }
                }
                if (!string.IsNullOrEmpty(item.ModelC))
                {
                    var model = listModel.FirstOrDefault(m => m.ModelC == item.ModelC);
                    if (model != null)
                    {
                        item.ModelName = model.ModelN ?? "";
                    }
                }
                var gpsViewModel = item.ListDispatchViewModels.FirstOrDefault();
                if (gpsViewModel != null)
                {
                    var dispatch = gpsViewModel.DriverDispatch;
                    if (dispatch != null)
                    {
                        item.IsTruckGoBack = checkGoBack(dispatch.ContainerStatus);
                        switch (numTransportPassed(dispatch))
                        {
                        case 0:
                        {
                            item.IsTruckEmpty = 0;
                        } break;

                        case 1:
                        {
                            item.IsTruckEmpty = checkTruckEmpty(dispatch.Operation1C, dispatch.Operation2C);
                        } break;

                        case 2:
                        {
                            item.IsTruckEmpty = checkTruckEmpty(dispatch.Operation2C, dispatch.Operation3C);
                        } break;

                        default:
                            item.IsTruckEmpty = 2;
                            break;
                        }
                    }
                }

                if (item.IsDriverDefault == 1 && item.DriverC != "")
                {
                    var driver = listDriver.FirstOrDefault(d => d.DriverC == item.DriverC);
                    if (driver != null)
                    {
                        item.FirstN = driver.FirstN;
                        item.LastN  = driver.LastN;
                    }
                }
                if (item.Longitude == 0 && item.Latitude == 0)
                {
                    var findDriver = listAllGps.FirstOrDefault(d => d.DriverC.Equals(item.DriverC));
                    if (findDriver != null)
                    {
                        item.Latitude  = findDriver.Latitude;
                        item.Longitude = findDriver.Longitude;
                        item.UpdateD   = findDriver.UpdateD;
                    }
                }
                if (item.ListDispatchViewModels.ToArray()[0].DriverDispatch != null)
                {
                    var firstOrDefault = listTruck.FirstOrDefault(c => c.TruckC.Equals(item.ListDispatchViewModels.ToArray()[0].DriverDispatch.TruckC));
                    //1 item
                    if (item.TargetDispatch == 1)
                    {
                        if (firstOrDefault != null)
                        {
                            item.RegisteredNo   = firstOrDefault.RegisteredNo;
                            item.TruckC         = firstOrDefault.TruckC;
                            item.TargetDispatch = 0;
                        }
                    }
                    else
                    {
                        if (item.TargetDispatch != 0)
                        {
                            var list = item.ListDispatchViewModels.OrderBy(x => x.DriverDispatch.DispatchOrder).ToList();
                            //Utilities.Switch(list, indexOfDispatch, 0);
                            item.ListDispatchViewModels = list;
                            var custom = listTruck.FirstOrDefault(c => c.TruckC.Equals(item.ListDispatchViewModels.ToArray()[0].DriverDispatch.TruckC));
                            if (custom != null)
                            {
                                item.RegisteredNo   = custom.RegisteredNo;
                                item.TruckC         = custom.TruckC;
                                item.TargetDispatch = 0;
                            }
                            #region an code tam
                            ////find dispatch status = 1
                            //var isNotDefaultDispatch = false;
                            //foreach (var dispatch in item.ListDispatchViewModels)
                            //{
                            //    if (dispatch.DriverDispatch.DispatchStatus == Constants.DISPATCH)
                            //    {
                            //        var indexOfDispatch = item.ListDispatchViewModels.IndexOf(dispatch);
                            //        //move to index = 0
                            //        if (indexOfDispatch != 0)
                            //        {
                            //            var list = item.ListDispatchViewModels.OrderBy(x=>x.DriverDispatch.DispatchOrder).ToList();
                            //            //Utilities.Switch(list, indexOfDispatch, 0);
                            //            item.ListDispatchViewModels = list;
                            //            var custom = listTruck.FirstOrDefault(c => c.TruckC.Equals(item.ListDispatchViewModels.ToArray()[0].DriverDispatch.TruckC));
                            //            if (custom != null)
                            //            {
                            //                item.RegisteredNo = custom.RegisteredNo;
                            //                item.TruckC = custom.TruckC;
                            //                item.TargetDispatch = 0;
                            //            }
                            //            isNotDefaultDispatch = true;
                            //            break;
                            //        }
                            //    }

                            //}
                            //if (!isNotDefaultDispatch)
                            //{
                            //    if (firstOrDefault != null)
                            //    {
                            //        item.RegisteredNo = firstOrDefault.RegisteredNo;
                            //        item.TruckC = firstOrDefault.TruckC;
                            //        item.TargetDispatch = 0;
                            //    }
                            //}
                            #endregion
                        }
                        else
                        {
                            item.TargetDispatch = 0;
                        }
                    }
                }
            }

            return(groupByTruck);
        }
Esempio n. 3
0
        public TruckExpenseDatatables GetTruckExpensesForTable(TruckExpenseSearchParams searchInfo)
        {
            var truckExpense = (from a in _truckExpenseRepository.GetAllQueryable()
                                join b in _truckRepository.GetAllQueryable() on a.Code
                                equals b.TruckC into t1
                                join f in _trailerRepository.GetAllQueryable() on a.Code
                                equals f.TrailerC into t6
                                from f in t6.DefaultIfEmpty()
                                from b in t1.DefaultIfEmpty()
                                join c in _expenseRepository.GetAllQueryable() on new { a.ExpenseC }
                                equals new { c.ExpenseC } into t2
                                from c in t2.DefaultIfEmpty()
                                join d in _driverRepository.GetAllQueryable() on new { a.DriverC }
                                equals new { d.DriverC } into t3
                                from d in t3.DefaultIfEmpty()
                                join e in _supplierRepository.GetAllQueryable() on new { a.SupplierMainC, a.SupplierSubC }
                                equals new { e.SupplierMainC, e.SupplierSubC } into t4
                                from e in t4.DefaultIfEmpty()
                                join t in _employeeRepository.GetAllQueryable() on a.EntryClerkC equals t.EmployeeC into t5
                                from t in t5.DefaultIfEmpty()
                                where (((searchInfo.ParamSearch.InvoiceDEnd == null || a.InvoiceD <= searchInfo.ParamSearch.InvoiceDEnd) &&
                                        (searchInfo.ParamSearch.InvoiceDStart == null || a.InvoiceD >= searchInfo.ParamSearch.InvoiceDStart)) &
                                       ((searchInfo.ParamSearch.TransportDEnd == null || a.TransportD <= searchInfo.ParamSearch.TransportDEnd) &&
                                        (searchInfo.ParamSearch.TransportDStart == null || a.TransportD >= searchInfo.ParamSearch.TransportDStart)) &
                                       (String.IsNullOrEmpty(searchInfo.ParamSearch.ExpenseC) || a.ExpenseC == searchInfo.ParamSearch.ExpenseC) &
                                       (String.IsNullOrEmpty(searchInfo.ParamSearch.SupplierMainC) || (a.SupplierMainC == searchInfo.ParamSearch.SupplierMainC && a.SupplierSubC == searchInfo.ParamSearch.SupplierSubC)) &
                                       (                                   //searchInfo.ParamSearch.ObjectI != "C" &&
                                           (                               //((String.IsNullOrEmpty(searchInfo.ParamSearch.Code) || a.Code == searchInfo.ParamSearch.Code)) ||
                                               (searchInfo.ParamSearch.ObjectI == "1" && searchInfo.ParamSearch.ObjectI == a.ObjectI && (String.IsNullOrEmpty(searchInfo.ParamSearch.Code) || searchInfo.ParamSearch.Code == f.TrailerC)) ||
                                               (searchInfo.ParamSearch.ObjectI == "0" && searchInfo.ParamSearch.ObjectI == a.ObjectI && (String.IsNullOrEmpty(searchInfo.ParamSearch.Code) || searchInfo.ParamSearch.Code == b.TruckC)))))
                                select new TruckExpenseViewModel()
            {
                Id = a.Id,
                InvoiceD = a.InvoiceD,
                TransportD = a.TransportD,
                ExpenseC = a.ExpenseC,
                ExpenseN = c.ExpenseN,
                EntryClerkC = a.EntryClerkC,
                EntryClerkN = t != null ? (t.EmployeeLastN + " " + t.EmployeeFirstN) : "",
                DriverC = a.DriverC,
                DriverN = d != null ? d.LastN + " " + d.FirstN : "",
                PaymentMethodI = a.PaymentMethodI,
                SupplierMainC = a.SupplierMainC,
                SupplierSubC = a.SupplierSubC,
                SupplierN = e.SupplierN,
                Quantity = a.Quantity,
                UnitPrice = a.UnitPrice,
                Total = a.Total + a.Tax,
                Tax = a.Tax,
                Description = a.Description,
                ObjectNo = a.ObjectI == "0" ? b.RegisteredNo : f.TrailerNo,
                ObjectI = a.ObjectI,
                ExpenseI = "T",
            }).ToList();
            var companyExpense = (from a in _companyExpenseRepository.GetAllQueryable()
                                  join c in _expenseRepository.GetAllQueryable() on new { a.ExpenseC }
                                  equals new { c.ExpenseC } into t1
                                  from c in t1.DefaultIfEmpty()
                                  join e in _supplierRepository.GetAllQueryable() on new { a.SupplierMainC, a.SupplierSubC }
                                  equals new { e.SupplierMainC, e.SupplierSubC } into t2
                                  from e in t2.DefaultIfEmpty()
                                  join t in _employeeRepository.GetAllQueryable() on a.EntryClerkC equals t.EmployeeC into t3
                                  from t in t3.DefaultIfEmpty()
                                  join q in _employeeRepository.GetAllQueryable() on a.EmployeeC equals q.EmployeeC into t4
                                  from q in t4.DefaultIfEmpty()
                                  where (((searchInfo.ParamSearch.InvoiceDEnd == null || a.InvoiceD <= searchInfo.ParamSearch.InvoiceDEnd) &&
                                          (searchInfo.ParamSearch.InvoiceDStart == null || a.InvoiceD >= searchInfo.ParamSearch.InvoiceDStart)) &
                                         //(String.IsNullOrEmpty(searchInfo.ParamSearch.EmployeeC) || a.EmployeeC == searchInfo.ParamSearch.EmployeeC) &
                                         (String.IsNullOrEmpty(searchInfo.ParamSearch.ExpenseC) || a.ExpenseC == searchInfo.ParamSearch.ExpenseC) &
                                         (searchInfo.ParamSearch.ObjectI == "C") &
                                         (String.IsNullOrEmpty(searchInfo.ParamSearch.SupplierMainC) || (a.SupplierMainC == searchInfo.ParamSearch.SupplierMainC && a.SupplierSubC == searchInfo.ParamSearch.SupplierSubC)))
                                  select new TruckExpenseViewModel()
            {
                Id = a.Id,
                InvoiceD = a.InvoiceD,
                ExpenseC = a.ExpenseC,
                ExpenseN = c.ExpenseN,
                //DriverC = a.EmployeeC,
                //DriverN = q != null ? (q.EmployeeLastN + " " + q.EmployeeFirstN) : "",
                EntryClerkC = a.EntryClerkC,
                EntryClerkN = t != null ? (t.EmployeeLastN + " " + t.EmployeeFirstN) : "",
                PaymentMethodI = a.PaymentMethodI,
                SupplierMainC = a.SupplierMainC,
                SupplierSubC = a.SupplierSubC,
                SupplierN = e.SupplierN,
                Quantity = a.Quantity,
                UnitPrice = a.UnitPrice,
                Total = a.Total + a.Tax,
                Tax = a.Tax,
                Description = a.Description,
                ExpenseI = "C",
            }).ToList();
            var combined = truckExpense.Concat(companyExpense);
            // sorting (done with the System.Linq.Dynamic library available on NuGet)
            var truckExpenseOrdered = combined.OrderBy(searchInfo.SortBy + (searchInfo.Reverse ? " descending" : ""));
            // paging
            var truckExpensePaging = truckExpenseOrdered.Skip((searchInfo.Page - 1) * searchInfo.ItemsPerPage).Take(searchInfo.ItemsPerPage).ToList();

            var datatable = new TruckExpenseDatatables()
            {
                Data  = truckExpensePaging,
                Total = truckExpenseOrdered.Count()
            };

            return(datatable);
        }
Esempio n. 4
0
        public List <FixedExpenseViewModel> GetFixedExpense(string depC,
                                                            int year,
                                                            string expenseC)
        {
            var fixedExpense = from a in _fixedExpenseRepository.GetAllQueryable()
                               join b in _departmentService.GetAllQueryable() on a.DepC
                               equals b.DepC into t1
                               from b in t1.DefaultIfEmpty()
                               join c in _truckRepository.GetAllQueryable() on a.TruckC
                               equals c.TruckC into t2
                               from c in t2.DefaultIfEmpty()
                               join d in _employeeRepository.GetAllQueryable() on a.EntryClerkC
                               equals d.EmployeeC into t3
                               from d in t3.DefaultIfEmpty()
                               join e in _expenseRepository.GetAllQueryable() on a.ExpenseC
                               equals e.ExpenseC into t4
                               from e in t4.DefaultIfEmpty()
                               where (a.DepC == depC &
                                      a.Year == year &
                                      a.ExpenseC == expenseC
                                      )
                               select new FixedExpenseViewModel()
            {
                DepC         = a.DepC,
                DepN         = b != null ? b.DepN : "",
                Year         = a.Year,
                ExpenseC     = a.ExpenseC,
                ExpenseN     = e != null ? e.ExpenseN : "",
                TruckC       = a.TruckC,
                RegisteredNo = c != null ? c.RegisteredNo : "",
                AcquisitionD = c != null ? c.AcquisitionD : null,
                RegisteredD  = c != null ? c.RegisteredD : null,
                DisusedD     = c != null ? c.DisusedD : null,
                EntryClerkC  = a.EntryClerkC,
                EntryClerkN  = d != null ? d.EmployeeLastN + " " + d.EmployeeFirstN : "",
                RetiredD     = d != null ? d.RetiredD : null,
                Total        = a.Total,
                Month1       = a.Month1,
                Month2       = a.Month2,
                Month3       = a.Month3,
                Month4       = a.Month4,
                Month5       = a.Month5,
                Month6       = a.Month6,
                Month7       = a.Month7,
                Month8       = a.Month8,
                Month9       = a.Month9,
                Month10      = a.Month10,
                Month11      = a.Month11,
                Month12      = a.Month12
            };

            fixedExpense = fixedExpense.OrderBy("RegisteredNo asc");
            var fixedExpenseList = fixedExpense.ToList();

            var truck = _truckRepository.Query(tru => tru.DepC == depC &&
                                               tru.PartnerI == "0" &&
                                               tru.IsActive == Constants.ACTIVE);
            var truckList = truck.OrderBy("RegisteredNo asc").ToList();

            if (truckList.Count > 0)
            {
                for (var iloop = 0; iloop < truckList.Count; iloop++)
                {
                    var index = fixedExpenseList.FindIndex(f => f.TruckC == truckList[iloop].TruckC);
                    if (index < 0)
                    {
                        var item = new FixedExpenseViewModel();
                        item.TruckC       = truckList[iloop].TruckC;
                        item.DepC         = truckList[iloop].DepC;
                        item.RegisteredNo = truckList[iloop].RegisteredNo;
                        item.RegisteredD  = truckList[iloop].RegisteredD;
                        item.AcquisitionD = truckList[iloop].AcquisitionD;
                        item.DisusedD     = truckList[iloop].DisusedD;
                        item.Total        = 0;
                        item.Month1       = 0;
                        item.Month2       = 0;
                        item.Month3       = 0;
                        item.Month4       = 0;
                        item.Month5       = 0;
                        item.Month6       = 0;
                        item.Month7       = 0;
                        item.Month8       = 0;
                        item.Month9       = 0;
                        item.Month10      = 0;
                        item.Month11      = 0;
                        item.Month12      = 0;

                        fixedExpenseList.Add(item);
                    }
                }
            }

            // sort fixedExpenseList by RegisteredNo
            fixedExpenseList = fixedExpenseList.OrderBy("RegisteredNo asc").ToList();

            var result = SetIsDisabledMonth(fixedExpenseList, year);

            return(result);
        }
        public FuelConsumptionDetailDatatable GetFuelConsumptionDetail(FuelConsumptionDetailSearchParams searchParams)
        {
            var searchInfo     = searchParams.SearchInfo;
            var newTruckCList  = "," + searchInfo.TruckCList + ",";
            var newDriverCList = "," + searchInfo.DriverCList + ",";

            var dispatches = from a in _dispatchRepository.GetAllQueryable()
                             join b in _orderHRepository.GetAllQueryable() on new { a.OrderD, a.OrderNo }
            equals new { b.OrderD, b.OrderNo } into ab
            from b in ab.DefaultIfEmpty()
            where ((searchInfo.TransportDFrom == null || a.TransportD >= searchInfo.TransportDFrom) &&
                   (searchInfo.TransportDTo == null || a.TransportD <= searchInfo.TransportDTo)) &
            (string.IsNullOrEmpty(searchInfo.TruckCList) || newTruckCList.Contains("," + a.TruckC + ",")) &
            (string.IsNullOrEmpty(searchInfo.DriverCList) || newDriverCList.Contains("," + a.DriverC + ",")) &
            (string.IsNullOrEmpty(searchInfo.DepC) || searchInfo.DepC == "0" || b.OrderDepC == searchInfo.DepC) &
            ((searchInfo.DispatchStatus && a.DispatchStatus == Constants.DISPATCH) ||
             (searchInfo.TransportedStatus && (a.DispatchStatus == Constants.TRANSPORTED || a.DispatchStatus == Constants.CONFIRMED))) &
            (a.DispatchI == "0")
            select new
            {
                a.OrderD,
                a.OrderNo,
                a.DispatchNo,
                a.DetailNo,
                a.TransportD,
                a.DriverC,
                a.TruckC,
                a.ContainerStatus,
                a.Location1C,
                a.Location1N,
                a.Location2C,
                a.Location2N,
                a.Location3C,
                a.Location3N
            };

            var dispatchOrdered = dispatches.OrderBy("TransportD desc");

            var dispatchPaged = dispatchOrdered.Skip((searchParams.page - 1) * searchParams.itemsPerPage).Take(searchParams.itemsPerPage).ToList();

            var fuelConsumptionDetail = from a in dispatchPaged
                                        join b in _orderDRepository.GetAllQueryable() on new { a.OrderD, a.OrderNo, a.DetailNo }
            equals new { b.OrderD, b.OrderNo, b.DetailNo } into ab
            from b in ab.DefaultIfEmpty()
            join c in _driverRepository.GetAllQueryable() on a.DriverC equals c.DriverC into abc
            from c in abc.DefaultIfEmpty()
            join d in _containerTypeRepository.GetAllQueryable() on b.ContainerTypeC equals d.ContainerTypeC into abcd
            from d in abcd.DefaultIfEmpty()
            join e in _truckRepository.GetAllQueryable() on a.TruckC equals e.TruckC into abcde
            from e in abcde.DefaultIfEmpty()
            join f in _fuelConsumptionDetailRepository.GetAllQueryable() on new { a.OrderD, a.OrderNo, a.DetailNo, a.DispatchNo }
            equals new { f.OrderD, f.OrderNo, f.DetailNo, f.DispatchNo } into abcdef
            from f in abcdef.DefaultIfEmpty()
            select new FuelConsumptionDetailViewModel()
            {
                OrderD              = a.OrderD,
                OrderNo             = a.OrderNo,
                DispatchNo          = a.DispatchNo,
                DetailNo            = a.DetailNo,
                TransportD          = a.TransportD,
                ContainerStatus     = a.ContainerStatus,
                DriverN             = c != null ? c.LastN + " " + c.FirstN : "",
                TruckC              = a.TruckC,
                RegisteredNo        = e != null ? e.RegisteredNo : "",
                ContainerSizeI      = b.ContainerSizeI,
                ContainerTypeN      = d != null ? d.ContainerTypeN : "",
                GrossWeight         = b != null ? b.GrossWeight : 0,
                Location1C          = a.Location1C,
                Location1N          = a.Location1N,
                Location2C          = a.Location2C,
                Location2N          = a.Location2N,
                Location3C          = a.Location3C,
                Location3N          = a.Location3N,
                ApproximateDistance = f != null ? f.Distance : 0,
                IsEmpty             = f != null ? f.IsEmpty : "",
                IsHeavy             = f != null ? f.IsHeavy : "",
                IsSingle            = f != null ? f.IsSingle : "",
                FuelConsumption     = f != null ? f.FuelConsumption : 0,
                UnitPrice           = f != null ? f.UnitPrice : 0,
                Amount              = f != null ? f.Amount : 0,
            };

            return(new FuelConsumptionDetailDatatable()
            {
                Data = fuelConsumptionDetail.ToList(),
                Total = dispatches.Count()
            });
        }