//find Purchase Order by id public static List <PurchaseOrderDetailModel> GetPurchaseOrderDetailByID(int poid, out string error) { LUSSISEntities entities = new LUSSISEntities(); error = ""; purchaseorder po = new purchaseorder(); List <PurchaseOrderDetailModel> podms = new List <PurchaseOrderDetailModel>(); try { po = entities.purchaseorders.Where(a => a.poid == poid).FirstOrDefault <purchaseorder>(); foreach (purchaseorderdetail pod in po.purchaseorderdetails) { podms.Add(ConvertDBtoAPIPOModel(pod)); } } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(podms); }
public ActionResult AddProductDetails(string submitAction, PurchaseOrderVM purchaseOrderVM) { //Remove first template record. purchaseOrderVM._orderDetail.RemoveAt(0); if (ModelState.IsValid) { purchaseorder po = new purchaseorder(); po.SupplierID = purchaseOrderVM.purchaseOrder.SupplierID; po.PurchaseOrderNo = purchaseOrderVM.purchaseOrder.PurchaseOrderNo; if (purchaseOrderVM.purchaseOrder.ID != 0) { po.ID = purchaseOrderVM.purchaseOrder.ID; } po.IsPurcheseEntry = false; // set this is false for Purchase Order foreach (var od in purchaseOrderVM._orderDetail) { if (od.ProductID == 0) { continue; } if (db.orderdetails.Where(x => x.PurchaseOrderID == purchaseOrderVM.purchaseOrder.ID && x.ProductID == od.ProductID).ToList().Count > 0) { continue; } po.orderdetails.Add(od); } db.purchaseorders.Add(po); db.SaveChanges(); var poList = db.purchaseorders.ToList(); return(View("Index", poList)); } return(View("Create", purchaseOrderVM)); }
//Update PurchaseOrder public static PurchaseOrderModel UpdatePurchaseOrder(PurchaseOrderModel pom, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); purchaseorder po = new purchaseorder(); try { po = entities.purchaseorders.Where(p => p.poid == pom.PoId).FirstOrDefault <purchaseorder>(); po.purchasedby = pom.Purchasedby; po.supid = pom.Supid; po.status = pom.Status; entities.SaveChanges(); pom = GetPurchaseOrderByID(po.poid, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(pom); }
//Create new PurchaseOrder public static PurchaseOrderModel CreatePurchaseOrder(PurchaseOrderModel pom, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); purchaseorder po = new purchaseorder(); List <purchaseorderdetail> pods = new List <purchaseorderdetail>(); try { po.purchasedby = pom.Purchasedby; po.supid = pom.Supid; po.podate = DateTime.Now; po.status = pom.Status; po = entities.purchaseorders.Add(po); entities.SaveChanges(); pom = GetPurchaseOrderByID(po.poid, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(pom); }
public ActionResult DeleteConfirmed(int id) { purchaseorder purchaseOrder = db.purchaseorders.Find(id); db.purchaseorders.Remove(purchaseOrder); db.SaveChanges(); return(RedirectToAction("Index")); }
// Convert From Auto Generated DB Model to APIModel private static PurchaseOrderModel ConvertDBtoAPIPOModel(purchaseorder po) { List <PurchaseOrderDetailModel> podms = new List <PurchaseOrderDetailModel>(); foreach (purchaseorderdetail pod in po.purchaseorderdetails) { podms.Add(new PurchaseOrderDetailModel(pod.poid, pod.itemid, pod.item.description, pod.qty, pod.delivqty, pod.item.category.name, pod.item.uom, pod.price as double?)); } PurchaseOrderModel pom = new PurchaseOrderModel(po.poid, po.purchasedby, po.user.fullname, po.supid, po.supplier.supname, po.podate, po.status, podms); return(pom); }
public ActionResult Edit(/*[Bind(Include = "ID,PurchaseOrderNo,SupplierID,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy")]*/ PurchaseOrderVM purchaseOrderVM) { purchaseorder purchaseOrder = new purchaseorder(); purchaseOrder = purchaseOrderVM.purchaseOrder; if (ModelState.IsValid) { db.Entry(purchaseOrder).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(purchaseOrder)); }
// GET: purchaseorders/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } purchaseorder purchaseOrder = db.purchaseorders.Find(id); if (purchaseOrder == null) { return(HttpNotFound()); } return(View(purchaseOrder)); }
public ActionResult Create(/*[Bind(Include = "ID,PurchaseOrderNo,SupplierID,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy")] */ PurchaseOrderVM purchaseOrderVM) { purchaseorder purchaseOrder = new purchaseorder(); purchaseOrder = purchaseOrderVM.purchaseOrder; purchaseOrder.orderdetails = purchaseOrderVM._orderDetail; if (ModelState.IsValid) { db.purchaseorders.Add(purchaseOrder); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(purchaseOrder)); }
// GET: purchaseorders/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } purchaseorder purchaseOrder = db.purchaseorders.Find(id); if (purchaseOrder == null) { return(HttpNotFound()); } ViewBag.SupplierID = new SelectList(db.suppliers, "ID", "OrganizationName"); ViewBag.suppliers = db.suppliers.ToList(); ViewBag.ProductID = new SelectList(db.products, "ID", "Name"); var purchaseOrderVM = new PurchaseOrderVM(); purchaseOrderVM.purchaseOrder = purchaseOrder; purchaseOrderVM._orderDetail = db.orderdetails.Where(x => x.PurchaseOrderID == id).ToList(); purchaseOrderVM._orderDetail.Insert(0, new orderdetail { }); return(View("Create", purchaseOrderVM)); }
//find Purchase Order by id public static PurchaseOrderModel GetPurchaseOrderByID(int poid, out string error) { LUSSISEntities entities = new LUSSISEntities(); error = ""; purchaseorder po = new purchaseorder(); PurchaseOrderModel pom = new PurchaseOrderModel(); try { po = entities.purchaseorders.Where(a => a.poid == poid).FirstOrDefault <purchaseorder>(); pom = ConvertDBtoAPIPOModel(po); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(pom); }
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())); }