コード例 #1
0
        public ActionResult AddLineItem([Bind(Include = "SalesInvoiceId,Quantity,ProductId")] SalesInvoiceLineItemViewModel salesInvoiceLineItemViewModel)
        {
            var salesInvoice = _salesInvoiceService.Get(t => t.SalesInvoiceId == salesInvoiceLineItemViewModel.SalesInvoiceId, null, "SalesLineItems").FirstOrDefault();
            int exists       = salesInvoice.SalesLineItems.Where(t => t.ProductId == salesInvoiceLineItemViewModel.ProductId).ToList().Count;

            if (exists > 0)
            {
                return(RedirectToAction("Create", "SalesInvoices", new { id = salesInvoice.SalesInvoiceId }));
            }
            var salesInvoiceLineItem = new SalesLineItem()
            {
                ProductId      = salesInvoiceLineItemViewModel.ProductId,
                Quantity       = salesInvoiceLineItemViewModel.Quantity,
                SalesInvoiceId = salesInvoiceLineItemViewModel.SalesInvoiceId,
                UnitPrice      = _productService.FindById(salesInvoiceLineItemViewModel.ProductId).UnitPrice
            };

            salesInvoice.SalesLineItems.Add(salesInvoiceLineItem);
            _salesInvoiceService.EditSalesInvoice(salesInvoice);
            return(RedirectToAction("Create", "SalesInvoices", new { id = salesInvoice.SalesInvoiceId }));
        }
コード例 #2
0
        public ActionResult SalesAttachment(int id)
        {
            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
            };

            var salesLineItemviewModels = new List <SalesInvoiceLineItemViewModel>();

            foreach (var salesLineItem in salesInvoice.SalesLineItems)
            {
                var salesLineItemviewModel = new SalesInvoiceLineItemViewModel()
                {
                    ProductId   = salesLineItem.ProductId,
                    Productname = _productService.FindBy(s => s.ProductcId == salesLineItem.ProductId).First().ProductName,
                    Quantity    = salesLineItem.Quantity,
                    UnitPrice   = salesLineItem.UnitPrice,
                    TotalPrice  = salesLineItem.Quantity * salesLineItem.UnitPrice
                };
                salesLineItemviewModels.Add(salesLineItemviewModel);
            }
            ViewBag.GrandTotal = salesLineItemviewModels.Sum(t => t.TotalPrice);
            ViewBag.SalesLineItemViewModels = salesLineItemviewModels;

            return(View(salesInvoiceViewModel));
        }
コード例 #3
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());
        }