コード例 #1
0
        public JsonResult CreateJson([Bind(Include = "StockIssueId,StockIssueTypeId,WarehouseId,Code,Ref,UserCreate,IssueDate,Note,LpoId,CuttingSheetId")] StockIssue stockIssue)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (stockIssue.LpoId != 0 && stockIssue.LpoId != null)
                    {
                        var lpo = db.Lpoes.Find(stockIssue.LpoId);
                        lpo.LpoStatusId = 3;  //complete
                    }



                    stockIssue.StampDate  = DateTime.Now;
                    stockIssue.UserCreate = User.Identity.GetUserName();
                    db.StockIssues.Add(stockIssue);
                    db.SaveChanges();
                    StockIssue s = db.StockIssues.Include(w => w.StockIssueType).Where(w => w.StockIssueId == stockIssue.StockIssueId).FirstOrDefault();

                    if (s.StockIssueType.Name == "Stock In (Puchase Invoice)")
                    {
                        this.notificationRepository.CreateNotificationAsync(stockIssue.StockIssueId, NotificationName.onStockIn);
                    }
                    else if (stockIssue.StockIssueType.Name == "Stock Out(Issue Material)")
                    {
                        this.notificationRepository.CreateNotificationAsync(stockIssue.StockIssueId, NotificationName.onStockOut);
                    }
                    return(Json(stockIssue.StockIssueId));
                }
                catch (Exception ex)
                {
                    String errors11 = ex.Message;

                    if (ex.InnerException != null)
                    {
                        errors11 = errors11 + ex.InnerException.Message + " \r\n ";;
                    }
                    return(Json(errors11));
                }
            }


            String errors111 = "";

            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    errors111 = errors111 + " <br /> " + error.ErrorMessage;
                }
            }
            return(Json(errors111));
        }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "StockIssueId,StockIssueTypeId,WarehouseId,Code,Ref,UserCreate,IssueDate,Note")] StockIssue stockIssue)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stockIssue).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StockIssueTypeId = new SelectList(db.StockIssueTypes, "StockIssueTypeId", "Name", stockIssue.StockIssueTypeId);
     ViewBag.WarehouseId      = new SelectList(db.Warehouses, "WarehouseId", "Name", stockIssue.WarehouseId);
     return(View(stockIssue));
 }
コード例 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            StockIssue stockIssue = db.StockIssues.Find(id);

            foreach (var x in stockIssue.StockIssueDetails.ToList())
            {
                db.StockIssueDetails.Remove(x);
            }

            db.StockIssues.Remove(stockIssue);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        // GET: StockIssues/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StockIssue stockIssue = db.StockIssues.Find(id);

            if (stockIssue == null)
            {
                return(HttpNotFound());
            }
            return(View(stockIssue));
        }
コード例 #5
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StockIssue stockIssue = db.StockIssues.Find(id);

            if (stockIssue == null)
            {
                return(HttpNotFound());
            }
            ViewBag.StockIssueTypeId = new SelectList(db.StockIssueTypes, "StockIssueTypeId", "Name", stockIssue.StockIssueTypeId);
            ViewBag.WarehouseId      = new SelectList(db.Warehouses, "WarehouseId", "Name", stockIssue.WarehouseId);
            return(View(stockIssue));
        }
コード例 #6
0
        public JsonResult CreateJson([Bind(Include = "StockIssueId,StockIssueTypeId,WarehouseId,Code,Ref,UserCreate,IssueDate,Note,LpoId,CuttingSheetId")] StockIssue stockIssue)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (stockIssue.LpoId != 0 && stockIssue.LpoId != null)
                    {
                        var lpo = db.Lpoes.Find(stockIssue.LpoId);
                        lpo.LpoStatusId = 3;  //complete
                    }



                    stockIssue.StampDate  = DateTime.Now;
                    stockIssue.UserCreate = User.Identity.GetUserName();
                    db.StockIssues.Add(stockIssue);
                    db.SaveChanges();
                    return(Json(stockIssue.StockIssueId));
                }
                catch (Exception ex)
                {
                    String errors11 = ex.Message;

                    if (ex.InnerException != null)
                    {
                        errors11 = errors11 + ex.InnerException.Message + " \r\n ";;
                    }
                    return(Json(errors11));
                }
            }


            String errors111 = "";

            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    errors111 = errors111 + " <br /> " + error.ErrorMessage;
                }
            }
            return(Json(errors111));
        }
