public ActionResult Create(InvoiceVM model) { // Header var invoice = new invoice(); invoice.customerid = Int32.Parse(model.CustomerID); invoice.currencycode = model.Currency; invoice.adddate = DateTime.Now; invoice.editdate = DateTime.Now; // Detail List <invoicedetail> detailList = new List <invoicedetail>(); for (int i = 0; i < model.Detail.Count; i++) { var source = model.Detail[i]; var detail = new invoicedetail(); detail.itemcode = source.ItemCode; detail.price = source.Price; detail.quantity = source.Qty; detail.adddate = DateTime.Now; detail.editdate = DateTime.Now; detailList.Add(detail); } // Assign detail to header invoice.invoicedetail = detailList; db.invoice.Add(invoice); db.SaveChanges(); return(RedirectToAction("Index")); }
// PUT api/Invoicedetail/5 public HttpResponseMessage Putinvoicedetail(short id, invoicedetail invoicedetail) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != invoicedetail.invoicedetailsid) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Entry(invoicedetail).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public ActionResult Edit(InvoiceVM model) { int invoiceID = int.Parse(model.InvoiceID); // Remove Detail db.invoicedetail.RemoveRange(db.invoicedetail.Where(x => x.invoiceid == invoiceID)); // Insert Detail List <invoicedetail> detailList = new List <invoicedetail>(); for (int i = 0; i < model.Detail.Count; i++) { var source = model.Detail[i]; var detail = new invoicedetail(); detail.itemcode = source.ItemCode; detail.price = source.Price; detail.quantity = source.Qty; detail.itemcode = source.ItemCode; detail.adddate = DateTime.Now; detail.editdate = DateTime.Now; detailList.Add(detail); } db.invoice.Find(invoiceID).invoicedetail = detailList; // Update Header db.invoice.Find(invoiceID).customerid = int.Parse(model.CustomerID); db.invoice.Find(invoiceID).currencycode = model.Currency; db.SaveChanges(); return(RedirectToAction("Index")); }
private void HapusTSB_Click(object sender, EventArgs e) { if (dtGrid.RowCount < 0) { if (new invoiceCRUD().deleteData(txtGRNNO.Text)) { MessageBox.Show(" Items Receive telah di hapus "); } } else //delete detail { invoicedetail k = new invoicedetail(); dtGrid.EndEdit(); for (int i = 0; i < dtGrid.Rows.Count - 1; i++) { k.INVNO = txtGRNNO.Text; k.ID = Convert.ToInt32(dtGrid.Rows[i].Cells["hID1"].Value); if ((Convert.ToInt32(dtGrid.Rows[i].Cells["hDel"].Value) == 1) && (dtGrid.Rows[i].Cells["hID1"].Value != null)) { if (new invoicedetailCRUD().deleteData(k.INVNO, k.ID)) { dtGrid.Rows.RemoveAt(i); } else if ((dtGrid.Rows[i].Cells["hID1"].Value.ToString() == null)) { dtGrid.Rows.RemoveAt(i); } else { MessageBox.Show("gagal delete"); } } } } }
// DELETE api/Invoicedetail/5 public HttpResponseMessage Deleteinvoicedetail(short id) { invoicedetail invoicedetail = db.invoicedetails.Find(id); if (invoicedetail == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } db.invoicedetails.Remove(invoicedetail); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, invoicedetail)); }
// POST api/Invoiceheader public invoiceheader Postinvoiceheader(invoiceheader invoiceheader, myshelf myshelf, product product, string purchasetype, short days) { if (ModelState.IsValid) { db.invoiceheaders.Add(invoiceheader); db.SaveChanges(); InvoicedetailController InvoicedetailController = new Controllers.InvoicedetailController(); invoicedetail invoicedetail = new invoicedetail(); invoicedetail.invoiceheader_invoiceheaderid = invoiceheader.invoiceheaderid; invoicedetail.product_productid = myshelf.product_productid; if (purchasetype.Contains("rent")) { invoicedetail.amount = product.rentcost * days; invoiceheader.totalamount = product.rentcost * days; } else { invoicedetail.amount = Convert.ToInt32(product.price); } InvoicedetailController.Postinvoicedetail(invoicedetail, purchasetype); db.SaveChanges(); // HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, invoiceheader); // response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = invoiceheader.invoiceheaderid })); return(invoiceheader); } else { return(invoiceheader); //return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// POST api/Invoicedetail public invoicedetail Postinvoicedetail(invoicedetail invoicedetail, string purchasetype) { double amt = 0; if (ModelState.IsValid) { db.invoicedetails.Add(invoicedetail); db.SaveChanges(); BeneficiarycalculationController BeneficiarycalculationController = new Controllers.BeneficiarycalculationController(); beneficiarycalculation beneficiarycalculation = new Models.beneficiarycalculation(); List <productbeneficiary> list = db.productbeneficiaries.ToList(); List <productbeneficiary> productbeneficiarylist = (from l in list where l.product_productid == invoicedetail.product_productid select l).ToList <productbeneficiary>(); foreach (var i in productbeneficiarylist) { beneficiarycalculation.purchasetype = purchasetype; amt = invoicedetail.amount * i.royalty / 100; beneficiarycalculation.royaltyamt = amt; beneficiarycalculation.productbeneficiary_productbeneficiaryid = i.productbeneficiaryid; beneficiarycalculation.invoicedetails_invoicedetailsid = invoicedetail.invoicedetailsid; BeneficiarycalculationController.Postbeneficiarycalculation(beneficiarycalculation); } return(invoicedetail); } else { return(invoicedetail); } }
// GET api/Invoicedetail public IList <invoicedetail> Getinvoicedetails() { var x = (from m in db.invoicedetails select new { invoicedetailsid = m.invoicedetailsid, amount = m.amount, product_productid = m.product_productid, invoiceheader_invoiceheaderid = m.invoiceheader_invoiceheaderid }); IList <invoicedetail> list = new List <invoicedetail>(); foreach (var a in x) { invoicedetail m = new invoicedetail(); m.invoicedetailsid = a.invoicedetailsid; m.amount = a.amount; m.product_productid = a.product_productid; m.invoiceheader_invoiceheaderid = a.invoiceheader_invoiceheaderid; list.Add(m); } return(list); }
//myshetlf add to cart receiving an array list public HttpResponseMessage Postmyshelf(short days, myshelf[] myshelfarr) { int cnt = 0; short invheaderid = 0; double sumamt = 0; if (ModelState.IsValid) { foreach (myshelf myshelf in myshelfarr) { ProductController ProductController = new Controllers.ProductController(); product product = ProductController.Getproduct(myshelf.product_productid); sumamt = sumamt + product.price; } foreach (myshelf myshelf in myshelfarr) { myshelf.purchasedate = DateTime.Now; if (myshelf.purchasetype.Equals("purchase")) { myshelf.enddate = null; // myshelf.enddate = Convert.ToDateTime(999912312); } else { myshelf.enddate = myshelf.purchasedate.Value.AddDays(days); } ProductController ProductController = new Controllers.ProductController(); product product = ProductController.Getproduct(myshelf.product_productid); if (cnt == 0) { InvoiceheaderController InvoiceheaderController = new InvoiceheaderController(); invoiceheader invoiceheader = new Models.invoiceheader(); invoiceheader.date = DateTime.Now; invoiceheader.totalamount = sumamt; invoiceheader.customer_customerid = myshelf.customer_customerid; invoiceheader = InvoiceheaderController.Postinvoiceheader(invoiceheader, myshelf, product, myshelf.purchasetype, days); myshelf.invoiceheader_invoiceheaderid = invoiceheader.invoiceheaderid; invheaderid = invoiceheader.invoiceheaderid; myshelf.invoiceheader_invoiceheaderid = invoiceheader.invoiceheaderid; cnt++; db.myshelves.Add(myshelf); db.SaveChanges(); } else { InvoicedetailController InvoicedetailController = new Controllers.InvoicedetailController(); invoicedetail invoicedetail = new invoicedetail(); invoicedetail.invoiceheader_invoiceheaderid = invheaderid; invoicedetail.product_productid = myshelf.product_productid; invoicedetail.amount = product.price; InvoicedetailController.Postinvoicedetail(invoicedetail, myshelf.purchasetype); myshelf.invoiceheader_invoiceheaderid = invheaderid; db.myshelves.Add(myshelf); db.SaveChanges(); } } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, myshelfarr); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
private void SimpanTSB_Click(object sender, EventArgs e) { //simpan header invoice k = new invoice(); Generate gen = new Generate(); txtGRNNO.Text = gen.genGRN(); k.PONO = txtJONO.Text; k.INVNO = txtGRNNO.Text; k.DATE = dateCreated.Value; DataRow selectedDIV = ((DataRowView)cbDIV.SelectedItem).Row; k.GDIV = selectedDIV["DIVID"].ToString(); k.APPROVE = 0; k.APPROVEBY = ""; k.CLOSE = 0; k.COLORID = ""; k.CUSTVENDCODE = txtCustomerID.Text; k.DOCREGNO = ""; k.OFFICER = GlobalVariables.GUserID; k.RECEIVEFROM = "CMT";// from PO k.REFFNO = txtRefer.Text; k.REMARKS = txtRemarks.Text; k.STOREID = cbStore.Text; k.JENIS = cbJENIS.Text; // k.STYLEID=""; if ((txtGRNNO.Text == "")) { MessageBox.Show("Isian Belum lengkap untuk PONO"); } else if (new invoiceCRUD().insertData(k)) { invoicedetail d = new invoicedetail(); dtGrid.EndEdit(); for (int i = 0; i < dtGrid.Rows.Count - 1; i++) { d.PONO = txtJONO.Text; d.INVNO = txtGRNNO.Text; d.ID = Convert.ToInt32(dtGrid.Rows[i].Cells["hID"].Value); //Convert.ToInt32(dtGrid.Rows[i].Cells["hCostingID"].Value); d.ITEMSID = dtGrid.Rows[i].Cells["hItemsID"].Value == null ? null : dtGrid.Rows[i].Cells["hItemsID"].Value.ToString(); d.DESCRIPTION = dtGrid.Rows[i].Cells["hDescription"].Value == null ? null : dtGrid.Rows[i].Cells["hDescription"].Value.ToString().ToString(); d.QUANTITY = Convert.ToDecimal(dtGrid.Rows[i].Cells["hQuantity"].Value); d.UOM = dtGrid.Rows[i].Cells["hUOM"].Value == null ? null : dtGrid.Rows[i].Cells["hUOM"].Value.ToString(); d.COLORID = dtGrid.Rows[i].Cells["hColorID"].Value == null ? null : dtGrid.Rows[i].Cells["hColorID"].Value.ToString(); d.GRADE = dtGrid.Rows[i].Cells["hGrade"].Value == null ? null : dtGrid.Rows[i].Cells["hGrade"].Value.ToString(); d.JENIS = cbJENIS.Text; d.SIZEID = Convert.ToString(dtGrid.Rows[i].Cells["hSizeID"].Value); d.STYLEID = dtGrid.Rows[i].Cells["hStyleID"].Value == null ? null : dtGrid.Rows[i].Cells["hStyleID"].Value.ToString(); if (dtGrid.Rows[i].HeaderCell.Value.ToString() == "#") { if (new invoicedetailCRUD().insertData(d)) { dtGrid.Rows[i].HeaderCell.Value = "V"; } else { } } } MessageBox.Show("Data berhasil di tambahkan"); SimpanTSB.Enabled = false; UbahTSB.Enabled = true; dtGrid.Enabled = true; // Binding(); } else { MessageBox.Show("Data gagal ditambahkan"); } //simpang detail }