public IActionResult AutoReorder(int[] SelectedBooks, int QuantityOrdered) { Invoice i = new Invoice(); foreach (int bookid in SelectedBooks) { Book book = _context.Books.FirstOrDefault(b => b.BookID == bookid); InvoiceDet ivd = new InvoiceDet(); ivd.Invoice = i; ivd.Book = book; ivd.QuantityOrdered = QuantityOrdered; ivd.BookCost = book.Cost; ivd.QuantityArrived = 0; AppUser user = _context.Users.FirstOrDefault(o => o.UserName == User.Identity.Name); ivd.User = user; if (ModelState.IsValid) { _context.InvoiceDets.Add(ivd); _context.SaveChanges(); } } i.ProDatePlaced = DateTime.Today; _context.Update(i); _context.SaveChanges(); return(RedirectToAction("Details", new { id = i.InvoiceID })); }
public IActionResult ManualReorder(InvoiceDet idet) { Book book = _context.Books.Include(b => b.Genre) .Include(b => b.InvoiceDets) .ThenInclude(b => b.Invoice) .FirstOrDefault(b => b.BookID == idet.Book.BookID); //need to change this to add to weighted average book.Cost = idet.BookCost; idet.Book = book; idet.QuantityArrived = 0; Invoice inv = _context.Invoices.Find(idet.Invoice.InvoiceID); idet.Invoice = inv; AppUser user = _context.Users.FirstOrDefault(o => o.UserName == User.Identity.Name); idet.User = user; ModelState.Clear(); this.TryValidateModel(idet); if (ModelState.IsValid) { _context.InvoiceDets.Add(idet); _context.SaveChanges(); return(RedirectToAction("Details", new { id = idet.Invoice.InvoiceID })); } return(View(idet)); }
public async Task <IActionResult> Create([Bind("InvoiceDetID,QuantityOrdered,QuantityArrived,BookCost")] InvoiceDet invoiceDet) { if (ModelState.IsValid) { _context.Add(invoiceDet); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(invoiceDet)); }
public void AddItems(InvoiceDet a) { ProdNo = a.ProdNo; WhID = a.WhID; ProdPrice = a.ProdPrice; ProdNewPrice = a.ProdNewPrice; Units = a.Units; Sales = a.Sales; Discount = a.Discount; IVU = a.IVU; }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } InvoiceDet = await _context.InvoiceDet.FirstOrDefaultAsync(m => m.Id == id); if (InvoiceDet == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } InvoiceDet = await _context.InvoiceDet.FindAsync(id); if (InvoiceDet != null) { _context.InvoiceDet.Remove(InvoiceDet); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// GET: InvoiceDets/Edit/5 public IActionResult Edit(int?id) { if (id == null) { return(NotFound()); } InvoiceDet invoiceDet = _context.InvoiceDets .Include(i => i.Invoice) .Include(i => i.Book) .FirstOrDefault(i => i.InvoiceDetID == id); if (invoiceDet == null) { return(NotFound()); } return(View(invoiceDet)); }
public IActionResult ManualReorder(int?id) { if (id == null) { return(NotFound()); } Book book = _context.Books.Include(o => o.InvoiceDets) .ThenInclude(o => o.Invoice) .FirstOrDefault(o => o.BookID == id); if (book == null) { return(NotFound()); } //find an invoice that hasn't been completed Invoice curInv = _context.Invoices .FirstOrDefault(i => i.ProDatePlaced == default(DateTime)); //if every invoice has been completed, create a new one if (curInv == null) { Invoice newInv = new Invoice(); //assign user property here? //might not need to know who created the invoice since invoicedets has that info InvoiceDet idet = new InvoiceDet(); idet.Book = book; idet.BookCost = book.Cost; idet.Invoice = newInv; _context.Add(newInv); _context.SaveChanges(); return(View(idet)); } //if an invoice has not been completed yet else { InvoiceDet idet = new InvoiceDet(); idet.Book = book; idet.BookCost = book.Cost; idet.Invoice = curInv; return(View(idet)); } }
public IActionResult Edit(InvoiceDet invoiceDet) { if (ModelState.IsValid) { try { InvoiceDet ivd = _context.InvoiceDets .Include(i => i.Invoice) .Include(i => i.Book) .FirstOrDefault(i => i.InvoiceDetID == invoiceDet.InvoiceDetID); Book book = _context.Books.Find(ivd.Book.BookID); Int32 NumBooksLeft = ivd.QuantityOrdered - ivd.QuantityArrived; //user inputs a quantity lower than what's needed to complete the invoicedet if (invoiceDet.QuantityArrived < NumBooksLeft) { ivd.Book.Inventory = ivd.Book.Inventory + invoiceDet.QuantityArrived; invoiceDet.QuantityArrived = ivd.QuantityArrived + invoiceDet.QuantityArrived; ivd.QuantityArrived = invoiceDet.QuantityArrived; ivd.QuantityOrdered = invoiceDet.QuantityOrdered; ivd.BookCost = invoiceDet.BookCost; book.Cost = invoiceDet.BookCost; _context.Update(ivd); _context.SaveChanges(); return(RedirectToAction(nameof(BooksOnOrder))); } //user inputs a quantity equal to or greater than what's needed to complete the invoicedet else { ivd.Book.Inventory = ivd.Book.Inventory + NumBooksLeft; ivd.QuantityArrived = invoiceDet.QuantityOrdered; ivd.QuantityOrdered = invoiceDet.QuantityOrdered; ivd.BookCost = invoiceDet.BookCost; //change to weighted average book.Cost = invoiceDet.BookCost; _context.Update(ivd); _context.SaveChanges(); Invoice i = _context.Invoices.Include(n => n.InvoiceDets).FirstOrDefault(n => n.InvoiceID == ivd.Invoice.InvoiceID); Int32 qtyarr = 0; Int32 qtyord = 0; foreach (InvoiceDet id in i.InvoiceDets) { qtyarr = qtyarr + id.QuantityArrived; qtyord = qtyord + id.QuantityOrdered; } if (qtyarr == qtyord) { i.ProDateArrived = DateTime.Today; _context.Update(i); _context.SaveChanges(); } return(RedirectToAction(nameof(BooksOnOrder))); } } catch (DbUpdateConcurrencyException) { if (!InvoiceDetExists(invoiceDet.InvoiceDetID)) { return(NotFound()); } else { throw; } } } return(View(invoiceDet)); }