public ActionResult AddBillsContent(BillsContent _BillContent, Bills _bill, string barcodeProduct, Produt_Price pro_price, int Quantity, string Client_ID) { bool res = s.Users(); if (res == true) { if (Session["flag"].ToString() == "true") { _bill.date = DateTime.Now; var ClintID = _db.Clients.Where(p => p.name == Client_ID).FirstOrDefault(); _bill.Client_ID = ClintID.Client_ID; Session["CLientID"] = ClintID.Client_ID; _bill.Cate_Id = 1; _bill.User_ID = int.Parse(Session["userID"].ToString()); _bill.Viewed = true; _db.Bills.Add(_bill); _db.SaveChanges(); } var LastId = _db.Bills.OrderByDescending(u => u.Id).FirstOrDefault(); _BillContent.Bill_ID = LastId.Id; // _BillContent.Price = price; _BillContent.Quantity = _BillContent.Quantity; var prodids = _db.Products.Where(d => d.name == barcodeProduct).Select(f => f.Pro_id).FirstOrDefault(); _BillContent.Product_ID = prodids; _BillContent.Cost = _db.Produt_Price.Where(s => s.Pro_ID == prodids).Select(p => p.cost).FirstOrDefault(); _BillContent.Viewed = true; _db.BillsContent.Add(_BillContent); _db.SaveChanges(); //edit quntity var proQuantity = _db.Produt_Price.Where(s => s.Pro_ID == prodids).FirstOrDefault(); Produt_Price model = _db.Produt_Price.Find(proQuantity.Prd_Pri_ID); model.Quantity = model.Quantity - Quantity; model.Store_Id = 1; model.Pro_ID = prodids; model.Minmum = model.Minmum; model.many_price = model.many_price; model.Price = model.Price; model.cost = model.cost; _db.Entry(model).State = EntityState.Modified; _db.SaveChanges(); Session["flag"] = "false"; return(RedirectToAction("Purchases")); } return(RedirectToAction("HavntAccess", "Employee")); }
public JsonResult FillBills() { List <BillsContent> list = new List <BillsContent>(); // List<BillsWithExten> list = new List<BillsWithExten>(); int UserId = int.Parse(Session["userID"].ToString()); var mo = _db.Bills.Where(p => p.User_ID == UserId && p.Viewed == true).ToList(); var lastIDInBIlls = mo.OrderByDescending(p => p.Id).FirstOrDefault(); var obj = _db.BillsContent.Where(ss => ss.Bill_ID == lastIDInBIlls.Id && ss.IsDeleted == false && ss.Viewed == true).ToList(); if (obj != null && obj.Count() > 0) { foreach (var item in obj) { BillsContent model = new BillsContent(); model.Product_ID = item.Product_ID; model.BillsContent_ID = item.BillsContent_ID; model.Price = item.Price; model.Quantity = item.Quantity; model.IsDeleted = item.IsDeleted; list.Add(model); } } return(Json(list, JsonRequestBehavior.AllowGet)); }
// gitt bill by id for edit #region edite record public JsonResult GetBillById(int BillsContent_ID) { BillsContent model = _db.BillsContent.Where(x => x.BillsContent_ID == BillsContent_ID).SingleOrDefault(); string value = string.Empty; value = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); return(Json(value, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveBillData(BillsContent model) { bool result = true; try { _db.BillsContent.Add(model); _db.SaveChanges(); } catch (Exception ex) { throw ex; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult saveReturnFatora(BillsContent content, string pro, Produt_Price pro_price, int Quantity, int price, int Bill_ID, Bills bill) { // bool result = true; int userID = int.Parse(Session["userID"].ToString()); // printer name string PrinterID = _db.Users.Where(d => d.Id == userID).Select(f => f.printer_name).FirstOrDefault(); string printerName = _db.PrintType.Where(id => id.ID.ToString() == PrinterID).Select(f => f.PrinterName).FirstOrDefault(); content.Price = price; var GetProID = _db.Products.Where(i => i.name == pro).FirstOrDefault(); content.Product_ID = GetProID.Pro_id; content.Quantity = -1 * Quantity; _db.BillsContent.Add(content); _db.SaveChanges(); //edit quantity pro_price = _db.Produt_Price.Where(p => p.Pro_ID == GetProID.Pro_id).FirstOrDefault(); pro_price.Quantity = pro_price.Quantity + Quantity; _db.Entry(pro_price).State = EntityState.Modified; _db.SaveChanges(); //edit all price decimal res = 0; var model = _db.BillsContent.Where(s => s.Bill_ID == Bill_ID).ToList(); foreach (var item in model) { res += item.Quantity * item.Price; } bill = _db.Bills.Where(p => p.Id == Bill_ID).FirstOrDefault(); bill.price = res; _db.Entry(bill).State = EntityState.Modified; _db.SaveChanges(); var usernameID = _db.Bills.Where(d => d.Id == Bill_ID).Select(f => f.User_ID).FirstOrDefault(); //print ReportDocument rd = new ReportDocument(); rd.Load(Path.Combine(Server.MapPath("~/Report/ReturnBill.rpt"))); rd.SetDataSource(_db.BillsContent.Where(d => d.Bill_ID == Bill_ID).Select(p => new { id = p.Bill_ID, Quantity = Quantity, Price = price, User_ID = _db.Users.Where(d => d.Id == usernameID).Select(f => f.name).FirstOrDefault(), Pro_ID = pro, Expr2 = price * Quantity, //info many_price = _db.PLaceInfo.Select(f => f.Img).FirstOrDefault(), active = _db.PLaceInfo.Select(f => f.PlaceName).FirstOrDefault(), status = _db.PLaceInfo.Select(f => f.Number).FirstOrDefault(), }).ToList()); Response.Buffer = false; Response.ClearContent(); Response.ClearHeaders(); Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); stream.Seek(0, SeekOrigin.Begin); rd.PrintOptions.PrinterName = printerName; rd.PrintToPrinter(1, false, 0, 0); rd.Refresh(); return(RedirectToAction("ReturnBill")); //return File(stream, "aaplication/pdf", "فاتوره بيع.pdf"); }