Exemple #1
0
        public ActionResult AddDetail(int ImportID = 0, int ItemID = 0, int Qty = 0, decimal Price = 0)
        {
            var import = db.tbl_Imports.Find(ImportID);
            tbl_ImportDetail detail = import.tbl_ImportDetail.Where(a => a.ItemID == ItemID).FirstOrDefault();

            if (detail != null)
            {
                detail.Qty            += Qty;
                db.Entry(detail).State = EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                detail          = new tbl_ImportDetail();
                detail.ItemID   = ItemID;
                detail.ImportID = ImportID;
                detail.Qty      = Qty;
                detail.Price    = Price;

                db.tbl_ImportDetail.Add(detail);
                db.SaveChanges();
            }
            tbl_Items item = db.tbl_Items.Find(ItemID);

            item.ItemCount      += Qty;
            db.Entry(item).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Edit", new { id = ImportID }));
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            tbl_Orders             tbl_orders = db.tbl_Orders.Find(id);
            List <tbl_OrderDetail> arr        = tbl_orders.tbl_OrderDetail.ToList();

            if (tbl_orders.Status == OrderStatus.Delivery)
            {
                foreach (var item in arr)
                {
                    tbl_Items sp = db.tbl_Items.Find(item.ItemID);
                    if (sp != null)
                    {
                        sp.ItemCount      += item.Qty.Value;
                        db.Entry(sp).State = EntityState.Modified;
                    }
                }
            }

            foreach (var item in arr)
            {
                db.tbl_OrderDetail.Remove(item);
            }

            db.tbl_Orders.Remove(tbl_orders);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public JsonResult AddStock(string vendorName, string billNo, string billDate, string quantity, string amount, string tax, string itemName, string price, string spareItemText)
        {
            string data     = "";
            int?   itemCode = Convert.ToInt32(itemName);
            int    empID    = Convert.ToInt32(Session["ID"]);
            var    items    = db.tbl_Items.Select(p => p.itemname.ToLower().Trim()).ToList();

            if (itemCode == 0)
            {
                if (!items.Contains(spareItemText.ToLower().Trim()))
                {
                    if (spareItemText != null || spareItemText != "")
                    {
                        tbl_Items item = new tbl_Items();
                        item.itemname    = spareItemText;
                        item.createdby   = db.tbl_employee.Where(e => e.EmployeeID == empID).Select(e => e.EmployeeName).FirstOrDefault();
                        item.createddate = DateTime.Now;
                        db.tbl_Items.Add(item);
                        db.SaveChanges();
                        data = "Item";
                    }
                }
                else
                {
                    data = "Item exists";
                }
            }

            if (data == "Item exists")
            {
                data = data;
            }
            else
            {
                tbl_InventoryStock stock = new tbl_InventoryStock();
                stock.Amount      = Convert.ToDecimal(amount);
                stock.BillDate    = Convert.ToDateTime(billDate);
                stock.BillNo      = billNo;
                stock.createdby   = db.tbl_employee.Where(e => e.EmployeeID == empID).Select(e => e.EmployeeName).FirstOrDefault();
                stock.createddate = DateTime.Now;
                if (itemCode == 0)
                {
                    stock.Item = spareItemText;
                }
                else
                {
                    stock.Item = db.tbl_Items.Where(i => i.itemcode == itemCode).Select(i => i.itemname).FirstOrDefault();
                }
                stock.Price      = Convert.ToDecimal(price);
                stock.quantity   = Convert.ToInt32(quantity);
                stock.Tax        = Convert.ToDecimal(tax);
                stock.VendorName = vendorName;
                db.tbl_InventoryStock.Add(stock);
                db.SaveChanges();
                data += "stock";
            }


            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            tbl_Items tbl_items = db.tbl_Items.Find(id);

            if (db.tbl_OrderDetail.Where(a => a.ItemID == id).Count() > 0)
            {
                ModelState.AddModelError("ItemName", "Sản phẩn này đã được đặt hàng, bạn không thể xóa!");
                return(View(tbl_items));
            }
            if (db.tbl_ImportDetail.Where(a => a.ItemID == id).Count() > 0)
            {
                ModelState.AddModelError("ItemName", "Sản phẩn này đã được nhập hàng, bạn không thể xóa!");
                return(View(tbl_items));
            }

            string FilesPath = ConfigurationManager.AppSettings["ItemImages"];
            string full_path = Server.MapPath(FilesPath).Replace("Item", "").Replace("Edit", "");

            if (tbl_items.Images + "" != "")
            {
                FileUpload.DeleteFile(tbl_items.Images, full_path);
            }

            db.tbl_Items.Remove(tbl_items);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #5
0
        //public async Task<ActionResult> Create([Bind(Include = "ID,Name,HSN_SAC_NO,Type,MeasuringUnit,Manufacture,BarCode,ItemUniqueDescription,Supplier,Photo,UseBatchNo,UseMfgDate,UseExpiryDate,CreatedDatetime")] tbl_Items tbl_Items)
        public async Task <ActionResult> Create([Bind(Include = "ID,Name,HSN_SAC_NO,Type,MeasuringUnit,Manufacture,BarCode,ItemUniqueDescription,Supplier,Photo,UseBatchNo,UseMfgDate,UseExpiryDate,CreatedDatetime,GST")] tbl_Items tbl_Items, [Bind(Include = "OpeningStock")] int?OpeningStock)
        {
            if (ModelState.IsValid)
            {
                db.tbl_Items.Add(tbl_Items);
                await db.SaveChangesAsync();

                tbl_Sequence NewSequenceValue = Helper.GenericHelper.GetNextUpdatedData("tbl_Items");
                db.Entry(NewSequenceValue).State = EntityState.Modified;
                await db.SaveChangesAsync();

                if (OpeningStock > 0)
                {
                    tbl_ItemStock tbl_ItemStock = new tbl_ItemStock()
                    {
                        ID              = tbl_Items.ID + "-" + Helper.GenericHelper.GetMaxValue("tbl_ItemStock") + "-1",
                        StockType       = "IN",
                        InvoiceNo       = "Opening Stock",
                        ItemID          = tbl_Items.ID,
                        Qty             = OpeningStock,
                        CreatedDatetime = tbl_Items.CreatedDatetime.ToString() ?? DateTime.Now.Date.ToString()
                    };
                    db.tbl_ItemStock.Add(tbl_ItemStock);
                    await db.SaveChangesAsync();
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.Type          = new SelectList(db.tbl_ItemType, "ItemTypeId", "ItemType", tbl_Items.Type);
            ViewBag.MeasuringUnit = new SelectList(db.tbl_ItemUnits, "MeasurintUnitID", "MeasuringUnits", tbl_Items.MeasuringUnit);
            ViewBag.Supplier      = new SelectList(db.tbl_vendor, "ID", "Name", tbl_Items.Supplier);
            ViewBag.GST           = new SelectList(db.tbl_GST, "ID", "GST", tbl_Items.GST);
            return(View(tbl_Items));
        }
        public ViewResult ImageList(int id)
        {
            tbl_Items item = db.tbl_Items.Find(id);
            string    path = "~/Images/uploads/" + item.ItemID;

            path = Server.MapPath(path);
            List <string> list = new List <string>();

            if (Directory.Exists(path))
            {
                string[] files = Directory.GetFiles(path);

                foreach (string s in files)
                {
                    string filename = Path.GetFileName(s);
                    System.IO.File.Move(s, s.Replace(" ", "_").Replace("-", "_"));
                    if (filename.ToLower().IndexOf(".jpg") >= 0 || filename.ToLower().IndexOf(".png") >= 0 || filename.ToLower().IndexOf(".gif") >= 0)
                    {
                        list.Add("../../images/uploads/" + item.ItemID + "/" + filename.Replace(" ", "_").Replace("-", "_"));
                    }
                }
            }
            ViewBag.ImageList = list;
            return(View(item));
        }
        public ActionResult Create(tbl_Items tbl_items, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                string filesPath = "", full_path = "";
                if (file != null)
                {
                    char DirSeparator = System.IO.Path.DirectorySeparatorChar;
                    filesPath        = ConfigurationManager.AppSettings["ItemImages"];
                    full_path        = Server.MapPath(filesPath).Replace("Item", "");
                    tbl_items.Images = FileUpload.UploadFile(file, full_path);
                }

                db.tbl_Items.Add(tbl_items);
                db.SaveChanges();

                if (file != null)
                {
                    string filename = tbl_items.ItemID + "_" + file.FileName.Replace(" ", "_").Replace("-", "_");
                    tbl_items.Images          = FileUpload.UploadFile(file, filename, full_path);
                    db.Entry(tbl_items).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.ItemGroupID = new SelectList(db.tbl_ItemGroup, "ItemGroupID", "ItemGroupName", tbl_items.ItemGroupID);
            return(View(tbl_items));
        }
Exemple #8
0
        public void Delete(int id)                //Upadate single records
        {
            tbl_Items Item = db.tbl_Items.Find(id);

            db.tbl_Items.Remove(Item);

            save();
        }
Exemple #9
0
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            tbl_Items tbl_Items = await db.tbl_Items.FindAsync(id);

            db.tbl_Items.Remove(tbl_Items);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemple #10
0
 public ActionResult Edit([Bind(Include = "Guid,StoreGuid,Name,Category,SellIn,Quality,PurchasePrice,SellPrice,Legendary,BetterWithAge,Image,ImageName,DateCreated,DateTrashed,Active")] tbl_Items tbl_Items)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbl_Items).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { guid = currentStore.Guid }));
     }
     return(View(tbl_Items));
 }
        public ActionResult Delete(int id = 0)
        {
            tbl_Items tbl_items = db.tbl_Items.Find(id);

            if (tbl_items == null)
            {
                return(HttpNotFound());
            }
            return(View(tbl_items));
        }
