public void GetInvoices_ByPartialAccount()
        {
            var query = new InvoiceQuery();
            query.AccountName = "DOBB";

            var invoices = repository.GetInvoices(query);
            Assert.AreEqual(17, invoices.Count);
        }
        public void GetInvoices_ByLocation()
        {
            var query = new InvoiceQuery();
            query.LocationId = 3;

            var invoices = repository.GetInvoices(query);
            Assert.AreEqual(5, invoices.Count);
        }
        public void GetInvoices_ByAccount()
        {
            var query = new InvoiceQuery();
            query.AccountName = "DOBBS FORD AT WOLFCHASE";

            var invoices = repository.GetInvoices(query);
            Assert.AreEqual(4, invoices.Count);
        }
        public void GetInvoices_ByReceiveDate()
        {
            var query = new InvoiceQuery();
            query.ReceivedDateStart = DateTime.Parse("12/7/2011");
            query.ReceivedDateEnd = DateTime.Parse("12/8/2011");

            var invoices = repository.GetInvoices(query);
            Assert.AreEqual(2, invoices.Count);
        }
        protected NHibernate.ICriteria GetInvoiceFilterCriteria(InvoiceQuery query, bool isCount = false)
        {
            var criteria = Session.CreateCriteria<InvoiceView>();

            if (!string.IsNullOrEmpty(query.AccountName)) criteria.Add(Expression.Like("AccountName", query.AccountName + "%"));
            if (query.AccountIds != null && query.AccountIds.Length > 0) criteria.Add(Expression.In("AccountId", query.AccountIds));
            if (query.LocationId.HasValue) criteria.Add(Expression.Eq("LocationId", query.LocationId.Value));
            if (query.ReceivedDateStart.HasValue) criteria.Add(Expression.Ge("ReceiveDate", query.ReceivedDateStart.Value));
            if (query.ReceivedDateEnd.HasValue) criteria.Add(Expression.Le("ReceiveDate", query.ReceivedDateEnd.Value));
            if (query.CompletedDateStart.HasValue) criteria.Add(Expression.Ge("CompleteDate", query.CompletedDateStart.Value));
            if (query.CompletedDateEnd.HasValue) criteria.Add(Expression.Le("CompleteDate", query.CompletedDateEnd.Value));
            if (!string.IsNullOrEmpty(query.StockNumber)) criteria.Add(Expression.Like("StockNumber", query.StockNumber + "%"));
            if (query.HadBeenCompleted.HasValue) criteria.Add(Expression.Eq("IsComplete", query.HadBeenCompleted.Value));
            if (query.HasBeenPaid.HasValue) criteria.Add(Expression.Eq("IsPaid", query.HasBeenPaid.Value));
            if (query.ExcludeZeroTotal) criteria.Add(Expression.Gt("Total", decimal.Parse("0.0")));

            if (string.IsNullOrEmpty(query.SortBy))
                criteria.AddOrder(new Order("Id", true));
            else
                criteria.AddOrder(new Order(query.SortBy, (query.SortDirection != null && query.SortDirection.Equals("asc", StringComparison.InvariantCultureIgnoreCase))));

            return criteria;
        }
 public IList<InvoiceView> GetInvoices(InvoiceQuery query)
 {
     var criteria = GetInvoiceFilterCriteria(query);
     var result = criteria.List<InvoiceView>();
     return result;
 }
        public void GetInvoices_ByStockNumber()
        {
            var query = new InvoiceQuery();
            query.StockNumber = "BPB";

            var invoices = repository.GetInvoices(query);
            Assert.AreEqual(3, invoices.Count);
        }
        public List<DealerStatementModel> GetStatements(DateTime endDate, List<int> accountIds, string role, int locationId)
        {
            InvoiceQuery query = new InvoiceQuery();
            query.ExcludeZeroTotal = true;
            query.HadBeenCompleted = true;
            query.HasBeenPaid = false;
            if (accountIds.Count > 0) query.AccountIds = accountIds.ToArray();
            query.ReceivedDateEnd = endDate;
            query.SortBy = "Id";
            query.SortDirection = "Asc";
            if (role.Equals("Manager", StringComparison.InvariantCultureIgnoreCase)) query.LocationId = locationId;

            var reportData = InvoiceRepository.GetInvoices(query)
                    .Where(i => i.Total > 0)
                    .GroupBy(i => i.AccountId)
                    .OrderBy(a => a.Key);

            List<DealerStatementModel> report = new List<DealerStatementModel>();
            foreach (IGrouping<int, InvoiceView> statement in reportData)
            {
                var account = AccountRepository.GetAccount(statement.Key);
                report.Add(new DealerStatementModel()
                {
                    Account = Mapper.Map<Data.Graph.Account, AccountModel>(account),
                    Invoices = Mapper.Map<IList<Data.Graph.InvoiceView>, List<InvoiceViewModel>>(statement.ToList())
                });
            }

            return report.OrderBy(o => o.Account.Name).ToList();
        }