public async Task <ActionResult> UpdateGoodsProfit(GoodsProfit model)
        {
            try
            {
                if (model != null)
                {
                    if (!string.IsNullOrEmpty(model.GoodsMarketingID.ToString()))
                    {
                        GoodsMarketing gm = await GoodsMarketingRepository.FindAsync(g => g.GoodsMarketingID == model.GoodsMarketingID);

                        GoodsPurchase gp = await GoodsPurchaseRepository.FindAsync(p => p.GoodsPurchaseID == gm.GoodsPurchaseID);

                        model.SigningTime        = gm.SigningTime;
                        model.MarketingName      = gm.CustomerName;
                        model.MarketingUnitPrice = gm.UnitPrice;
                        model.ContractNum        = gm.ContractNum;
                        model.PurchaseName       = gp.CustomerName;
                        model.ContractType       = gp.ContractType;
                        model.ContractObject     = gp.ContractObject;
                        model.PurchaseUnitPrice  = gp.UnitPrice;
                        model.TotalPrice         = gp.UnitPrice * gm.ContractNum;
                        model.RealityPrice       = gp.UnitPrice * model.RealityPickdingNum;
                        model.RealityPayment     = gm.UnitPrice * model.RealityPickdingNum;
                        model.Spread             = gm.UnitPrice - gp.UnitPrice;
                        model.Profit             = (gm.UnitPrice - gp.UnitPrice) * model.RealityPickdingNum;
                        model.ProfitPercentage   = (model.Profit / model.RealityPrice) / 100;
                    }
                    model.Noter      = Session["LoginedUser"].ToString();
                    model.RecordTime = DateTime.Now;
                    if (GoodsProfitRepository.Update(model))
                    {
                        return(Json(new { Success = true }));
                    }
                }
                return(Json(new
                {
                    Success = false,
                    Message = "参数有误。"
                }));
            }
            catch (Exception ex)
            {
                LogRepository.Add(new EventLog()
                {
                    Name = Session["LoginedUser"].ToString(), Date = DateTime.Now.ToLocalTime(), Event = "更新利润核算表失败" + ex.Message
                });
                return(Json(new
                {
                    Success = false,
                    Message = ex.Message
                }));
            }
        }
        public async Task <ActionResult> GetGoodsMarketingDetails(string ID)
        {
            try
            {
                if (!string.IsNullOrEmpty(ID))
                {
                    Guid           gid    = new Guid(ID);
                    GoodsMarketing findgp = await GoodsMarketingRepository.FindAsync(p => p.GoodsMarketingID == gid);

                    if (findgp != null)
                    {
                        return(Json(new
                        {
                            Success = true,
                            CustomerName = findgp.CustomerName,
                            ContractNo = findgp.ContractNo,
                            SigningTime = findgp.SigningTime,
                            PickingType = findgp.PickingType,
                            ContractObject = findgp.ContractObject,
                            UnitPrice = findgp.UnitPrice,
                            ContractNum = findgp.ContractNum,
                            DeliveryTime = findgp.DeliveryTime.ToString("yyyy-MM-dd"),
                            AlreadyDeliveryNum = findgp.AlreadyDeliveryNum,
                            RealityDeliveryNum = findgp.RealityDeliveryNum,
                            LogisticsCost = findgp.LogisticsCost,
                            InvoiceStatus = findgp.InvoiceStatus,
                            AlreadyPayment = findgp.AlreadyPayment,
                            Remark = findgp.Remark
                        }, JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json(new
                {
                    Success = false,
                    Message = "参数有误。"
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogRepository.Add(new EventLog()
                {
                    Name = Session["LoginedUser"].ToString(), Date = DateTime.Now.ToLocalTime(), Event = "绑定现货销售合同明细失败" + ex.Message
                });
                return(Json(new
                {
                    Success = false,
                    Message = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <ActionResult> GetGoodsProfitDetails(string ID)
        {
            try
            {
                if (!string.IsNullOrEmpty(ID))
                {
                    Guid        gid    = new Guid(ID);
                    GoodsProfit findgp = await GoodsProfitRepository.FindAsync(p => p.GoodsProfitID == gid);

                    GoodsMarketing findgm = await GoodsMarketingRepository.FindAsync(m => m.GoodsMarketingID == findgp.GoodsMarketingID);

                    if (findgp != null && findgm != null)
                    {
                        return(Json(new
                        {
                            Success = true,
                            GoodsMarketingID = findgp.GoodsMarketingID,
                            ContractNo = findgm.ContractNo,
                            RealityPickdingNum = findgp.RealityPickdingNum,
                            ReflowTime = findgp.ReflowTime,
                            Status = findgp.Status,
                            Remark = findgp.Remark
                        }, JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json(new
                {
                    Success = false,
                    Message = "参数有误。"
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogRepository.Add(new EventLog()
                {
                    Name = Session["LoginedUser"].ToString(), Date = DateTime.Now.ToLocalTime(), Event = "绑定利润核算表明细失败" + ex.Message
                });
                return(Json(new
                {
                    Success = false,
                    Message = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <ActionResult> DeleteGoodsMarketing(string ID)
        {
            try
            {
                if (!string.IsNullOrEmpty(ID))
                {
                    Guid           gid    = new Guid(ID);
                    GoodsMarketing findgp = await GoodsMarketingRepository.FindAsync(p => p.GoodsMarketingID == gid);

                    if (findgp != null)
                    {
                        if (GoodsMarketingRepository.Delete(findgp))
                        {
                            return(Json(new { Success = true }));
                        }
                    }
                }
                return(Json(new
                {
                    Success = false,
                    Message = "参数有误。"
                }));
            }
            catch (Exception ex)
            {
                LogRepository.Add(new EventLog()
                {
                    Name = Session["LoginedUser"].ToString(), Date = DateTime.Now.ToLocalTime(), Event = "删除现货銷售合同失败" + ex.Message
                });
                return(Json(new
                {
                    Success = false,
                    Message = ex.Message
                }));
            }
        }
 public ActionResult UpdateGoodsMarketing(GoodsMarketing model)
 {
     try
     {
         if (model != null)
         {
             model.TotalPrice       = model.UnitPrice + model.ContractNum;
             model.AwaitDeliveryNum = model.ContractNum + model.AlreadyDeliveryNum;
             model.RealityPayment   = model.RealityDeliveryNum * model.UnitPrice;
             model.AwaitPayment     = model.RealityDeliveryNum * model.UnitPrice - model.AlreadyPayment;
             model.Noter            = Session["LoginedUser"].ToString();
             model.RecordTime       = DateTime.Now;
             if (GoodsMarketingRepository.Update(model))
             {
                 return(Json(new { Success = true }));
             }
         }
         return(Json(new
         {
             Success = false,
             Message = "参数有误。"
         }));
     }
     catch (Exception ex)
     {
         LogRepository.Add(new EventLog()
         {
             Name = Session["LoginedUser"].ToString(), Date = DateTime.Now.ToLocalTime(), Event = "更新现货销售合同失败" + ex.Message
         });
         return(Json(new
         {
             Success = false,
             Message = ex.Message
         }));
     }
 }