Exemple #12
0
        public int Insert(tbl_Items obj)                //Insert single records
        {
            db.tbl_Items.Add(obj);

            save();

            int Id = obj.ID;

            return(Id);
        }
        public ActionResult Edit(int id = 0)
        {
            tbl_Items tbl_items = db.tbl_Items.Find(id);

            if (tbl_items == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ItemGroupID = new SelectList(db.tbl_ItemGroup, "ItemGroupID", "ItemGroupName", tbl_items.ItemGroupID);
            return(View(tbl_items));
        }
        //
        // GET: /Item/Details/5

        public ActionResult Details(int id = 0)
        {
            tbl_Items tbl_items = db.tbl_Items.Find(id);

            if (tbl_items == null)
            {
                return(HttpNotFound());
            }
            tbl_items.ViewCount      += 1;
            db.Entry(tbl_items).State = EntityState.Modified;
            db.SaveChanges();
            return(View(tbl_items));
        }
Exemple #15
0
        // GET: Items/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_Items tbl_Items = db.tbl_Items.Find(id);

            if (tbl_Items == null)
            {
                return(HttpNotFound());
            }
            return(View(tbl_Items));
        }
Exemple #16
0
 public void SaveItem(tbl_Items item)
 {
     using (var connection = new SqlConnection(Configuration.ConnectionString))
     {
         if (item.ItemID == 0)
         {
             connection.Insert(item);
         }
         else
         {
             connection.Update(item);
         }
     }
 }
