Пример #1
0
        public ActionResult TransactionHistory(int id, string sortColumn, string sortOrder, string currentFilter, string searchString, string dateFrom, string dateTo, int?page)
        {
            ViewBag.CurrentSort = sortColumn;
            ViewBag.SortOrder   = sortOrder == "asc" ? "desc" : "asc";

            DateTime dtDateFrom = DateTime.Now;
            DateTime dtDateTo   = DateTime.Now;

            if (!String.IsNullOrEmpty(dateFrom) && !String.IsNullOrEmpty(dateTo))
            {
                dtDateFrom = Convert.ToDateTime(dateFrom);
                dtDateTo   = Convert.ToDateTime(dateTo);
            }

            ViewBag.DateFrom = dtDateFrom.ToShortDateString();
            ViewBag.DateTo   = dtDateTo.ToShortDateString();

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            List <int?> lstVehicle = vehicleItemRepo.List().Where(v => v.VehicleId == id).Select(v => v.TransactionLogId).ToList();

            //IQueryable<TransactionLog> lstTransactionLog = transactionLogRepo.List().Where(p => lstVehicle.Contains(p.Id));

            //lstTransactionLog = from p in lstTransactionLog
            //                    where DbFunctions.TruncateTime(p.Date) >= DbFunctions.TruncateTime(dtDateFrom) &&
            //                                                  DbFunctions.TruncateTime(p.Date) <= DbFunctions.TruncateTime(dtDateTo)
            //                                                  && p.CompanyId == Sessions.CompanyId.Value
            //                    select p;

            //if (!String.IsNullOrEmpty(searchString))
            //{
            //    lstTransactionLog = lstTransactionLog.Where(s => s.Item.Description.Contains(searchString)
            //                           || s.Date.ToString().Contains(searchString));

            //}

            //if (String.IsNullOrEmpty(sortColumn))
            //{
            //    lstTransactionLog = lstTransactionLog.OrderByDescending(p => p.Id);
            //}
            //else
            //{
            //    lstTransactionLog = lstTransactionLog.OrderBy(sortColumn + " " + sortOrder);
            //}

            // IQueryable<TransactionLogVM> lstTransactionLog =  transactionLogRepo.List().Where(p => lstVehicle.Contains(p.Id));

            var lstVehicleStockTransferItem = from p in context.VehicleStockTransferItems
                                              select new TransactionLogVM
            {
                TransactionLog = p.TransactionLog,
                VehicleFrom    = p.VehicleFrom.LicenseNo
            };

            List <TransactionLogVM> lstTransactionLog = (from p in transactionLogRepo.List().Where(p => DbFunctions.TruncateTime(p.Date) >= DbFunctions.TruncateTime(dtDateFrom) &&
                                                                                                   DbFunctions.TruncateTime(p.Date) <= DbFunctions.TruncateTime(dtDateTo) &&
                                                                                                   p.CompanyId == Sessions.CompanyId.Value).ToList()
                                                         join q in lstVehicleStockTransferItem.ToList()
                                                         on p.Id equals q.TransactionLog.Id into pq from sub in pq.DefaultIfEmpty()
                                                         where lstVehicle.Contains(p.Id)

                                                         select new TransactionLogVM
            {
                TransactionLog = p,
                VehicleFrom = sub == null ? null: "from vehicle:" + sub.VehicleFrom
            }).ToList();

            //lstTransactionLog = (from p in lstTransactionLog
            //                     where DbFunctions.TruncateTime(p.TransactionLog.Date) >= DbFunctions.TruncateTime(dtDateFrom) &&
            //                                                   DbFunctions.TruncateTime(p.TransactionLog.Date) <= DbFunctions.TruncateTime(dtDateTo)
            //                                                  && p.TransactionLog.CompanyId == Sessions.CompanyId.Value).ToList();



            if (!String.IsNullOrEmpty(searchString))
            {
                lstTransactionLog = (lstTransactionLog.Where(s => s.TransactionLog.Item.Description.Contains(searchString) ||
                                                             s.TransactionLog.Date.ToString().Contains(searchString) ||
                                                             s.VehicleFrom.Contains(searchString))).ToList();
            }

            if (String.IsNullOrEmpty(sortColumn))
            {
                lstTransactionLog = (lstTransactionLog.OrderByDescending(p => p.TransactionLog.Id)).ToList();
            }
            else
            {
                lstTransactionLog = (lstTransactionLog.OrderBy(sortColumn + " " + sortOrder)).ToList();
            }



            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            var transHistoryVM = new ItemHistoryVM
            {
                Vehicle         = vehicleRepo.GetById(id),
                Company         = companyRepo.GetById(Sessions.CompanyId.Value),
                TransactionLogs = lstTransactionLog.ToPagedList(pageNumber, pageSize),
            };

            return(View(transHistoryVM));
        }
        public ActionResult TransactionHistory(int id, string sortColumn, string sortOrder, string currentFilter, string searchString, string dateFrom, string dateTo, int?page)
        {
            ViewBag.CurrentSort = sortColumn;
            ViewBag.SortOrder   = sortOrder == "asc" ? "desc" : "asc";

            DateTime dtDateFrom = DateTime.Now;
            DateTime dtDateTo   = DateTime.Now;

            if (!String.IsNullOrEmpty(dateFrom) && !String.IsNullOrEmpty(dateTo))
            {
                dtDateFrom = Convert.ToDateTime(dateFrom);
                dtDateTo   = Convert.ToDateTime(dateTo);
            }

            ViewBag.DateFrom = dtDateFrom.ToShortDateString();
            ViewBag.DateTo   = dtDateTo.ToShortDateString();

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            IQueryable <TransactionLog> lstTransactionLog = transactionLogRepo.List().Where(p => p.ItemId == id);

            lstTransactionLog = from p in lstTransactionLog
                                where DbFunctions.TruncateTime(p.Date) >= DbFunctions.TruncateTime(dtDateFrom) &&
                                DbFunctions.TruncateTime(p.Date) <= DbFunctions.TruncateTime(dtDateTo) &&
                                p.CompanyId == Sessions.CompanyId.Value && p.TransactionMethodId != 7
                                select p;

            if (!String.IsNullOrEmpty(searchString))
            {
                lstTransactionLog = lstTransactionLog.Where(s => s.TransactionMethod.Description.Contains(searchString) ||
                                                            s.Quantity.ToString().Contains(searchString) ||
                                                            s.Date.ToString().Contains(searchString) ||
                                                            s.User.Username.ToString().Contains(searchString));
            }

            if (String.IsNullOrEmpty(sortColumn))
            {
                lstTransactionLog = lstTransactionLog.OrderByDescending(p => p.Id);
            }
            else
            {
                lstTransactionLog = lstTransactionLog.OrderBy(sortColumn + " " + sortOrder);
            }

            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            var transHistoryVM = new TransactionHistoryVM
            {
                Item            = itemRepo.GetById(id),
                Company         = companyRepo.GetById(Sessions.CompanyId.Value),
                TransactionLogs = lstTransactionLog.ToPagedList(pageNumber, pageSize)
            };

            return(View(transHistoryVM));
        }