public ActionResult List(int? orderStatusId = null,
            int? paymentStatusId = null, int? shippingStatusId = null)
        {
            //if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
            //    return AccessDeniedView();

            //if (_workContext.CurrentVendor != null)
            //{
            var orders = _orderService.SearchOrders();
            //}

            foreach (var order in orders)
            {
                decimal commission = new decimal(0);

                foreach (var item in order.OrderItems)
                {
                    var productTemplates = _productTemplateService.GetAllProductTemplates();
                    foreach (var template in productTemplates)
                    {
                        if (template.Id == item.Product.ProductTemplateId)
                        {

                        }
                    }
                }

                var invoice = new Invoice
                {
                    OrderId = order.Id,
                    Commission = order.OrderTotal * new decimal(0.15),
                    StoreId = order.StoreId,
                    IsCommissionPaid = false,
                    CreatedOnUtc = DateTime.Now,
                    PaymentStatus = order.PaymentStatus,
                    ShippingStatus = order.ShippingStatus,
                    BillingAddress = order.BillingAddress,
                    OrderStatus = order.OrderStatus,
                    ProductId = 0
                };
                if (_invoiceService.GetInvoicesByOrderId(order.Id) == null)
                {
                    _invoiceService.InsertInvoice(invoice);
                }
                else
                {
                    _invoiceService.UpdateInvoice(invoice);
                }
            }

            //order statuses
            var model = new InvoiceListModel();
            model.AvailableOrderStatuses = OrderStatus.Pending.ToSelectList(false).ToList();
            model.AvailableOrderStatuses.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
            if (orderStatusId.HasValue)
            {
                //pre-select value?
                var item = model.AvailableOrderStatuses.FirstOrDefault(x => x.Value == orderStatusId.Value.ToString());
                if (item != null)
                    item.Selected = true;
            }

            //payment statuses
            model.AvailablePaymentStatuses = PaymentStatus.Pending.ToSelectList(false).ToList();
            model.AvailablePaymentStatuses.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
            if (paymentStatusId.HasValue)
            {
                //pre-select value?
                var item = model.AvailablePaymentStatuses.FirstOrDefault(x => x.Value == paymentStatusId.Value.ToString());
                if (item != null)
                    item.Selected = true;
            }

            //shipping statuses
            model.AvailableShippingStatuses = ShippingStatus.NotYetShipped.ToSelectList(false).ToList();
            model.AvailableShippingStatuses.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
            if (shippingStatusId.HasValue)
            {
                //pre-select value?
                var item = model.AvailableShippingStatuses.FirstOrDefault(x => x.Value == shippingStatusId.Value.ToString());
                if (item != null)
                    item.Selected = true;
            }

            //stores
            model.AvailableStores.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
            foreach (var s in _storeService.GetAllStores())
                model.AvailableStores.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString() });

            ////vendors
            //model.AvailableVendors.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
            //foreach (var v in _vendorService.GetAllVendors(showHidden: true))
            //    model.AvailableVendors.Add(new SelectListItem { Text = v.Name, Value = v.Id.ToString() });

            ////warehouses
            //model.AvailableWarehouses.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
            //foreach (var w in _shippingService.GetAllWarehouses())
            //    model.AvailableWarehouses.Add(new SelectListItem { Text = w.Name, Value = w.Id.ToString() });

            //payment methods
            model.AvailablePaymentMethods.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "" });
            foreach (var pm in _paymentService.LoadAllPaymentMethods())
                model.AvailablePaymentMethods.Add(new SelectListItem { Text = pm.PluginDescriptor.FriendlyName, Value = pm.PluginDescriptor.SystemName });

            ////billing countries
            //foreach (var c in _countryService.GetAllCountriesForBilling(true))
            //{
            //    model.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.Id.ToString() });
            //}
            //model.AvailableCountries.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });

            //a vendor should have access only to orders with his products
            model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

            return View(model);
        }
        public void InsertInvoice(Invoice invoice)
        {
            if(invoice == null)
                throw new ArgumentNullException("invoice");

            _invoiceRepository.Insert(invoice);

            _eventPublisher.EntityInserted(invoice);
        }
        public void UpdateInvoice(Invoice invoice)
        {
            if (invoice == null)
                throw new ArgumentNullException("invoice");

            _invoiceRepository.Update(invoice);

            _eventPublisher.EntityUpdated(invoice);
        }
 public void DeleteInvoice(Invoice invoice)
 {
     throw new NotImplementedException();
 }