public InvoiceAdministrationModel GetInvoiceAdministrationDetail(InvoiceFilterModel filter)
        {
            InvoiceAdministrationModel model = new InvoiceAdministrationModel(filter);

            if (filter == null)
            {
                filter = new InvoiceFilterModel();
                filter.Size = 1;
            }

            var invoices = GetInvoices(filter);
            if (invoices != null && invoices.Count > 0)
            {
                //falls back to first invoice if current page is off the end
                var currentId = GetCurrentInvoiceId(filter, invoices);

                model.InvoiceList = invoices.Select(i => i.Id).ToPagedList(filter.Page, filter.Size);
                model.CurrentInvoice = Mapper.Map<Data.Graph.Invoice, InvoiceModel>(InvoiceRepository.GetInvoice(currentId));
                model.Filter = filter;

                if (!string.IsNullOrEmpty(model.CurrentInvoice.StockNumber))
                {
                    var history = InvoiceRepository.GetInvoiceHistory(model.CurrentInvoice.StockNumber);
                    model.CurrentInvoice.History = Mapper.Map<IList<Data.Graph.StockNumberHistory>, List<HistoryModel>>(history);
                }
            }

            return model;
        }
 public InvoiceAdministrationModel()
 {
     Filter = new InvoiceFilterModel()
     {
         Size = 1
     };
     InvoiceList    = new PagedList <int>(new List <int>(), Filter.Page, Filter.Size);
     CurrentInvoice = new InvoiceModel();
 }
        public InvoiceListingModel GetInvoiceListing(InvoiceFilterModel filter)
        {
            if (filter == null)
            {
                filter = new InvoiceFilterModel();
            }

            var invoices = GetInvoices(filter);

            InvoiceListingModel model = new InvoiceListingModel();
            model.Filter = filter;
            model.InvoiceList = invoices.ToPagedList(filter.Page, filter.Size);

            for (int i = 0; i < model.InvoiceList.Count; i++)
                model.InvoiceList[i].RowId = ((filter.Page - 1) * filter.Size) + i + 1;

            return model;
        }
        // TODO: test?
        public ActionResult InvoiceListing(InvoiceFilterModel filter)
        {
            var listing = AdministrationServices.GetInvoiceListing(filter);

            ViewBag.Filter = "InvoiceListing";
            ViewBag.Locations = LocationServices.GetLocationLookup(true, filter.LocationId);
            ViewBag.Paid = LookupServices.GetPaidOptions(filter.HasBeenPaid, true);
            ViewBag.Size = LookupServices.GetSizeOptions(filter.Size);

            if (listing.InvoiceList.Count == 0)
                return View("InvoiceListingNoData", listing);
            else
                return View("InvoiceListing", listing);
        }
        // TODO: test?
        public ActionResult InvoiceDetail(InvoiceFilterModel filter)
        {
            var detail = AdministrationServices.GetInvoiceAdministrationDetail(filter);

            ViewBag.Filter = "InvoiceDetail";
            ViewBag.Locations = LocationServices.GetLocationLookup(true, filter.LocationId);
            ViewBag.Paid = LookupServices.GetPaidOptions(filter.HasBeenPaid, true);

            if (detail.InvoiceList.Count == 0)
                return View("InvoiceDetailNoData", detail);
            else
                return View("InvoiceDetail", detail);
        }
 private int GetCurrentInvoiceId(InvoiceFilterModel filter, IList<InvoiceViewModel> invoices)
 {
     //fall back to first invoice if current page is off the end
     int currentId;
     if (filter.Page - 1 >= invoices.Count)
     {
         currentId = invoices[0].Id;
         filter.Page = 1;
     }
     else
     {
         currentId = invoices[filter.Page - 1].Id;
     }
     return currentId;
 }
        private IList<InvoiceViewModel> GetInvoices(InvoiceFilterModel filter)
        {
            var cacheKey = "invoice-admin";

            var invoices = HttpRuntime.Cache[cacheKey] as IList<InvoiceViewModel>;
            if (invoices == null || invoices.Count == 0 || filter.DoEvaluate)
            {
                // load from database
                Logger.Info("Loading invoice administration from database");
                var query = Mapper.Map<InvoiceFilterModel, Data.Query.InvoiceQuery>(filter);
                var result = InvoiceRepository.GetInvoices(query);
                invoices = Mapper.Map<IList<Data.Graph.InvoiceView>, IList<InvoiceViewModel>>(result);
                HttpRuntime.Cache.Insert(cacheKey, invoices, null, Cache.NoAbsoluteExpiration, TimeSpan.FromHours(1.0));
            }
            else
            {
                Logger.Info("Returning invoice administration from cache");
            }

            // load from cache unless told not to
            filter.DoEvaluate = false;

            return invoices;
        }
Ejemplo n.º 8
0
        public void InvoiceServiceSetup()
        {
            service = WindsorPersistenceFixture.Container.Resolve<InvoiceAdministrationService>();

            filter = new InvoiceFilterModel();
            filter.AccountName = "DOBBS FORD AT MT. MORIAH";
            filter.ReceivedDateStart = DateTime.Parse("12/7/2011");
            filter.ReceivedDateEnd = DateTime.Parse("12/10/2011");
        }
 public InvoiceAdministrationModel(InvoiceFilterModel filter)
 {
     Filter = filter;
     InvoiceList = new PagedList<int>(new List<int>(), Filter.Page, Filter.Size);
     CurrentInvoice = new InvoiceModel();
 }