コード例 #7
0
        public JsonResult CreateDetailsJson(List <StockIssueDetail> Details, int id)
        {
            string errors11 = "";
            int    aaa      = 0;
            int    test     = 0;
            int    eid      = 0;
            float  oldQty   = 0;

            StockIssue stockIssue = db.StockIssues.Find(id);


            StockIssueDetail EP = new StockIssueDetail();

            foreach (StockIssueDetail d in Details)
            {
                try
                {
                    EP = new StockIssueDetail();
                    EP.StockIssueId = int.Parse(d.StockIssueId.ToString());
                    eid             = int.Parse(d.StockIssueId.ToString());

                    EP.MaterialId = int.Parse(d.MaterialId.ToString());
                    Material mm = db.Materials.Find(EP.MaterialId);
                    EP.Price = float.Parse(d.Price.ToString());


                    //calculat Qty
                    var StockIssue = db.StockIssues.Find(eid);
                    if (StockIssue.StockIssueType.Type == MoveType.InStore)
                    {
                        EP.InQty  = float.Parse(d.InQty.ToString());
                        EP.OutQty = 0;
                        //update material qty
                        oldQty = mm.qty ?? 0;
                        mm.qty = oldQty + EP.InQty;
                    }
                    else
                    {
                        EP.InQty = 0;
                        float OldResevedqty = mm.Resevedqty ?? 0;
                        EP.OutQty = float.Parse(d.OutQty.ToString());

                        //EP.BalanceQty = float.Parse(d.BalanceQty.ToString());

                        //update material qty
                        oldQty        = mm.qty ?? 0;
                        mm.qty        = oldQty - EP.OutQty;
                        mm.Resevedqty = OldResevedqty - EP.OutQty;
                    }



                    //calculat Price

                    if (StockIssue.StockIssueType.Type == MoveType.InStore)
                    {
                        if (d.Price != null && d.Price != 0)
                        {
                            EP.Price = float.Parse(d.Price.ToString());

                            //update material avrgae price


                            mm.latestPrice = EP.Price;

                            float Avg = mm.AvgPrice ?? 0;
                            mm.AvgPrice = (Avg * oldQty + EP.Price * EP.InQty) / (mm.qty);
                        }
                    }

                    db.StockIssueDetails.Add(EP);



                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    DeleteConfirmed(eid);
                    test     = 1;
                    errors11 = errors11 + ex.Message;
                    if (ex.InnerException != null)
                    {
                        if (ex.InnerException.InnerException != null)
                        {
                            errors11 = errors11 + ex.InnerException.InnerException.Message;
                        }
                    }
                    return(Json(errors11));
                }
            }


            if (stockIssue.CuttingSheetId != null)
            {
                CuttingSheet cuttingSheet = db.CuttingSheets.Find(stockIssue.CuttingSheetId);


                List <CuttingSheetDetail> cuttingSheetDetails = cuttingSheet.CuttingSheetDetails.ToList();

                foreach (CuttingSheetDetail cuttingSheetDetail in cuttingSheetDetails)
                {
                    float qty = stockIssue.StockIssueDetails.Where(s => s.MaterialId == cuttingSheetDetail.MaterialId).FirstOrDefault().OutQty;

                    cuttingSheetDetail.IssueQty += qty;

                    db.SaveChanges();
                }
            }


            if (test == 1)
            {
                return(Json(errors11));
            }
            return(Json("Cutting Sheet Saved Successfully"));
        }