public ActionResult DeleteConfirmed(int id)
      {
          I_StockTranferDetails i_StockTranferDetails = db.I_StockTranferDetails.Find(id);

          db.I_StockTranferDetails.Remove(i_StockTranferDetails);
          db.SaveChanges();
          return(RedirectToAction("Index"));
      }
      public ActionResult Approve(int?id)
      {
          if (id == null)
          {
              return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
          }
          I_StockReqDetails i_StockReqDetails = db.I_StockReqDetails.Find(id);

          i_StockReqDetails.Status          = 3; // Approve
          i_StockReqDetails.ModifiedBy      = System.Web.HttpContext.Current.User.Identity.Name;
          i_StockReqDetails.ModifiedOn      = System.DateTime.Now;
          db.Entry(i_StockReqDetails).State = EntityState.Modified;
          db.SaveChanges();
          I_StockTranferDetails obj = new I_StockTranferDetails();

          obj.SourceStore = i_StockReqDetails.SourceStore;
          obj.TragetStore = i_StockReqDetails.TragetStore;
          obj.Reference   = "Againest Request No " + i_StockReqDetails.TranferNo;
          obj.CreatedBy   = System.Web.HttpContext.Current.User.Identity.Name;
          obj.CreatedOn   = System.DateTime.Now;
          obj.Date        = i_StockReqDetails.Date;
          obj.TranferNo   = "TRN";
          obj.CreatedBy   = System.Web.HttpContext.Current.User.Identity.Name;
          obj.CreatedOn   = System.DateTime.Now;
          obj.Status      = 1;
          db.I_StockTranferDetails.Add(obj);
          db.SaveChanges();
          I_StockTranferDetails i_StockTranferDetail = db.I_StockTranferDetails.Find(obj.Id);

          i_StockTranferDetail.TranferNo       = "TRN" + System.DateTime.Now.Year + "/" + System.DateTime.Now.Month + "/" + obj.Id;
          db.Entry(i_StockTranferDetail).State = EntityState.Modified;
          db.SaveChanges();
          List <I_StockRequestItemCatalog> i_StockRequestItemCatalog = new List <I_StockRequestItemCatalog>();

          i_StockRequestItemCatalog = db.I_StockRequestItemCatalog.Where(x => x.ReqNo == id).ToList();
          I_StockTransferItemCatalog objtransfer;

          foreach (I_StockRequestItemCatalog item in i_StockRequestItemCatalog)
          {
              objtransfer = new I_StockTransferItemCatalog();

              objtransfer.ItemCode  = item.ItemCode;
              objtransfer.ItemName  = item.ItemName;
              objtransfer.ReqNo     = obj.Id;
              objtransfer.ReqQty    = item.Qty;
              objtransfer.UnitId    = item.UnitId;
              objtransfer.UnitName  = item.UnitName;
              objtransfer.CreatedBy = System.Web.HttpContext.Current.User.Identity.Name;
              objtransfer.CreatedOn = System.DateTime.Now;
              db.I_StockTransferItemCatalog.Add(objtransfer);
              db.SaveChanges();
          }



          return(RedirectToAction("PendingRequests"));
      }
      // GET: StockTranfer/Create
      public ActionResult Create()
      {
          I_StockTranferDetails obj = new I_StockTranferDetails();

          obj.CreatedBy       = System.Web.HttpContext.Current.User.Identity.Name;
          obj.CreatedOn       = System.DateTime.Now;
          obj.Date            = System.DateTime.Now;
          obj.TranferNo       = "TRF";
          ViewBag.SourceStore = new SelectList(db.Store_Details, "storeId", "storename");
          ViewBag.TragetStore = new SelectList(db.Store_Details, "storeId", "storename");
          return(View(obj));
      }
      public ActionResult Edit(I_StockTranferDetails i_StockTranferDetails)
      {
          i_StockTranferDetails.ModifiedBy = System.Web.HttpContext.Current.User.Identity.Name;
          i_StockTranferDetails.ModifiedOn = System.DateTime.Now;
          if (ModelState.IsValid)
          {
              db.Entry(i_StockTranferDetails).State = EntityState.Modified;
              db.SaveChanges();
              return(RedirectToAction("Index"));
          }

          ViewBag.SourceStore = new SelectList(db.Store_Details, "storeId", "storename", i_StockTranferDetails.SourceStore);
          ViewBag.TragetStore = new SelectList(db.Store_Details, "storeId", "storename", i_StockTranferDetails.TragetStore);
          return(View(i_StockTranferDetails));
      }
      // GET: StockTranfer/Delete/5
      public ActionResult Delete(int?id)
      {
          if (id == null)
          {
              return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
          }
          I_StockTranferDetails i_StockTranferDetails = db.I_StockTranferDetails.Find(id);

          i_StockTranferDetails.Status          = -99;
          i_StockTranferDetails.ModifiedBy      = System.Web.HttpContext.Current.User.Identity.Name;
          i_StockTranferDetails.ModifiedOn      = System.DateTime.Now;
          db.Entry(i_StockTranferDetails).State = EntityState.Modified;

          db.SaveChanges();
          return(RedirectToAction("Index"));
      }
      // GET: StockTranfer/Edit/5
      public ActionResult Edit(int?id)
      {
          if (id == null)
          {
              return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
          }
          I_StockTranferDetails i_StockTranferDetails = db.I_StockTranferDetails.Find(id);

          if (i_StockTranferDetails == null)
          {
              return(HttpNotFound());
          }
          ViewBag.SourceStore = new SelectList(db.Store_Details, "storeId", "storename", i_StockTranferDetails.SourceStore);
          ViewBag.TragetStore = new SelectList(db.Store_Details, "storeId", "storename", i_StockTranferDetails.TragetStore);
          return(View(i_StockTranferDetails));
      }
      public ActionResult Create(I_StockTranferDetails i_StockTranferDetails)
      {
          i_StockTranferDetails.CreatedBy = System.Web.HttpContext.Current.User.Identity.Name;
          i_StockTranferDetails.CreatedOn = System.DateTime.Now;
          i_StockTranferDetails.Status    = 1;

          if (ModelState.IsValid)
          {
              db.I_StockTranferDetails.Add(i_StockTranferDetails);
              db.SaveChanges();
              I_StockTranferDetails i_StockTranferDetail = db.I_StockTranferDetails.Find(i_StockTranferDetails.Id);
              i_StockTranferDetail.TranferNo = "TRN" + System.DateTime.Now.Year + "/" + System.DateTime.Now.Month + "/" + i_StockTranferDetails.Id;
              Edit(i_StockTranferDetail);
              return(RedirectToAction("Index"));
          }
          ViewBag.SourceStore = new SelectList(db.Store_Details, "storeId", "storename", i_StockTranferDetails.SourceStore);
          ViewBag.TragetStore = new SelectList(db.Store_Details, "storeId", "storename", i_StockTranferDetails.TragetStore);
          return(View(i_StockTranferDetails));
      }
