public List<SummaryInOutStatisticReport> GetInOutStatisticItemsData(int maximumRows, int startRowIndex, string area, DateTime from, DateTime to)
        {
            var items = GetInOutStatisticItems(area, from, to).ToList();
            var sd = GetShippingQuery(area, from, to);
            var ds = sd.GroupBy(p => p.ShippingHeader.DealerCode).Select(p => p.Key).ToList();

            _SummaryInOutReportCount = ds.Count;
            if (maximumRows > 0) ds = ds.Skip(startRowIndex).Take(maximumRows).ToList();

            List<SummaryInOutStatisticReport> res = new List<SummaryInOutStatisticReport>();
            ds.ForEach(p =>
            {
                var row = new SummaryInOutStatisticReport()
                {
                    Items = sd.Where(d => d.ShippingHeader.DealerCode == p)
                              .GroupBy(d => new { d.Item.ItemType },
                    (g, rs) => new SummaryInOutStatisticItem
                    {
                        ItemCode = g.ItemType,
                        In = rs.Count(),
                        Out = rs.Where(s => s.ItemInstance.Status == (int)ItemStatus.Sold).Count(),
                    }).ToList(),
                    DealerCode = p,
                    DealerName = DealerHelper.GetNameI(p),
                };
                row.Items.AddRange(items.Where(i => !row.Items.Exists(i2 => i.ItemCode == i2.ItemCode)));
                row.Items = row.Items.OrderBy(i => i.ItemCode).ToList();
                row.TotalIn = row.Items.Where(i => i.In.HasValue).Sum(i => i.In.Value);
                row.TotalOut = row.Items.Where(i => i.Out.HasValue).Sum(i => i.Out.Value);
                res.Add(row);
            });

            return res;
        }
        public List<SummaryInOutStatisticReport> GetInOutStatisticItemsData(int maximumRows, int startRowIndex, string area, DateTime from, DateTime to)
        {
            //var items = GetInOutStatisticItems(area, from, to).ToList();
            //var sd = GetShippingQuery(area, from, to);
            var sd = GetInOutTransactions(area, from, to).ToList();

            var items = sd.GroupBy(p => p.ItemInstance.ItemType, (g, ress) => new SummaryInOutStatisticItem() { ItemCode = g }).OrderBy(p => p.ItemCode);
            var ds = sd.GroupBy(p => p.ItemInstance.DealerCode).Select(p => p.Key).ToList();

            _SummaryInOutReportCount = ds.Count;
            if (maximumRows > 0) ds = ds.Skip(startRowIndex).Take(maximumRows).ToList();

            List<SummaryInOutStatisticReport> res = new List<SummaryInOutStatisticReport>();
            foreach (var p in ds)
            {
                var row = new SummaryInOutStatisticReport()
                {
                    Items = sd.Where(d => d.ItemInstance.DealerCode == p)
                              .GroupBy(d => new { d.ItemInstance.ItemType },
                    (g, rs) => new SummaryInOutStatisticItem
                    {
                        ItemCode = g.ItemType,
                        In = rs.Where(t => IsImportedItem(t.TransactionType)).Count(),
                        Out = rs.Where(s => !IsImportedItem(s.TransactionType)).Count(),
                    }).ToList(),
                    DealerCode = p,
                    DealerName = DealerHelper.GetNameI(p),
                };
                row.Items.AddRange(items.Where(i => !row.Items.Exists(i2 => i2.ItemCode == i.ItemCode)));
                row.Items = row.Items.OrderBy(i => i.ItemCode).ToList();
                row.TotalIn = row.Items.Where(i => i.In.HasValue).Sum(i => i.In.Value);
                row.TotalOut = row.Items.Where(i => i.Out.HasValue).Sum(i => i.Out.Value);
                res.Add(row);
            }

            return res;
        }