public ActionResult DeleteConfirmed(int id) { purchaseentry purchaseEntry = db.purchaseentries.Find(id); db.purchaseentries.Remove(purchaseEntry); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,PurchaseOrderID,InvoiceChallan,InvoiceChallanNo,InvoiceDate,CGST,SGST,DiscountAmount,TotalAmount,DueAmount,Status,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy")] purchaseentry purchaseEntry) { if (ModelState.IsValid) { db.Entry(purchaseEntry).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PurchaseOrderID = new SelectList(db.purchaseorders, "ID", "PurchaseOrderNo", purchaseEntry.PurchaseOrderID); return(View(purchaseEntry)); }
// GET: purchaseentries/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } purchaseentry purchaseEntry = db.purchaseentries.Find(id); if (purchaseEntry == null) { return(HttpNotFound()); } return(View(purchaseEntry)); }
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())); }