public async Task <ActionResult <InvoicesDTO> > addInvoice(int inUserID, string discountCode = null) { Users user = await db.Users.FindAsync(inUserID); if (user == null) { return(new JsonResult(new { Status = "error", Message = "User Not Found" })); } Invoices invoices = new Invoices { User = user, UserID = user.Id, tax = 0, total = 0, isFreeShipping = false, created_at = DateTime.Now, updated_at = DateTime.Now }; if (discountCode != null) { DiscountCodes discCodes = await db.DiscountCodes.Where(ds => ds.code.Equals(discountCode.ToUpper())).FirstOrDefaultAsync(); if (discCodes != null) { invoices.discount_code = discCodes.code; invoices.discount_percentage = discCodes.percentage; } } db.Invoices.Add(invoices); try { await db.SaveChangesAsync(); } catch (Exception e) { return(new JsonResult(new { Status = "error", Message = "Error creating invoice" })); } InvoicesDTO invcDTO = new InvoicesDTO { Id = invoices.Id, total = invoices.total, tax = invoices.tax, discount_code = invoices.discount_code, discount_percentage = invoices.discount_percentage, isFreeShipping = invoices.isFreeShipping, UserID = invoices.UserID, created_at = invoices.created_at, updated_at = invoices.created_at, invoiceItems = null }; return(new JsonResult(new { Status = "success", Message = invcDTO })); }
protected void btnPrint_Click(object sender, EventArgs e) { InvoicesDTO dto = (InvoicesDTO)Session["invoiceDTO"]; ModelFacade facade = new ModelFacade(); Invoices invoice = facade.createInvoice(dto); InvoicesDAO dao = new InvoicesDAO(); dao.saveInvoice(invoice); Session.Abandon(); Response.Redirect("~/Staff/AdminHome.aspx"); }
public async Task <IActionResult> Edit(int id, [Bind("Id, Invoiced, StaffAccountId, UserAccountId")] Invoice invoice) { if (id != invoice.Id) { return(NotFound()); } //need to alter the staff account to whoever invoiced it if (ModelState.IsValid) { try { _context.Update(invoice); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvoiceExists(invoice.Id)) { return(NotFound()); } else { throw; } } } InvoicesDTO invoices = new InvoicesDTO { Id = invoice.Id, Invoiced = invoice.Invoiced, StaffAccountId = invoice.StaffAccountId, UserAccountId = invoice.UserAccountId }; try { var response = await _invoicesService.PushInvoices(invoices); } catch (Exception e) { //_logger.LogWarning(e); } return(RedirectToAction(nameof(Index))); }
private void getSessionData() { InvoicesDTO dto = (InvoicesDTO)Session["invoiceDTO"]; ModelFacade facade = new ModelFacade(); Invoices invoice = facade.createInvoice(dto); lblDateIssued.Text = invoice.dateIssued; lblinvoiceID.Text = invoice.invoiceID; lblJobID.Text = invoice.jobID; lblCustID.Text = invoice.custID; lblCustName.Text = invoice.custName + " " + invoice.custSurname; lblItemID.Text = invoice.itemID; lblTechID.Text = invoice.techID; lblTechName.Text = invoice.techName; lblHoursWorked.Text = invoice.hoursWorked; lblTotalDue.Text = "R " + invoice.billAmount; }
public Invoices createInvoice(InvoicesDTO dto) { Invoices invoice = new Invoices(); invoice.invoiceID = dto.invoiceID; invoice.jobID = dto.jobID; invoice.custID = dto.custID; invoice.custName = dto.custName; invoice.custSurname = dto.custSurname; invoice.itemID = dto.invoiceID; invoice.techID = dto.techID; invoice.techName = dto.techName; invoice.hoursWorked = dto.hoursWorked; invoice.billAmount = dto.billAmount; invoice.dateIssued = dto.dateIssued; return(invoice); }
public async Task <ActionResult <InvoicesDTO> > addItem(int inInvoiceID, int inProductOptionID, int inQuantity) { Invoices invoice = await db.Invoices.FindAsync(inInvoiceID); if (invoice == null) { return(new JsonResult(new { Status = "error", Message = "No Invoices With The Id: " + inInvoiceID })); } ProductOptions prodOpt = await db.ProductOptions.FindAsync(inProductOptionID); if (prodOpt == null) { return(new JsonResult(new { Status = "error", Message = "No Product Option With The Id: " + inProductOptionID })); } Products prod = await db.Products.FindAsync(prodOpt.ProductID); if (prod == null) { return(new JsonResult(new { Status = "error", Message = "No Product With The Id: " + prodOpt.ProductID })); } prodOpt.Product = prod; if (inQuantity < 1) { return(new JsonResult(new { Status = "error", Message = "Quantity Can't be less than 1" })); } InvoiceItems invoiceItems = new InvoiceItems { InvoiceID = invoice.Id, ProductOptionID = prodOpt.Id, prod_name = prodOpt.Product.name, prod_desc = prodOpt.Product.desc, prod_region = prodOpt.Product.region, prod_roast = prodOpt.Product.roast, prod_altitude_max = prodOpt.Product.altitude_max, prod_altitude_min = prodOpt.Product.altitude_min, prod_bean_type = prodOpt.Product.bean_type, prod_image_url = prodOpt.Product.image_url, opt_price = prodOpt.price, opt_weight = prodOpt.weight, quantity = inQuantity }; db.InvoiceItems.Add(invoiceItems); try { await db.SaveChangesAsync(); } catch (Exception e) { return(new JsonResult(new { Status = "error", Message = "Error adding item to invoice" })); } try { updateTotalInvoice(invoice.Id, invoiceItems.opt_price, invoiceItems.quantity); } catch (Exception e) { return(new JsonResult(new { Status = "error", Message = e })); } InvoicesDTO invcDTO = new InvoicesDTO { Id = invoice.Id, total = invoice.total, UserID = invoice.UserID, discount_code = invoice.discount_code, discount_percentage = invoice.discount_percentage, isFreeShipping = invoice.isFreeShipping, tax = invoice.tax, created_at = invoice.created_at, updated_at = invoice.created_at }; InvoiceItemsDTO invoiceItemsDTO = new InvoiceItemsDTO { Id = invoiceItems.Id, InvoiceID = invoice.Id, ProductOptionID = prodOpt.Id, prod_name = prodOpt.Product.name, prod_desc = prodOpt.Product.desc, prod_region = prodOpt.Product.region, prod_roast = prodOpt.Product.roast, prod_altitude_max = prodOpt.Product.altitude_max, prod_altitude_min = prodOpt.Product.altitude_min, prod_bean_type = prodOpt.Product.bean_type, prod_image_url = prodOpt.Product.image_url, opt_price = prodOpt.price, opt_weight = prodOpt.weight, quantity = inQuantity }; if (invcDTO.invoiceItems == null) { List <InvoiceItemsDTO> tempList = new List <InvoiceItemsDTO>(); tempList.Add(invoiceItemsDTO); invcDTO.invoiceItems = tempList; } else { invcDTO.invoiceItems.Add(invoiceItemsDTO); } return(new JsonResult(new { Status = "success", Message = invcDTO })); }