public ActionResult DeleteConfirmed(int id)
        {
            productsinventory productsInventory = db.productsinventories.Find(id);

            db.productsinventories.Remove(productsInventory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ID,ProductID,Quantity,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate")] productsinventory productsInventory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productsInventory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductID = new SelectList(db.products, "ID", "Name", productsInventory.ProductID);
     return(View(productsInventory));
 }
        // GET: ProductsInventories/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            productsinventory productsInventory = db.productsinventories.Find(id);

            if (productsInventory == null)
            {
                return(HttpNotFound());
            }
            return(View(productsInventory));
        }
        // GET: ProductsInventories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            productsinventory productsInventory = db.productsinventories.Find(id);

            if (productsInventory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProductID = new SelectList(db.products, "ID", "Name", productsInventory.ProductID);
            return(View(productsInventory));
        }
Esempio n. 5
0
        public ActionResult Create(PurchaseEntryVM purchaseEntryVM)
        {
            purchaseEntryVM._orderDetail.RemoveAt(0); // remove first template record from list

            purchaseentry purchaseEntry = purchaseEntryVM.purchaseEntry;
            float         totalAmt      = calculateTotal(purchaseEntryVM._orderDetail);

            purchaseEntry.TotalAmount = calculateGrandTotal(purchaseEntry.CGST, purchaseEntry.SGST, purchaseEntry.DiscountAmount, totalAmt);
            if (purchaseEntry.DueAmount == 0)
            {
                purchaseEntry.Status = true;
            }
            if (ModelState.IsValid)
            {
                purchaseorder po = new purchaseorder();
                po.SupplierID      = purchaseEntryVM.purchaseOrder.SupplierID;
                po.PurchaseOrderNo = purchaseEntryVM.purchaseOrder.PurchaseOrderNo;
                if (purchaseEntryVM.purchaseOrder.ID != 0)
                {
                    po.ID = purchaseEntryVM.purchaseOrder.ID;
                }
                po.IsPurcheseEntry = true; // set this is true for Purchase Entry
                foreach (var od in purchaseEntryVM._orderDetail)
                {
                    if (od.ProductID == 0)
                    {
                        continue;
                    }
                    if (db.orderdetails.Where(x => x.PurchaseOrderID == purchaseEntryVM.purchaseOrder.ID && x.ProductID == od.ProductID).ToList().Count > 0)
                    {
                        var orderDetail = db.orderdetails.Find(od.ID);
                        if (orderDetail != null)
                        {
                            orderDetail.CostPrice        = od.CostPrice;
                            orderDetail.PurchaseOrderID  = purchaseEntryVM.purchaseOrder.ID;
                            orderDetail.Quantity         = od.Quantity;
                            orderDetail.ReceivedQuantity = od.ReceivedQuantity;
                            db.orderdetails.Attach(orderDetail);
                            db.Entry(orderDetail).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        po.orderdetails.Add(od);
                    }

                    // Update inventory table with quantity
                    var objPI = db.productsinventories.Where(x => x.ProductID == od.ProductID).SingleOrDefault();
                    if (objPI != null)
                    {
                        objPI.Quantity = objPI.Quantity + (int)od.ReceivedQuantity;
                        db.productsinventories.Attach(objPI);
                        db.Entry(objPI).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        productsinventory PI = new productsinventory();
                        PI.ProductID = od.ProductID;
                        PI.Quantity  = (int)od.ReceivedQuantity;
                        db.productsinventories.Add(PI);
                    }
                }
                if (po.ID == 0)
                {
                    po.purchaseentries.Add(purchaseEntry);
                    db.purchaseorders.Add(po);
                }
                else
                {
                    purchaseEntry.PurchaseOrderID = po.ID;
                    db.purchaseentries.Add(purchaseEntry);
                }
                db.SaveChanges();

                // Once save is success update Products Inventory table
            }
            var purchaseEntries = db.purchaseentries.Include(p => p.purchaseorder);

            return(View("Index", purchaseEntries.ToList()));
        }