コード例 #1
0
        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"));
        }
コード例 #2
0
        //public JsonResult SaveDataInDatabase(Produt_Price model, bool active)
        //{
        //    var result = false;
        //    try
        //    {
        //        Produt_Price pro = _db.Produt_Price.SingleOrDefault(x => x.Prd_Pri_ID == model.Prd_Pri_ID);
        //        pro.cost = model.cost;
        //        pro.Price = model.Price;
        //        pro.Quantity = model.Quantity;
        //        pro.Minmum = model.Minmum;
        //        pro.Discount = model.Discount;
        //        pro.many_price = model.many_price;
        //        pro.active = model.active;

        //        pro.Pro_ID = model.Pro_ID;
        //        _db.SaveChanges();


        //        result = true;
        //    }

        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }

        //    return Json(result, JsonRequestBehavior.AllowGet);
        //}
        #endregion

        #region  save new product

        public JsonResult SaveProduct(string Cat, string barcode, string name, decimal?cost, decimal?Price, decimal?Quantity, decimal?Minmum, decimal?Discount, bool active)
        {
            Products modelProduct = new Products();

            modelProduct.name    = name;
            modelProduct.barcode = barcode;
            //  modelProduct.active = active ??default(bool);
            modelProduct.Cate_ID = _db.ProductCategory.Where(p => p.name == Cat).Select(f => f.Cate_ID).FirstOrDefault();

            _db.Products.Add(modelProduct);
            _db.SaveChanges();

            Produt_Price modelPrice = new Produt_Price();

            modelPrice.Pro_ID = modelProduct.Pro_id;

            modelPrice.cost     = cost ?? default(decimal);
            modelPrice.Price    = Price ?? default(decimal);
            modelPrice.Quantity = Quantity ?? default(decimal);
            modelPrice.Minmum   = Minmum ?? default(decimal);
            modelPrice.Discount = Discount ?? default(decimal);
            modelPrice.active   = active;
            _db.Produt_Price.Add(modelPrice);

            _db.SaveChanges();
            bool result = true;


            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public JsonResult GetBillById(int Pro_id)
        {
            Produt_Price model = _db.Produt_Price.Where(x => x.Pro_ID == Pro_id).SingleOrDefault();
            string       value = string.Empty;

            value = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });
            return(Json(value, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public JsonResult ReturnValue(int Pro_id)
        {
            List <Produt_Price> result = new List <Produt_Price>();

            var model = _db.Produt_Price.Where(i => i.Pro_ID == Pro_id);

            // decimal result = model.Quantity;
            foreach (var item in model)
            {
                Produt_Price mo = new Produt_Price();
                mo.Prd_Pri_ID = item.Prd_Pri_ID;
                mo.Quantity   = item.Quantity;
                mo.Minmum     = item.Minmum;
                mo.cost       = item.cost;
                mo.Price      = item.Price;
                result.Add(mo);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public JsonResult ReturnValueByName(string name)
        {
            List <Produt_Price> result = new List <Produt_Price>();

            var model  = _db.Products.Where(i => i.name == name).FirstOrDefault();
            var model2 = _db.Produt_Price.Where(i => i.Pro_ID == model.Pro_id).ToList();

            // decimal result = model.Quantity;
            foreach (var item in model2)
            {
                Produt_Price mo = new Produt_Price();
                mo.Prd_Pri_ID = item.Prd_Pri_ID;
                mo.Quantity   = item.Quantity;
                mo.Minmum     = item.Minmum;
                mo.cost       = item.cost;
                mo.Price      = item.Price;
                result.Add(mo);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        public JsonResult DeleteContentRecordOfBuy(int BillsContent_ID, Produt_Price _proPrice)
        {
            bool result = false;
            var  Stu    = _db.BillsContent.SingleOrDefault(x => x.BillsContent_ID == BillsContent_ID);
            var  model  = _db.Produt_Price.Where(p => p.Pro_ID == Stu.Product_ID).FirstOrDefault();

            if (Stu != null)
            {
                Stu.IsDeleted = true;
                _db.SaveChanges();

                model.Quantity = model.Quantity - Stu.Quantity;

                _db.Entry(model).State = EntityState.Modified;
                _db.SaveChanges();

                result = true;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
        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");
        }