Exemple #17
0
        // GET: Items/Details/5
        public async Task <ActionResult> Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_Items tbl_Items = await db.tbl_Items.FindAsync(id);

            if (tbl_Items == null)
            {
                return(HttpNotFound());
            }
            return(View(tbl_Items));
        }
Exemple #18
0
        //public async Task<ActionResult> Edit([Bind(Include = "ID,Name,HSN_SAC_NO,Type,MeasuringUnit,Manufacture,BarCode,ItemUniqueDescription,Supplier,Photo,UseBatchNo,UseMfgDate,UseExpiryDate,CreatedDatetime")] tbl_Items tbl_Items)
        public async Task <ActionResult> Edit([Bind(Include = "ID,Name,HSN_SAC_NO,Type,MeasuringUnit,Manufacture,BarCode,ItemUniqueDescription,Supplier,Photo,UseBatchNo,UseMfgDate,UseExpiryDate,CreatedDatetime,GST")] tbl_Items tbl_Items)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tbl_Items).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.Type          = new SelectList(db.tbl_ItemType, "ItemTypeId", "ItemType", tbl_Items.Type);
            ViewBag.MeasuringUnit = new SelectList(db.tbl_ItemUnits, "MeasurintUnitID", "MeasuringUnits", tbl_Items.MeasuringUnit);
            ViewBag.Supplier      = new SelectList(db.tbl_vendor, "ID", "Name", tbl_Items.Supplier);
            ViewBag.GST           = new SelectList(db.tbl_GST, "ID", "GST", tbl_Items.GST);
            return(View(tbl_Items));
        }
