Exemplo n.º 1
0
        public IActionResult Purchases()
        {
            if (Request.Cookies["Id"] == null)
            {
                return(LocalRedirect("~/User/Login"));
            }
            int Id = Convert.ToInt32(Request.Cookies["Id"]);
            List <PurchaseView>    purchaseView = new List <PurchaseView>();
            IEnumerable <Purchase> purchases    = db.Purchases.Where(u => u.BuyerId == Id);

            foreach (var p in purchases)
            {
                Book book = db.Books.FirstOrDefault(u => u.Id == p.ProductId);
                if (book == null)
                {
                    continue;
                }
                User         seller = db.Users.FirstOrDefault(u => u.Id == book.SellerId);
                PurchaseView pv     = new PurchaseView {
                    BookId = book.Id, SellerId = seller.Id, SellerName = seller.Name, BookName = book.Title, Date = p.Date, Price = book.Price, Id = p.Id
                };
                purchaseView.Add(pv);
            }
            ViewBag.purchases = purchaseView;
            return(View());
        }
Exemplo n.º 2
0
        public ActionResult Purchase(PurchaseView model, int id)
        {
            if (ModelState.IsValid)
            {
                var repo = VehicleRepositoryFactory.GetRepository();

                try
                {
                    model.purchaser.UserID = User.Identity.GetUserId();
                    //AuthorizeUtilities.GetUserId(this);
                    repo.Purchase(model.purchaser, id);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                return(View("Index"));
            }
            else
            {
                var repo = VehicleRepositoryFactory.GetRepository();
                model.vehicle = repo.GetDetails(id);
                return(View(model));
            }
        }
Exemplo n.º 3
0
 public ActionResult ListPurchased()
 {
     try
     {
         if (User == null || string.IsNullOrEmpty(User.Identity.Name))
         {
             return(PartialView(new List <PurchaseView>()));
         }
         ManagerQuery manager      = new ManagerQuery();
         var          UserID       = manager.GetAllUsers().Where(p => p.UserName == User.Identity.Name).Select(p => p.ID).FirstOrDefault();
         var          model        = new List <PurchaseView>();
         var          lstPurchased = manager.AllPurchases().Where(p => p.UserId.HasValue && p.UserId.Value == UserID && p.PurchasesStatus.HasValue && p.PurchasesStatus.Value == 1).ToList();
         if (lstPurchased.Count > 0)
         {
             foreach (var pur in lstPurchased)
             {
                 var purView = new PurchaseView(pur);
                 purView.Availlability = (pur.CarID.HasValue && pur.PurchaseDate.HasValue && pur.ReturnDate.HasValue) ? CheckCarAvailability(pur.PurchaseDate.Value, pur.ReturnDate.Value, pur.CarID.Value) : false;
                 model.Add(purView);
             }
         }
         return(PartialView(model));
     }
     catch
     {
         return(PartialView(new List <PurchaseView>()));
     }
 }
Exemplo n.º 4
0
        public List <PurchaseView> GetExpenseReportOnSales()
        {
            List <PurchaseView> purchaseViews = new List <PurchaseView>();

            var products = _productRepository.GetAll();

            foreach (var p in products)
            {
                var sds = _salesRepository.GetAllSalesDetailses().Where(c => c.ProductId == p.Id).ToList();

                if (sds.Count == 0)
                {
                    continue;
                }

                int SoldQuantity = _salesRepository.GetTotalSaleQuantity(p.Id);

                PurchaseView purchaseView = new PurchaseView();
                purchaseView.Product      = p.Name;
                purchaseView.Quantity     = SoldQuantity;
                purchaseView.ReOrderLevel = p.ReOrderLevel;
                purchaseView.UnitPrice    = sds.Last().UnitPrice;
                purchaseView.MRP          = sds.Last().MRP;
                purchaseView.Profit       = (purchaseView.Quantity * purchaseView.MRP) -
                                            (purchaseView.Quantity * purchaseView.UnitPrice);

                purchaseViews.Add(purchaseView);
            }

            return(purchaseViews);
        }
Exemplo n.º 5
0
        public PurchaseView GetAsset_master(int ordno)
        {
            db.Configuration.ProxyCreationEnabled = true;
            PurchaseTbl  x       = db.PurchaseTbls.Where(y => y.pd_order_no == ordno).FirstOrDefault();
            PurchaseView pvModel = new PurchaseView();

            if (x == null)
            {
            }

            else
            {
                pvModel.pd_id        = x.pd_id;
                pvModel.pd_order_no  = Convert.ToInt32(x.pd_order_no);
                pvModel.pd_ad_id     = x.assetDef.ad_id;
                pvModel.assetname    = x.assetDef.ad_name;
                pvModel.pd_datestr   = x.pd_datestr;
                pvModel.pd_ddatestr  = x.pd_ddatestr;
                pvModel.pd_qty       = Convert.ToInt32(x.pd_qty);
                pvModel.pd_status    = x.pd_status;
                pvModel.pd_atype_id  = x.assetType.at_id;
                pvModel.assettype    = x.assetType.at_name;
                pvModel.pd_vendor_id = x.pd_vendor_id;
                pvModel.vendorname   = x.vendorTbl.vd_name;
            }

            return(pvModel);
        }
Exemplo n.º 6
0
        public PurchaseViewVM(PurchaseView view, ClientService service)
        {
            this.view    = view;
            this.service = service;

            initView();
        }
Exemplo n.º 7
0
        public ActionResult Purchase(int id)
        {
            var repo  = VehicleRepositoryFactory.GetRepository();
            var model = new PurchaseView();

            model.vehicle = repo.GetDetails(id);

            return(View(model));
        }
        public ActionResult Show(string search)
        {
            PurchaseView purchaseView = new PurchaseView {
                PurchaseInfos = _PurchaseManager.Search(search)
            };

            ViewBag.product = null;
            return(View(purchaseView));
        }
        public void VIP()
        {
            var vm   = AppManager.GetPurchaseViewModel();
            var view = new PurchaseView
            {
                DataContext = vm
            };

            view.Show();
        }
        public ActionResult Add(PurchaseView purchaseView)
        {
            PurchaseInfo aPurchaseInfo = purchaseView.PurchaseInfo;

            ViewBag.Message = _PurchaseManager.Insert(aPurchaseInfo) ? "Purchase is saved" : "Purchase is not Saved";
            aPurchaseView   = new PurchaseView();
            PurchaseInitialize();

            return(View(aPurchaseView));
        }
        // GET: Purchases/Create
        public ActionResult AddPurchase()
        {
            var purchaseView = new PurchaseView();

            purchaseView.Provider = new Provider();
            purchaseView.Products = new List <ProductDetail>();

            ViewBag.ProviderID = new SelectList(_repository.ProviderList(), "ProviderID", "ProviderName");

            return(View(purchaseView));
        }
Exemplo n.º 12
0
        public ActionResult SubmitNewDeal(PurchaseView pv)
        {
            if (ModelState.IsValid)
            {
                var managerHelper = new CalcModel();
                _manager.AddPurchase(pv.ReturnDateDetails());
                managerHelper.ActionResult = "New deal submitted";
                return(Json(managerHelper, JsonRequestBehavior.AllowGet));
            }

            else
            {
                return(PartialView("AddDeal"));
            }
        }
Exemplo n.º 13
0
        public ActionResult SubmitEditDeal(PurchaseView pv)
        {
            if (ModelState.IsValid)
            {
                var managerHelper = new CalcModel();
                _manager.UpdatePurchase(pv.ReturnDateDetails());
                managerHelper.ActionResult = "Deal edit submitted";
                return(Json(managerHelper, JsonRequestBehavior.AllowGet));
            }

            else
            {
                return(PartialView("EditDeal", pv));
            }
        }
Exemplo n.º 14
0
        public ActionResult AddtoBusket(PurchaseView deal)
        {
            TempData["Success"] = "Reservation Succeded!";
            var deals = Session[DEALS_IN_THE_BUSKET] as List <PurchaseView>;

            if (deals == null)
            {
                deals = new List <PurchaseView>();
            }

            deals.Add(deal);

            Session[DEALS_IN_THE_BUSKET] = deals;

            return(RedirectToAction("MyBusket"));
        }
Exemplo n.º 15
0
        public ActionResult NewPurchase()
        {
            var purchaseView = new PurchaseView();

            purchaseView.Supplier   = new Supplier();
            purchaseView.Products   = new List <ProductPurchase>();
            Session["purchaseView"] = purchaseView;

            var list = db.Suppliers.ToList();

            list.Add(new Supplier {
                SupplierID = 0, Name = "[Seleccione un Proveedor]"
            });
            list = list.OrderBy(c => c.Name).ToList();
            ViewBag.SupplierID = new SelectList(list, "SupplierID", "Name");

            return(View(purchaseView));
        }
Exemplo n.º 16
0
        // GET: Purchase
        // GET: del customer
        public ActionResult NewPackage()
        {
            var purchaseView = new PurchaseView();

            purchaseView.Customer         = new Customer();
            purchaseView.PackagePurchase1 = new List <PackagePurchase>();
            Session["purchaseView"]       = purchaseView;


            var list = db.Customers.ToList();

            list.Add(new Customer {
                CustomerId = 0, FirstName = "[Seleccione un Cliente]"
            });
            list = list.OrderBy(C => C.FullName).ToList();
            ViewBag.CustomerId = new SelectList(list, "CustomerId", "FullName");

            return(View(purchaseView));
        }
Exemplo n.º 17
0
        //  [Authorize(Roles = "Employee, Manager, Customer")]
        public ActionResult Index()
        {
            var UserID = _customer.UserId(User.Identity.Name);

            ViewBag._Model = customerModel;

            ViewBag._Car = customerCar;

            ViewBag.price = totallPrice;

            ViewBag.userId = UserID;

            ViewBag.startDate = startDate;

            ViewBag.supposedReturn = supposedReturn;

            var model = new PurchaseView();

            return(View(model));
        }
Exemplo n.º 18
0
        //// GET: api/PurchaseEdit/5
        //[ResponseType(typeof(PurchaseTbl))]
        //public IHttpActionResult GetPurchaseTbl(int id)
        //{
        //    PurchaseTbl purchaseTbl = db.PurchaseTbls.Find(id);
        //    if (purchaseTbl == null)
        //    {
        //        return NotFound();
        //    }

        //    return Ok(purchaseTbl);
        //}
        public PurchaseView GetPurchaseOrder(int id)
        {
            db.Configuration.ProxyCreationEnabled = true;
            PurchaseTbl  order = db.PurchaseTbls.Where(x => x.pd_id == id).FirstOrDefault();
            PurchaseView model = new PurchaseView();

            model.pd_id        = order.pd_id;
            model.pd_order_no  = Convert.ToInt32(order.pd_order_no);
            model.assetname    = order.assetDef.ad_name;
            model.assettype    = order.assetType.at_name;
            model.pd_ad_id     = order.pd_ad_id;
            model.pd_atype_id  = order.pd_atype_id;
            model.pd_vendor_id = order.pd_vendor_id;
            model.vendorname   = order.vendorTbl.vd_name;
            model.pd_datestr   = order.pd_datestr;
            model.pd_ddatestr  = order.pd_ddatestr;
            model.pd_qty       = Convert.ToInt32(order.pd_qty);
            model.pd_status    = order.pd_status;



            return(model);
        }
Exemplo n.º 19
0
        public ActionResult MyBusket()
        {
            //var deals = Session[DEALS_IN_THE_BUSKET] as List<PurchaseView>;
            ManagerQuery manager = new ManagerQuery();

            if (User == null || string.IsNullOrEmpty(User.Identity.Name))
            {
                return(RedirectToAction("Login", "Home"));
            }
            var UserID  = manager.GetAllUsers().Where(p => p.UserName == User.Identity.Name).Select(p => p.ID).FirstOrDefault();
            var listPur = manager.AllPurchases().Where(p => p.UserId == UserID && (!p.PurchasesStatus.HasValue || p.PurchasesStatus.Value == 0)).ToList();
            List <PurchaseView> deals = new List <PurchaseView>();

            if (listPur.Count > 0)
            {
                foreach (var pur in listPur)
                {
                    var purView = new PurchaseView(pur);
                    purView.Availlability = (pur.CarID.HasValue && pur.PurchaseDate.HasValue && pur.ReturnDate.HasValue) ? CheckCarAvailability(pur.PurchaseDate.Value, pur.ReturnDate.Value, pur.CarID.Value) : false;
                    deals.Add(purView);
                }
            }
            return(View(deals));
        }
Exemplo n.º 20
0
 public string AddPurchase(PurchaseView buyInput)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
        public ActionResult NewPackage(PurchaseView purchaseView)
        {
            purchaseView = Session["PurchaseView"] as PurchaseView;
            var customerId = int.Parse(Request["CustomerId"]);

            if (customerId == 0)
            {
                var list = db.Customers.ToList();
                list.Add(new Customer {
                    CustomerId = 0, FirstName = "[Seleccione un Cliente]"
                });
                list = list.OrderBy(C => C.FullName).ToList();
                ViewBag.CustomerId = new SelectList(list, "CustomerId", "FullName");
                ViewBag.Error      = "Debe Seleccionar un Cliente";
                return(View(purchaseView));
            }

            var customer = db.Customers.Find(customerId);

            if (customer == null)
            {
                var listC = db.Customers.ToList();
                listC.Add(new Customer {
                    CustomerId = 0, FirstName = "[Seleccione un Cliente]"
                });
                listC = listC.OrderBy(C => C.FullName).ToList();
                ViewBag.CustomerId = new SelectList(listC, "CustomerId", "FullName");
                ViewBag.Error      = "El cliente no existe";
                return(View(purchaseView));
            }

            if (purchaseView.PackagePurchase1.Count == 0)
            {
                var listC = db.Customers.ToList();
                listC.Add(new Customer {
                    CustomerId = 0, FirstName = "[Seleccione un Cliente]"
                });
                listC = listC.OrderBy(C => C.FullName).ToList();
                ViewBag.CustomerId = new SelectList(listC, "CustomerId", "FullName");
                return(View(purchaseView));
            }

            var order = new Order
            {
                CustomerId  = customerId,
                DateOrder   = DateTime.Now,
                OrderStatus = OrderStatus.Create
            };

            db.Orders.Add(order);
            db.SaveChanges();

            var orderId = db.Orders.ToList().Select(o => o.OrderID).Max();

            foreach (var item in purchaseView.PackagePurchase1)
            {
                var orderDetail = new OrderDetail
                {
                    PackageID   = item.PackageID,
                    Description = item.Description,
                    Price       = item.Price,
                    Quantity    = item.Quantity,
                    OrderID     = orderId
                };
                db.OrderDetails.Add(orderDetail);
                db.SaveChanges();
            }

            ViewBag.Message = string.Format("Orden {0}, Guardada Correctamente", orderId);

            var listS = db.Customers.ToList();

            listS.Add(new Customer {
                CustomerId = 0, FirstName = "[Seleccione un Cliente]"
            });
            listS = listS.OrderBy(C => C.FullName).ToList();
            ViewBag.CustomerId = new SelectList(listS, "CustomerId", "FullName");

            purchaseView                  = new PurchaseView();
            purchaseView.Customer         = new Customer();
            purchaseView.PackagePurchase1 = new List <PackagePurchase>();
            Session["purchaseView"]       = purchaseView;


            return(View(purchaseView));
        }
Exemplo n.º 22
0
        private void OpenWindow(string windowName)
        {
            try
            {
                WindowName name   = windowName.ConvertToWindowName();
                Window     window = null;
                switch (name)
                {
                case WindowName.NewSaleView:
                    window = new NewSaleView();
                    break;

                case WindowName.CustomerView:
                    window = new CustomerView();
                    break;

                case WindowName.NewPurchaseView:
                    window = new NewPurchaseView();
                    break;

                case WindowName.SupplierView:
                    window = new SupplierView();
                    break;

                case WindowName.SaleView:
                    window = new SaleView();
                    break;

                case WindowName.PurchaseView:
                    window = new PurchaseView();
                    break;

                case WindowName.ProductView:
                    window = new ProductView();
                    break;

                case WindowName.ServiceView:
                    window = new ServiceView();
                    break;

                case WindowName.ChargeView:
                    window = new ChargeView();
                    break;

                case WindowName.SaleReportView:
                    window = new SaleReportView();
                    break;

                case WindowName.PurchaseReportView:
                    window = new PurchaseReportView();
                    break;

                case WindowName.ProductReportView:
                    window = new ProductReportView();
                    break;
                }

                window?.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 23
0
        public ActionResult NewPurchase(PurchaseView purchaseView)
        {
            purchaseView = Session["purchaseView"] as PurchaseView;

            var SupplierID = int.Parse(Request["SupplierID"]);

            if (SupplierID == 0)
            {
                var list = db.Suppliers.ToList();
                list.Add(new Supplier {
                    SupplierID = 0, Name = "[Seleccione un Proveedor]"
                });
                list = list.OrderBy(c => c.Name).ToList();
                ViewBag.SupplierID = new SelectList(list, "SupplierID", "Name");
                ViewBag.Error      = "Debe seleccionar un Cliente";
                return(View(purchaseView));
            }

            var supplier = db.Suppliers.Find(SupplierID);

            if (supplier == null)
            {
                var list = db.Suppliers.ToList();
                list.Add(new Supplier {
                    SupplierID = 0, Name = "[Seleccione un Proveedor]"
                });
                list = list.OrderBy(c => c.Name).ToList();
                ViewBag.SupplierID = new SelectList(list, "SupplierID", "Name");
                ViewBag.Error      = "El cliente no existe";
                return(View(purchaseView));
            }

            if (purchaseView.Products.Count == 0)
            {
                var list = db.Suppliers.ToList();
                list.Add(new Supplier {
                    SupplierID = 0, Name = "[Seleccione un Proveedor]"
                });
                list = list.OrderBy(c => c.Name).ToList();
                ViewBag.SupplierID = new SelectList(list, "SupplierID", "Name");
                ViewBag.Error      = "Debe ingresar Detalle";
                return(View(purchaseView));
            }

            var purchaseID = 0;

            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    var purchase = new Purchase
                    {
                        SupplierID = SupplierID,
                        DateBuy    = DateTime.Now
                    };
                    db.Purchases.Add(purchase);
                    db.SaveChanges();

                    purchaseID = db.Purchases.ToList().Select(s => s.PurchaseID).Max();

                    foreach (var item in purchaseView.Products)
                    {
                        var purchaseProduct = new PurchaseProduct
                        {
                            ProductID   = item.ProductID,
                            Description = item.Description,
                            Price       = item.Price,
                            Quantity    = item.Quantity,
                            Total       = item.Value,
                            PurchaseID  = purchaseID
                        };
                        var product = db.ProductInventories.Find(purchaseProduct.ProductID);
                        if (product == null)
                        {
                            ProductInventory productInventory = new ProductInventory
                            {
                                ProductID   = item.ProductID,
                                Description = item.Description,
                                Price       = (purchaseProduct.Price * (decimal)db.Products.Find(purchaseProduct.ProductID).Margin) + purchaseProduct.Price,
                                Stock       = (int)purchaseProduct.Quantity,
                                SupplierID  = purchase.SupplierID,
                                LastBuy     = purchase.DateBuy
                            };
                            db.ProductInventories.Add(productInventory);

                            db.SaveChanges();
                        }
                        else
                        {
                            db.ProductInventories.Find(purchaseProduct.ProductID).Stock += (int)purchaseProduct.Quantity;
                            db.ProductInventories.Find(purchaseProduct.ProductID).Price  = (purchaseProduct.Price * (decimal)db.Products.Find(purchaseProduct.ProductID).Margin) + purchaseProduct.Price;
                        }
                        db.PurchaseProducts.Add(purchaseProduct);
                        db.Products.Find(purchaseProduct.ProductID).Price = (purchaseProduct.Price * (decimal)db.Products.Find(purchaseProduct.ProductID).Margin) + purchaseProduct.Price;
                        purchase.Total += purchaseProduct.Total;
                        db.SaveChanges();
                    }
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    ViewBag.Error = "Error" + e.Message;
                    return(View(purchaseView));
                }
            }


            ViewBag.Message = string.Format("La orden: {0}, grabada OK", purchaseID);


            var listp = db.Suppliers.ToList();

            listp.Add(new Supplier {
                SupplierID = 0, Name = "[Seleccione un Proveedor]"
            });
            listp = listp.OrderBy(c => c.Name).ToList();
            ViewBag.SupplierID = new SelectList(listp, "SupplierID", "Name");

            //RedirectToAction("NewOrder");

            purchaseView            = new PurchaseView();
            purchaseView.Supplier   = new Supplier();
            purchaseView.Products   = new List <ProductPurchase>();
            Session["purchaseView"] = purchaseView;
            return(View(purchaseView));
        }