示例#1
0
        public ActionResult _Instock(int id, int? _purchaseid, FormCollection collection)
        {
            FoodMaterialInstock instock = null;
            FoodMaterialPurchase purchase = new FoodMaterialPurchase();
            FoodMaterialRequest req = new FoodMaterialRequest();
            FoodMaterialType food = new FoodMaterialType();
            FoodMaterialSpec spec=new FoodMaterialSpec();
            int purchaseid = 0;

            if (id == 0)
            {
                if (_purchaseid == null)
                {
                    instock = new FoodMaterialInstock
                    {
                        PurchaseId = purchaseid
                        ,
                        QualityLevel = (int)QualityLevel.合格
                        ,
                        PersonId = UserInfo.CurUser.Id
                        ,
                        Code = "自动产生"
                        ,ProductDate = DateTime.Today
                    };
                }
                else
                {
                    purchaseid = (int)_purchaseid;
                    purchase = db.FoodMaterialPurchases.Find(purchaseid);
                    if (purchase == null)
                    {
                        return View("ShowError", "", "找不到采购单");
                    }
                    instock = new FoodMaterialInstock
                    {
                        TypeId = purchase.TypeId
                        ,
                        SpecId = purchase.SpecId
                        ,
                        SupplierId = purchase.SupplierId
                        ,
                        PurchaseId = purchaseid
                        ,
                        QualityLevel = (int)QualityLevel.合格
                        ,
                        PersonId = UserInfo.CurUser.Id
                        ,
                        Code = "自动产生"
                        ,
                        InstockDate = DateTime.Today
                        ,
                        InstockUnit = purchase.InstockUnit
                        ,
                        InstockUnitNum = purchase.InstockUnitNum
                        ,ProductDate = DateTime.Today
                    };
                }
            }
            else
            {
                instock = db.FoodMaterialInstocks.Find(id);
                if (instock == null)
                {
                    return View("ShowError", "", "找不到入库单");
                }
                purchase = db.FoodMaterialPurchases.Find(instock.PurchaseId);
            }

            if (collection != null)//POST
            {
                TryUpdateModel(instock, "", null, new string[] { "TypeId","SpecId","SupplierId", "State", "InstockUnit", "InstockUnitNum", "Payed", "PersonId", "PriceNum", "QualityLevel", "QualityRemark" }, collection);
                if (ModelState.IsValid)
                {
                    if (instock.Id == 0)
                    {
                        instock.Code = SysCode.GetCode_ByDate(db, FoodMaterialInstock.LogClass, DateTime.Today);
                        db.FoodMaterialInstocks.Add(instock);
                    }
                    instock.TypeId = purchase.TypeId;
                    instock.SpecId = purchase.SpecId;
                    instock.SupplierId = purchase.SupplierId;
                    instock.InstockUnit = purchase.InstockUnit;
                    instock.InstockUnitNum = purchase.InstockUnitNum;
                    decimal instocknum = (from o in db.FoodMaterialInstocks where o.PurchaseId == instock.PurchaseId select o.PriceNum).ToList().Sum();
                    if (purchase.Num <= instocknum)
                    {
                        purchase.State = (int)FoodMaterialPurchaseState.完成入库;
                    }
                    else
                    {
                        purchase.State = (int)FoodMaterialPurchaseState.未完成入库;
                    }
                    instock.PersonId = UserInfo.CurUser.Id;
                    db.SaveChanges();
                    BLL.Utilities.AddLog(instock.Id, FoodMaterialInstock.LogClass, "添加或修改", "");
                    return Redirect("../InstockView/" + instock.Id);
                }
            }
            if (purchase.Id != 0)
            {
                req = db.FoodMaterialRequests.Find(purchase.RequestId);
                if (req == null)
                {
                    return View("ShowError", "", "找不到申购单");
                }
                //food = db.FoodMaterialType.Find(req.TypeId);
                //if (food == null)
                //{
                //    return View("ShowError", "", "找不到原料");
                //}
            }
            if(instock.TypeId>0)
            {
                food = db.FoodMaterialType.Find(instock.TypeId);
            }
            if(instock.SpecId>0)
            {
                spec = db.FoodMaterialSpecs.Find(instock.SpecId);
            }
            ViewBag.Purchase = purchase;
            ViewBag.Request = req;
            ViewBag.Food = food;
            ViewBag.Spec = spec;
            if(food.StorePlace!=null&&instock.StorePlace==null)
            {
                instock.StorePlace = food.StorePlace;
            }
            if (instock.Id != 0)
            {
                ViewBag.ReturnList = (from o in db.FoodMaterialInstockReturns where o.InstockId == instock.Id select o).ToList();
            }
            return View(instock);
        }
示例#2
0
 public string RequestImportItem(OUContext db, string code, int foodId, decimal num, DateTime date, string remark, string action)
 {
     FoodMaterialRequest req = (from o in db.FoodMaterialRequests where o.Code == code select o).FirstOrDefault();
     if (action == "删除")
     {
         if (req == null) return "找不到可以删除的申请";
         if (req.TypeId != foodId) return "要删除的记录与原记录不匹配,原料不同";
         if(req.State!=(int)FoodMaterialRequestState.未提交)return "要删除的记录状态不允许删除";
         req.State = (int)FoodMaterialRequestState.作废;
         db.SaveChanges();
         return "";
     }
     if (action == "修改")
     {
         if (req == null) return "找不到可以修改的申请";
         if (req.TypeId != foodId) return "要修改的记录与原记录不匹配,原料不同";
         if(req.State!=(int)FoodMaterialRequestState.未提交)return "要修改的记录状态不允许修改";
     }
     if (req == null)
     {
         req = new FoodMaterialRequest();
         db.FoodMaterialRequests.Add(req);
         req.Code = code;
         req.TypeId=foodId;
     }
     req.Num = num;
     req.OrderDate = date;
     req.Remark = remark;
     req.PersonId = UserInfo.CurUser.Id;
     req.RequestTime = DateTime.Now;
     db.SaveChanges();
     return "";
 }