Example #1
0
        public ActionResult OutOrderApprove(int id)
        {
            var uow = new UnitOfWork();

            ProductManageBz.SetUOW(uow);
            ProductPutOutOrderManageBz.SetUOW(uow);
            ProductLogManageBz.SetUOW(uow);

            var model = ProductPutOutOrderManageBz.Get(o => o.ID == id);

            if (model.Status != OrderStatus.未审批)
            {
                TempData["Msg"] = "此订单非未审批状态,无法审批!";
            }
            else
            {
                foreach (var detail in model.ProductOrderDetail)
                {
                    var product = ProductManageBz.Get(o => o.ProductName == detail.ProductName);
                    if (product == null || product.SumNum < detail.Num)//add
                    {
                        TempData["Msg"] = "库存数量不足,无法审批!";
                        return(RedirectToAction("OutIndex"));
                    }
                    else
                    {
                        product.SumNum -= detail.Num;
                        ProductManageBz.Update(product, false);
                    }
                }
                //库存记录(验收产品种类一般不多故分开结构清晰)
                foreach (var row in model.ProductOrderDetail)
                {
                    if (row.Num > 0)
                    {
                        ProductLogManageBz.Save(new ProductLog
                        {
                            In1Out      = "Out",
                            Oper        = CurrentUser.UserName,
                            OperTime    = DateTime.Now,
                            num         = row.Num,
                            ProductName = row.ProductName,
                            Remark      = $"出库单号:{model.ProductOrderNo}审批出库"
                        }, false);
                    }
                }
                model.Status = OrderStatus.已审批;
                model.Oper   = CurrentUser.UserName;
                var isSuccess = ProductPutOutOrderManageBz.Update(model);
                if (isSuccess)
                {
                    TempData["Msg"] = "审批成功!";
                }
                else
                {
                    TempData["Msg"] = "审批失败!";
                }
            }
            return(RedirectToAction("OutIndex"));
        }
        public ActionResult AcceptApprove(int id)
        {
            var model = AcceptOrderManageBz.Get(o => o.ID == id);

            if (model.Status != OrderStatus.未审批)
            {
                TempData["Msg"] = "此订单非未审批状态,无法审批!";
            }
            else
            {
                var uow = new UnitOfWork();
                PurchaseOrderManageBz.SetUOW(uow);
                AcceptOrderManageBz.SetUOW(uow);
                ProductManageBz.SetUOW(uow);
                ProductLogManageBz.SetUOW(uow);
                //更新采购单数量
                var purchaseOrder = PurchaseOrderManageBz.Get(o => o.PurchaseOrderNo == model.PurchaseOrderNo);
                purchaseOrder.PurchaseNumWait -= model.AcceptNum;
                purchaseOrder.PurchaseNumOver += model.AcceptNum;
                if (purchaseOrder.PurchaseNumWait < 0)
                {
                    TempData["Msg"] = "审批失败:验收数大于待采购数";
                    return(RedirectToAction("Index"));
                }
                else if (purchaseOrder.PurchaseNumWait == 0)
                {
                    purchaseOrder.Status = OrderStatus.已验收;
                }
                else
                {
                    purchaseOrder.Status = OrderStatus.部分验收;
                }
                foreach (var row in model.AcceptOrderDetail)
                {
                    var detail = purchaseOrder.PurchaseOrderDetail.Find(o => o.ProductId == row.ProductId);
                    detail.PurchaseNumOver += row.AcceptNum;
                    detail.PurchaseNumWait -= row.AcceptNum;
                }
                PurchaseOrderManageBz.Update(purchaseOrder, false);
                //新增库存

                foreach (var row in model.AcceptOrderDetail)
                {
                    var product = ProductManageBz.Get(o => o.ProductName == row.ProductName);
                    if (product == null)
                    {
                        ProductManageBz.Save(new Product {
                            From        = "验收单",
                            Location    = "",
                            LockNum     = 0,
                            Price       = row.Price,
                            ProductName = row.ProductName,
                            SumNum      = row.AcceptNum,
                            Type        = ProductType.物料,
                            WaringMin   = -1,
                            WaringMax   = -1
                        }, false);
                    }
                    else
                    {
                        product.SumNum += row.AcceptNum;
                        ProductManageBz.Update(product, false);
                    }
                }
                //库存记录(验收产品种类一般不多故分开结构清晰)
                foreach (var row in model.AcceptOrderDetail)
                {
                    if (row.AcceptNum > 0)
                    {
                        ProductLogManageBz.Save(new ProductLog
                        {
                            In1Out      = "In",
                            Oper        = CurrentUser.UserName,
                            OperTime    = DateTime.Now,
                            num         = row.AcceptNum,
                            ProductName = row.ProductName,
                            Remark      = $"验收单号:{model.AcceptOrderNo}验收入库"
                        }, false);
                    }
                }

                //审批验收单
                model.Status = OrderStatus.已审批;
                model.Oper   = CurrentUser.UserName;
                bool isSuccess = AcceptOrderManageBz.Update(model);

                if (isSuccess)
                {
                    TempData["Msg"] = "审批成功!";
                }
                else
                {
                    TempData["Msg"] = "审批失败!";
                }
            }
            return(RedirectToAction("Index"));
        }