Exemple #19
0
        public RedirectToRouteResult RemoveDetail(int ImportID, int ItemID)
        {
            var import = db.tbl_Imports.Find(ImportID);
            tbl_ImportDetail detail = import.tbl_ImportDetail.Where(a => a.ItemID == ItemID).FirstOrDefault();

            if (detail != null)
            {
                db.tbl_ImportDetail.Remove(detail);
                tbl_Items item = db.tbl_Items.Find(ItemID);
                item.ItemCount      -= detail.Qty.Value;
                db.Entry(item).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("Edit", new { id = ImportID }));
        }
Exemple #20
0
        public ActionResult Edit(tbl_Orders tbl_orders, OrderStatus currStatus)
        {
            var date = DateTime.Now;

            tbl_orders.DeliveryDate = null;
            string[] s = (Request.Form["datepicker"] + "").Split('/');
            try
            {
                date = new DateTime(Convert.ToInt16(s[2]), Convert.ToInt16(s[1]), Convert.ToInt16(s[0]));
                tbl_orders.DeliveryDate = date;
            }
            catch (Exception e) { if (tbl_orders.Status == OrderStatus.Delivery)
                                  {
                                      ModelState.AddModelError("DeliveryDate", "Ngày giao hàng chưa đúng");
                                  }
            }
            if (ModelState.IsValid)
            {
                //tbl_Orders currOrder = db.tbl_Orders.Find(tbl_orders.OrderID);
                if (tbl_orders.Status == OrderStatus.Delivery && currStatus == OrderStatus.Order)
                {
                    foreach (var item in db.tbl_OrderDetail.Where(a => a.OrderID == tbl_orders.OrderID))
                    {
                        tbl_Items sp = db.tbl_Items.Find(item.ItemID);
                        sp.ItemCount      -= item.Qty.Value;
                        db.Entry(sp).State = EntityState.Modified;
                    }
                }
                if (tbl_orders.Status != OrderStatus.Delivery && currStatus == OrderStatus.Delivery)
                {
                    foreach (var item in db.tbl_OrderDetail.Where(a => a.OrderID == tbl_orders.OrderID))
                    {
                        tbl_Items sp = db.tbl_Items.Find(item.ItemID);
                        sp.ItemCount      += item.Qty.Value;
                        db.Entry(sp).State = EntityState.Modified;
                    }
                }
                db.Entry(tbl_orders).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            tbl_orders           = db.tbl_Orders.Find(tbl_orders.OrderID);
            ViewBag.Customer     = db.tbl_Customers.Find(tbl_orders.CustomerID).CustomerName;
            ViewBag.DeliveryDate = tbl_orders.DeliveryDate == null ? "" : tbl_orders.DeliveryDate.Value.ToString("dd/MM/yyyy");
            ViewBag.Amount       = tbl_orders.tbl_OrderDetail.Sum(a => a.Amount).Value.ToString("#,###");
            return(View(tbl_orders));
        }
Exemple #21
0
        // GET: Items/Edit/5
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_Items tbl_Items = await db.tbl_Items.FindAsync(id);

            if (tbl_Items == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Type          = new SelectList(db.tbl_ItemType, "ItemTypeId", "ItemType", tbl_Items.Type);
            ViewBag.MeasuringUnit = new SelectList(db.tbl_ItemUnits, "MeasurintUnitID", "MeasuringUnits", tbl_Items.MeasuringUnit);
            ViewBag.Supplier      = new SelectList(db.tbl_vendor, "ID", "Name", tbl_Items.Supplier);
            ViewBag.GST           = new SelectList(db.tbl_GST, "ID", "GST", tbl_Items.GST);
            return(View(tbl_Items));
        }
Exemple #22
0
        public ActionResult Upload(string file)
        {
            try
            {
                using (StringReader reader = new StringReader(file))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] itemimport = line.Split(',');

                        tbl_Items item = new tbl_Items();
                        item.Guid        = Guid.NewGuid();
                        item.Active      = true;
                        item.Category    = itemimport[1];
                        item.DateCreated = DateTime.Now;
                        item.Name        = itemimport[0];
                        if (item.Name == "Aged Brie")
                        {
                            item.BetterWithAge = true;
                        }
                        if (item.Category == "Sulfuras")
                        {
                            item.Legendary = true;
                        }
                        item.Quality   = Int32.Parse(itemimport[2]);
                        item.SellIn    = Int32.Parse(itemimport[3]);
                        item.StoreGuid = currentStore.Guid;
                        db.tbl_Items.Add(item);
                        db.SaveChanges();
                    }
                }

                ViewBag.Message = "Inventory Uploaded Successfully!";
                return(View());
            }
            catch (Exception e)
            {
                ViewBag.Message = "Inventory upload failed! " + e.Message;
                return(View());
            }
        }
