Ejemplo n.º 1
0
        public ActionResult Index()
        {
            MyIdentityDbContext          db          = new MyIdentityDbContext();
            UserStore <MyIdentityUser>   userStore   = new UserStore <MyIdentityUser>(db);
            UserManager <MyIdentityUser> userManager = new UserManager <MyIdentityUser>(userStore);

            MyIdentityUser user = userManager.FindByName(HttpContext.User.Identity.Name);

            //MoencoPOSContext northwindDb = new MoencoPOSContext();
            //List<AspNetUsers> model = null;

            //if (userManager.IsInRole(user.Id, "Administrator"))
            //{
            //    model = northwindDb.Customers.ToList();
            //}

            //if (userManager.IsInRole(user.Id, "Operator"))
            //{
            //    model = northwindDb.Customers.Where(c => c.Country == "USA").ToList();
            //}
            var salesInvoices = new List <SalesInvoice>();

            if (user.Role == "Administrator")
            {
                salesInvoices = _salesInvoiceService.Get(t => t.Status == "Paid", null, "SalesLineItems").OrderByDescending(o => o.DateSold).ToList();
            }
            else
            {
                salesInvoices = _salesInvoiceService.Get(t => t.BranchId == user.BranchId && t.Status == "Paid", null, "SalesLineItems").OrderByDescending(o => o.DateSold).ToList();
            }

            var salesLineItems = new List <SalesLineItem>();

            foreach (var salesInvoice in salesInvoices)
            {
                foreach (var sLI in salesInvoice.SalesLineItems)
                {
                    salesLineItems.Add(sLI);
                }
            }
            var groupedSLIs = (from tr in salesLineItems
                               group tr by new { tr.ProductId }
                               into groupedSLI
                               select
                               new
            {
                ProductID = groupedSLI.Key.ProductId,
                ProductName = _productService.FindById(groupedSLI.Key.ProductId).ProductName,
                UnitPrice = _productService.FindById(groupedSLI.Key.ProductId).UnitPrice,
                QuantitySold = groupedSLI.Sum(p => p.Quantity)
            });
            List <SalesReportViewModel> salesReportViewModels = (from groupedSLI in groupedSLIs let i = groupedSLI where i != null where i != null select new SalesReportViewModel()
            {
                ProductId = i.ProductID, ProductName = i.ProductName, QuantitySold = i.QuantitySold, UnitPrice = i.UnitPrice
            }).ToList();

            ViewBag.GroupedSLIs = salesReportViewModels.Take(10);

            var allSalesInvoices       = _salesInvoiceService.Get(t => t.Status == "Returned", null, "SalesLineItems").OrderByDescending(o => o.DateSold).ToList();
            var salesInvoiceViewModels = new List <SalesInvoiceViewModel>();

            foreach (var salesInvoice in allSalesInvoices)
            {
                var salesInvoiceViewModel = new SalesInvoiceViewModel()
                {
                    BranchId       = salesInvoice.BranchId,
                    CustomerId     = salesInvoice.CustomerId,
                    CustomerName   = salesInvoice.Customer.FirstName + " " + salesInvoice.Customer.LastName,
                    BranchName     = salesInvoice.Branch.BranchName,
                    DateSold       = salesInvoice.DateSold,
                    ReferenceNo    = salesInvoice.ReferenceNo,
                    SalesInvoiceId = salesInvoice.SalesInvoiceId,
                    SalesType      = salesInvoice.SalesType,
                    UserId         = salesInvoice.UserId,
                    UserName       = userManager.FindById(salesInvoice.UserId).FullName,
                    Status         = salesInvoice.Status
                };
                salesInvoiceViewModels.Add(salesInvoiceViewModel);
            }
            ViewBag.ReturnedSales = salesInvoiceViewModels.Take(10);

            var productReceives           = _productReceiveService.GetAllProductReceive();
            var productReceivesViewModels = new List <ProductReceiveViewModel>();

            foreach (var productReceive in productReceives)
            {
                var productReceiveViewModel = new ProductReceiveViewModel()
                {
                    BranchId         = productReceive.BranchId,
                    BranchName       = productReceive.Branch.BranchName,
                    DateReceived     = productReceive.DateReceived,
                    ProductReceiveId = productReceive.ProductReceiveId,

                    UserId   = productReceive.UserId,
                    UserName = userManager.FindById(productReceive.UserId).FullName
                };
                productReceivesViewModels.Add(productReceiveViewModel);
            }
            ViewBag.ReceivedStock = salesInvoiceViewModels.Take(10);

            var productTransfers          = _productTransferService.GetAllProductTransfer();
            var producttransferViewModels = new List <ProductTransferViewModel>();

            foreach (var productTransfer in productTransfers)
            {
                var productTransferViewModel = new ProductTransferViewModel()
                {
                    FromBranchId      = productTransfer.FromBranchId,
                    ToBranchId        = productTransfer.ToBranchId,
                    ProductTransferId = productTransfer.ProductTransferId,
                    DateTransfered    = productTransfer.DateTransfered,
                    UserId            = productTransfer.UserId,
                    UserName          = userManager.FindById(productTransfer.UserId).FullName
                };
                productTransferViewModel.FromBranchName = _branchService.FindById(productTransferViewModel.FromBranchId).BranchName;
                productTransferViewModel.ToBranchName   = _branchService.FindById(productTransferViewModel.ToBranchId).BranchName;

                producttransferViewModels.Add(productTransferViewModel);
            }
            ViewBag.TransferredStock = salesInvoiceViewModels.Take(10);

            if (user != null)
            {
                ViewBag.FullName = user.FullName;
            }
            else
            {
                ViewBag.FullName = "Admin";
            }
            //return View(model);
            return(View());
        }
