public int CountExchangeHeaders(string vnFrom, string vnTo, string propNo, string enNo, string dCode,
     string repairFromDt, string repairToDt, string confirmFromDt, string confirmToDt, int? status, ExchangePartHeader pageSum)
 {
     return _exchangeHeadersCount;
 }
        public List<ExchangePartHeader> FindExchangeHeaders(string vnFrom, string vnTo, string propNo, string enNo, string dCode,
            string repairFromDt, string repairToDt, string confirmFromDt, string confirmToDt, int? status, out ExchangePartHeader pageSum, int maximumRows, int startRowIndex)
        {
            DateTime dtRF = DataFormat.DateFromString(repairFromDt);
            DateTime dtRT = DataFormat.DateFromString(repairToDt); //if (dtRT == DateTime.MinValue) dtRT = DateTime.Now.Date;
            DateTime dtCF = DataFormat.DateFromString(confirmFromDt);
            DateTime dtCT = DataFormat.DateFromString(confirmToDt); //if (dtCT == DateTime.MinValue) dtCT = DateTime.Now.Date;

            var dc = ExchangeVoucherBO.DC;
            var query = dc.ExchangePartHeaders.AsQueryable();
            if (!string.IsNullOrEmpty(vnFrom)) query = query.Where(h => h.VoucherNumber.CompareTo(vnFrom) >= 0);
            if (!string.IsNullOrEmpty(vnTo)) query = query.Where(h => h.VoucherNumber.CompareTo(vnTo) <= 0);
            if (!string.IsNullOrEmpty(propNo)) query = query.Where(h => h.FinalVoucherNumber.Contains(propNo));
            if (!string.IsNullOrEmpty(enNo)) query = query.Where(h => h.EngineNumber.Contains(enNo));
            if (!string.IsNullOrEmpty(dCode)) query = query.Where(h => h.DealerCode == dCode);
            if (dtCF > DateTime.MinValue) query = query.Where(h => h.LastProcessedDate >= dtCF);
            if (dtCT > DateTime.MinValue) query = query.Where(h => h.LastProcessedDate < dtCT.AddDays(1));
            if (dtRF > DateTime.MinValue) query = query.Where(h => h.ServiceHeader.ServiceDate >= dtRF);
            if (dtRT > DateTime.MinValue) query = query.Where(h => h.ServiceHeader.ServiceDate < dtRT.AddDays(1));
            if ((status.HasValue) && (status.Value >= 0)) query = query.Where(h => h.Status == (int)status);

            _exchangeHeadersCount = query.Count();

            if ((startRowIndex >= 0) && (maximumRows > 0)) query = query.Skip(startRowIndex).Take(maximumRows);
            var res = query.ToList();

            //summarization
            pageSum = new ExchangePartHeader();

            foreach (var item in res)
            {
                foreach (var d in item.ExchangePartDetails)
                {
                    d.LoadWarrCond(dc);
                }
                item.DoSummary();
                if (pageSum.DealerCode == null)
                    pageSum.DealerCode = item.DealerCode;
                else
                    if (!pageSum.DealerCode.Contains(item.DealerCode)) pageSum.DealerCode = string.Concat(pageSum.DealerCode, "@", item.DealerCode);
            }
            pageSum.TotalFeeM = res.Sum(p => p.TotalFeeM);
            pageSum.TotalFeeO = res.Sum(p => p.TotalFeeO);
            pageSum.TotalPartCostM = res.Sum(p => p.TotalPartCostM);
            pageSum.TotalPartCostO = res.Sum(p => p.TotalPartCostO);
            pageSum.TotalQuantityM = res.Sum(p => p.TotalQuantityM);
            pageSum.TotalQuantityO = res.Sum(p => p.TotalQuantityO);
            pageSum.ProposeFeeAmount = res.Sum(p => p.ProposeFeeAmount);

            return res;
        }
        public static ExchangePartHeader SummaryExchangeHeaders(string vnFrom, string vnTo, string propNo, string enNo, string dCode,
            string repairFromDt, string repairToDt, string confirmFromDt, string confirmToDt, int? status)
        {
            DateTime dtRF = DataFormat.DateFromString(repairFromDt);
            DateTime dtRT = DataFormat.DateFromString(repairToDt); //if (dtRT == DateTime.MinValue) dtRT = DateTime.Now.Date;
            DateTime dtCF = DataFormat.DateFromString(confirmFromDt);
            DateTime dtCT = DataFormat.DateFromString(confirmToDt); //if (dtCT == DateTime.MinValue) dtCT = DateTime.Now.Date;

            var dc = ExchangeVoucherBO.DC;
            var query = dc.ExchangePartDetails.AsQueryable();
            if (!string.IsNullOrEmpty(vnFrom)) query = query.Where(p => p.ExchangePartHeader.VoucherNumber.CompareTo(vnFrom) >= 0);
            if (!string.IsNullOrEmpty(vnTo)) query = query.Where(p => p.ExchangePartHeader.VoucherNumber.CompareTo(vnTo) <= 0);
            if (!string.IsNullOrEmpty(propNo)) query = query.Where(p => p.ExchangePartHeader.FinalVoucherNumber.Contains(propNo));
            if (!string.IsNullOrEmpty(enNo)) query = query.Where(p => p.ExchangePartHeader.EngineNumber.Contains(enNo));
            if (!string.IsNullOrEmpty(dCode)) query = query.Where(p => p.ExchangePartHeader.DealerCode == dCode);
            if (dtCF > DateTime.MinValue) query = query.Where(p => p.ExchangePartHeader.LastProcessedDate >= dtCF);
            if (dtCT > DateTime.MinValue) query = query.Where(p => p.ExchangePartHeader.LastProcessedDate < dtCT.AddDays(1));
            if (dtRF > DateTime.MinValue) query = query.Where(p => p.ExchangePartHeader.ServiceHeader.ServiceDate >= dtRF);
            if (dtRT > DateTime.MinValue) query = query.Where(p => p.ExchangePartHeader.ServiceHeader.ServiceDate < dtRT.AddDays(1));
            if (status != null) query = query.Where(p => p.ExchangePartHeader.Status == (int)status);
            var cQuery = query.Where(p => p.ExchangePartHeader.Status == (int)ExchangeVoucherStatus.Approved);

            ExchangePartHeader res = new ExchangePartHeader();
            res.TotalFeeM = cQuery.Sum(p => p.TotalFeeM);
            res.TotalQuantityM = cQuery.Sum(p => p.PartQtyM);
            res.TotalPartCostM = cQuery.Sum(p => p.UnitPriceM * p.PartQtyM);

            res.TotalFeeO = query.Sum(p => p.TotalFeeO);
            res.TotalQuantityO = query.Sum(p => p.PartQtyO);
            res.TotalPartCostO = query.Sum(p => p.UnitPriceO * p.PartQtyO);
            res.ProposeFeeAmount = query.GroupBy(p => new { HId = p.ExchangePartHeaderId, ProposeFeeAmount = p.ExchangePartHeader.ProposeFeeAmount }, (g, result) => new { ProposeFeeAmount = g.ProposeFeeAmount }).Sum(p => p.ProposeFeeAmount);
            return res;
        }