public IActionResult Index(Guid?guidInvoice) { var datas = _context.Tbinvoices.Include(t => t.GuidcourierNavigation).Include(t => t.GuidpaymentNavigation).Include(t => t.GuidsalesNavigation).Include(t => t.TbinvoiceDetails); var data = new Tbinvoice(); if (guidInvoice != null) { data = datas.FirstOrDefault(t => t.Guidinvoice == guidInvoice); } else { data = datas.FirstOrDefault(); } if (data == null) { return(NotFound()); } ViewData["invoiceNumbers"] = new SelectList(_context.Tbinvoices, "Guidinvoice", "InvoiceNumber"); var subtotal = data.TbinvoiceDetails.Sum(x => x.UnitPrice * x.Qty); var courierFee = data.TbinvoiceDetails.Sum(x => x.Weight) * data.GuidcourierNavigation.Cost; ViewData["subTotal"] = subtotal; ViewData["courierFee"] = courierFee; ViewData["total"] = subtotal + courierFee; return(View(data)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Guidinvoice,InvoiceDate,Guidsales,Guidcourier,Guidpayment,ShipTo,TargetTo")] Tbinvoice tbinvoice) { if (id != tbinvoice.Guidinvoice) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tbinvoice); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TbinvoiceExists(tbinvoice.Guidinvoice)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Guidcourier"] = new SelectList(_context.Tbcouriers, "Guidcourier", "Guidcourier", tbinvoice.Guidcourier); ViewData["Guidpayment"] = new SelectList(_context.Tbpayments, "Guidpayment", "Guidpayment", tbinvoice.Guidpayment); ViewData["Guidsales"] = new SelectList(_context.Tbsales, "Guidsales", "Guidsales", tbinvoice.Guidsales); return(View(tbinvoice)); }
public async Task <IActionResult> Create([Bind("Guidinvoice,InvoiceDate,Guidsales,Guidcourier,Guidpayment,ShipTo,TargetTo")] Tbinvoice tbinvoice) { if (ModelState.IsValid) { var counter = _context.Tbinvoices.Count() + 1; tbinvoice.InvoiceNumber = "INV-" + counter; tbinvoice.Guidinvoice = Guid.NewGuid(); _context.Add(tbinvoice); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Guidcourier"] = new SelectList(_context.Tbcouriers, "Guidcourier", "Guidcourier", tbinvoice.Guidcourier); ViewData["Guidpayment"] = new SelectList(_context.Tbpayments, "Guidpayment", "Guidpayment", tbinvoice.Guidpayment); ViewData["Guidsales"] = new SelectList(_context.Tbsales, "Guidsales", "Guidsales", tbinvoice.Guidsales); return(View(tbinvoice)); }