Ejemplo n.º 2
0
        // GET: SalesInvoices/Create
        public ActionResult Create(int?id, int?salesType)
        {
            MyIdentityDbContext          db          = new MyIdentityDbContext();
            UserStore <MyIdentityUser>   userStore   = new UserStore <MyIdentityUser>(db);
            UserManager <MyIdentityUser> userManager = new UserManager <MyIdentityUser>(userStore);
            MyIdentityUser user = userManager.FindByName(HttpContext.User.Identity.Name);

            if (id != null && id != 0)
            {
                var salesInvoice          = _salesInvoiceService.Get(t => t.SalesInvoiceId == id, null, "SalesLineItems").FirstOrDefault();
                var salesInvoiceViewModel = new SalesInvoiceViewModel()
                {
                    BranchId       = salesInvoice.BranchId,
                    CustomerId     = salesInvoice.CustomerId,
                    CustomerName   = salesInvoice.Customer.FirstName + " " + salesInvoice.Customer.LastName,
                    BranchName     = salesInvoice.Branch.BranchName,
                    DateSold       = salesInvoice.DateSold,
                    ReferenceNo    = salesInvoice.ReferenceNo,
                    SalesInvoiceId = salesInvoice.SalesInvoiceId,
                    SalesType      = salesInvoice.SalesType,
                    UserId         = salesInvoice.UserId,
                    UserName       = userManager.FindById(salesInvoice.UserId).FullName,
                    Status         = salesInvoice.Status
                };
                ViewBag.UserName       = user.FullName;
                ViewBag.BranchName     = _branchService.FindById(user.BranchId).BranchName;
                ViewBag.CustomerList   = new SelectList(_customerService.GetAllCustomers(), "CustomerId", "FirstName", salesInvoice.CustomerId);
                ViewBag.BranchList     = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName", salesInvoice.BranchId);
                ViewBag.SalesInvoiceId = salesInvoice.SalesInvoiceId;
                var salesLineItemviewModels = new List <SalesInvoiceLineItemViewModel>();
                foreach (var salesLineItem in salesInvoice.SalesLineItems)
                {
                    var salesLineItemviewModel = new SalesInvoiceLineItemViewModel()
                    {
                        SalesLineItemId = salesLineItem.SalesLineItemId,
                        ProductId       = salesLineItem.ProductId,
                        Productname     = _productService.FindBy(s => s.ProductcId == salesLineItem.ProductId).First().ProductName,
                        Quantity        = salesLineItem.Quantity,
                        UnitPrice       = salesLineItem.UnitPrice
                    };
                    salesLineItemviewModels.Add(salesLineItemviewModel);
                }
                ViewData["CustomerList"] = new SelectList(_customerService.GetAllCustomers(), "CustomerId", "FirstName", salesInvoice.CustomerId);
                ViewData["ProductList"]  = new SelectList(_productService.GetAllProducts(), "ProductcId", "ProductName", salesInvoice.CustomerId);

                ViewBag.SalesLineItemViewModels = salesLineItemviewModels;
                ViewBag.UserName   = user.FullName;
                ViewBag.BranchName = _branchService.FindById(user.BranchId).BranchName;
                ViewBag.SalesType  = salesInvoice.SalesType;
                return(View(salesInvoiceViewModel));
            }

            ViewBag.UserName   = user.FullName;
            ViewBag.BranchName = _branchService.FindById(user.BranchId).BranchName;
            if (salesType == 0)
            {
                ViewBag.CustomerList = new SelectList(_customerService.Get(t => t.Trusted).ToList(), "CustomerId", "FirstName");
            }
            else
            {
                ViewBag.CustomerList = new SelectList(_customerService.GetAllCustomers(), "CustomerId", "FirstName");
            }
            ViewBag.SalesType  = salesType;
            ViewBag.BranchList = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName");
            return(View());
        }
 public IList <SalesInvoice> Get()
 {
     return(_salesInvoiceService.Get());
 }