Example #8
0
        public IHttpActionResult PostI_StockTransferItemCatalog(List <I_StockTransferItemCatalog> i_StockReqDetails)
        {
            int ReqNo   = 0;
            int orderId = 0;

            foreach (I_StockTransferItemCatalog i_orderMaster in i_StockReqDetails)
            {
                I_StockTranferDetails i_OrderDetails = new I_StockTranferDetails();
                ReqNo                          = i_orderMaster.ReqNo;
                i_OrderDetails                 = db.I_StockTranferDetails.Find(i_orderMaster.ReqNo);
                i_OrderDetails.Status          = 2;
                db.Entry(i_OrderDetails).State = EntityState.Modified;
                db.SaveChanges();

                I_OrderDetails objOrd = new I_OrderDetails();
                objOrd.DeliveryDate = i_OrderDetails.Date;
                objOrd.Status       = 1;
                objOrd.OrderNo      = "TRA";
                objOrd.StoreId      = i_OrderDetails.TragetStore;
                objOrd.TranferNo    = i_OrderDetails.TranferNo;
                objOrd.Reference    = "Created against Transfer No " + i_OrderDetails.TranferNo;
                objOrd.CreatedBy    = i_OrderDetails.CreatedBy;
                objOrd.CreatedOn    = i_OrderDetails.CreatedOn;
                db.I_OrderDetails.Add(objOrd);
                db.SaveChanges();
                orderId = objOrd.Id;
                I_OrderDetails i_OrderDetail = db.I_OrderDetails.Find(objOrd.Id);
                i_OrderDetail.OrderNo         = "ORD" + System.DateTime.Now.Year + "/" + System.DateTime.Now.Month + "/" + i_OrderDetails.Id;
                db.Entry(i_OrderDetail).State = EntityState.Modified;
                db.SaveChanges();


                break;
            }

            foreach (I_StockTransferItemCatalog item in i_StockReqDetails)
            {
                if (I_stockTransExists(Convert.ToInt32(item.ItemCode), item.ReqNo))
                {
                    I_StockTransferItemCatalog i_orderMaster1 = db.I_StockTransferItemCatalog.Where(e => e.ItemCode == item.ItemCode && e.ReqNo == item.ReqNo).FirstOrDefault();
                    if (i_orderMaster1 != null)
                    {
                        db.I_StockTransferItemCatalog.Remove(i_orderMaster1);
                        db.SaveChanges();
                    }

                    db.I_StockTransferItemCatalog.Add(item);
                    db.SaveChanges();

                    I_OrderItemCatalog obj = new I_OrderItemCatalog();
                    obj.ItemName        = item.ItemName;
                    obj.ItemsId         = item.ItemCode;
                    obj.Qty             = item.Qty;
                    obj.Status          = 1;
                    obj.Price           = db.I_StockInventory.Where(x => x.ItemId == item.ItemCode).Average(i => i.Price);
                    obj.OrderId         = orderId;
                    obj.TotalSum        = obj.Price * obj.Qty;
                    obj.Unit            = item.UnitId;
                    obj.Vendor          = 0;
                    obj.FixedorVariable = db.I_InventoryItemMaster.Where(x => x.ItemCode == item.ItemCode).Select(i => i.FixedorVariable).SingleOrDefault();;
                    obj.Createdby       = item.CreatedBy;
                    obj.CreatedOn       = item.CreatedOn;

                    db.I_OrderItemCatalog.Add(obj);
                    db.SaveChanges();
                }
                else
                {
                    db.I_StockTransferItemCatalog.Add(item);
                    db.SaveChanges();

                    I_OrderItemCatalog obj = new I_OrderItemCatalog();
                    obj.ItemName        = item.ItemName;
                    obj.ItemsId         = item.ItemCode;
                    obj.Qty             = item.Qty;
                    obj.Status          = 1;
                    obj.Price           = db.I_StockInventory.Where(x => x.ItemId == item.ItemCode).Average(i => i.Price);
                    obj.OrderId         = orderId;
                    obj.TotalSum        = obj.Price * obj.Qty;
                    obj.Unit            = item.UnitId;
                    obj.Vendor          = 0;
                    obj.FixedorVariable = db.I_InventoryItemMaster.Where(x => x.Id == item.ItemCode).Select(i => i.FixedorVariable).SingleOrDefault();;
                    obj.Createdby       = item.CreatedBy;
                    obj.CreatedOn       = item.CreatedOn;
                    db.I_OrderItemCatalog.Add(obj);
                    db.SaveChanges();
                }
            }



            return(CreatedAtRoute("DefaultApi", new { }, i_StockReqDetails));
        }