Exemple #23
0
        public ActionResult Create([Bind(Include = "Guid,StoreGuid,Name,Category,SellIn,Quality,Legendary,BetterWithAge,Image,ImageName,DateCreated,DateTrashed,Active")] tbl_Items tbl_Items)
        {
            if (ModelState.IsValid)
            {
                tbl_Items.Guid        = Guid.NewGuid();
                tbl_Items.StoreGuid   = currentStore.Guid;
                tbl_Items.DateCreated = DateTime.Now;
                if (tbl_Items.Name == "Aged Brie")
                {
                    tbl_Items.BetterWithAge = true;
                }
                if (tbl_Items.Category == "Sulfuras")
                {
                    tbl_Items.Legendary = true;
                }
                tbl_Items.Active = true;
                db.tbl_Items.Add(tbl_Items);
                db.SaveChanges();
                return(RedirectToAction("Index", new { guid = currentStore.Guid }));
            }

            return(View(tbl_Items));
        }
        public ActionResult Edit(tbl_Items tbl_items, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    char   DirSeparator = System.IO.Path.DirectorySeparatorChar;
                    string FilesPath    = ConfigurationManager.AppSettings["ItemImages"];
                    string full_path    = Server.MapPath(FilesPath).Replace("Item", "").Replace("Edit", "");
                    if (tbl_items.Images + "" != "")
                    {
                        FileUpload.DeleteFile(tbl_items.Images, full_path);
                    }

                    tbl_items.Images = FileUpload.UploadFile(file, full_path);
                }

                db.Entry(tbl_items).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.ItemGroupID = new SelectList(db.tbl_ItemGroup, "ItemGroupID", "ItemGroupName", tbl_items.ItemGroupID);
            return(View(tbl_items));
        }
Exemple #25
0
        public tbl_Items GetById(int id)            //get single records
        {
            tbl_Items Item = db.tbl_Items.Find(id);

            return(Item);
        }
Exemple #26
0
        public void Upadate(tbl_Items obj)                //Upadate single records
        {
            db.Entry(obj).State = System.Data.Entity.EntityState.Modified;

            save();
        }