Exemplo n.º 1
0
        /// <summary>
        /// 删除合同成本
        /// </summary>
        public void DeleteCost(HttpContext context, long cid)
        {
            string reason = "";
            var    result = new ContractCostBLL().DeleteContractCost(cid, LoginUserId, out reason);

            context.Response.Write(new Tools.Serialize().SerializeJson(new { result = result, reason = reason }));
        }
Exemplo n.º 2
0
        protected void save_close_Click(object sender, EventArgs e)
        {
            var thisConDefCost = AssembleModel <ctt_contract_cost_default>();

            thisConDefCost.is_billable = (sbyte)(isbillable.Checked ? 1 : 0);
            thisConDefCost.contract_id = contract.id;
            bool result = false;

            if (isAdd)
            {
                result = new ContractCostBLL().ConDefCostAddOrUpdate(thisConDefCost, GetLoginUserId());
            }
            else
            {
                conDefCost.unit_cost    = thisConDefCost.unit_cost;
                conDefCost.unit_price   = thisConDefCost.unit_price;
                conDefCost.is_billable  = thisConDefCost.is_billable;
                conDefCost.cost_code_id = thisConDefCost.cost_code_id;
                result = new ContractCostBLL().ConDefCostAddOrUpdate(conDefCost, GetLoginUserId());
            }

            if (result)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('保存默认成本成功!');window.close();self.opener.location.reload();</script>");
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('保存默认成本失败!');window.close();self.opener.location.reload();</script>");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 删除合同默认成本
        /// </summary>
        public void DeleteDefaultCost(HttpContext context, long cdcID)
        {
            bool result = false;


            result = new ContractCostBLL().DeleteConDefCost(cdcID, LoginUserId);

            context.Response.Write(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 取消配送
        /// </summary>
        private void UnShipItem(HttpContext context)
        {
            var thisCostId = context.Request.QueryString["costProId"];

            if (!string.IsNullOrEmpty(thisCostId))
            {
                var isDelete = true; // 配送成本是否删除
                var result   = new ContractCostBLL().UnShipItem(long.Parse(thisCostId), LoginUserId, out isDelete);
                //  isDelete = false; 代表有运费成本 并且已经审核无法删除
                context.Response.Write(new Tools.Serialize().SerializeJson(new { result = result, reason = isDelete }));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取成本的客户信息
        /// </summary>
        private void GetCostAccount(HttpContext context, long cost_id)
        {
            var accountId = new ContractCostBLL().GetAccountIdByCostId(cost_id);

            if (accountId != null)
            {
                var account = new CompanyBLL().GetCompany((long)accountId);
                if (account != null)
                {
                    context.Response.Write(new Tools.Serialize().SerializeJson(account));
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 采购审批通过
        /// </summary>
        /// <param name="context"></param>
        private void PurchaseApproval(HttpContext context)
        {
            var id = context.Request.QueryString["ids"];

            string[] ids = id.Split(',');
            var      bll = new ContractCostBLL();

            foreach (string costId in ids)
            {
                bll.PurchaseApproval(long.Parse(costId), LoginUserId);
            }
            context.Response.Write(new Tools.Serialize().SerializeJson(true));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 配送产品
        /// </summary>
        private void ShipItem(HttpContext context)
        {
            var result      = true;    // 配送结果
            var isDoneOrder = false;   // 是否完成销售订单

            try
            {
                #region  获取相关参数
                var costId           = long.Parse(context.Request.QueryString["cost_id"]);
                var wareId           = long.Parse(context.Request.QueryString["wareId"]);
                var productId        = long.Parse(context.Request.QueryString["productId"]);
                var ShipNum          = int.Parse(context.Request.QueryString["ShipNum"]);
                var shipSerIds       = context.Request.QueryString["shipSerIds"];
                var ShipDate         = DateTime.Parse(context.Request.QueryString["ShipDate"]);
                int?shipping_type_id = null;
                if (!string.IsNullOrEmpty(context.Request.QueryString["shipping_type_id"]))
                {
                    shipping_type_id = int.Parse(context.Request.QueryString["shipping_type_id"]);
                }
                long?ShipCostCodeId = null;
                if (!string.IsNullOrEmpty(context.Request.QueryString["ShipCostCodeId"]))
                {
                    ShipCostCodeId = long.Parse(context.Request.QueryString["ShipCostCodeId"]);
                }
                var     shipping_reference_number = context.Request.QueryString["shipping_reference_number"];
                decimal?BillMoney = null;
                if (!string.IsNullOrEmpty(context.Request.QueryString["BillMoney"]))
                {
                    BillMoney = decimal.Parse(context.Request.QueryString["BillMoney"]);
                }
                decimal?BillCost = null;
                if (!string.IsNullOrEmpty(context.Request.QueryString["BillCost"]))
                {
                    BillCost = decimal.Parse(context.Request.QueryString["BillCost"]);
                }
                var costProId = long.Parse(context.Request.QueryString["costProId"]);
                #endregion
                var ccBll = new ContractCostBLL();
                result = ccBll.ShipItem(costId, productId, wareId, ShipNum, shipSerIds, ShipDate, shipping_type_id, shipping_reference_number, LoginUserId, costProId, ShipCostCodeId, BillMoney, BillCost);
                ccBll.ChangCostStatus(costId, LoginUserId);
                // 是否完成销售订单(返回页面进行处理)


                new SaleOrderBLL().ChangeSaleOrderStatus(costId, LoginUserId, out isDoneOrder);
            }
            catch (Exception)
            {
                result = false;
            }
            context.Response.Write(new Tools.Serialize().SerializeJson(new { result = result, reason = isDoneOrder }));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 库存转移
        /// </summary>
        /// <param name="context"></param>
        /// <param name="product_id"></param>
        /// <param name="ware_id"></param>
        /// <param name="transNum"></param>
        /// <param name="serSnIds"></param>
        /// <param name="transType"></param>
        /// <param name="cost_id"></param>
        /// <param name="account_id"></param>
        /// <param name="toLocaId"></param>
        public void TransferPro(HttpContext context, long product_id, long ware_id, int transNum, string serSnIds, string transType, long cost_id, long account_id, long toLocaId, long costProId)
        {
            var result = false;

            var ccBll = new ContractCostBLL();

            if (transType == "ToAccount")
            {
                result = ccBll.TransferToAccount(cost_id, product_id, ware_id, account_id, transNum, serSnIds, LoginUserId, costProId);
            }
            else if (transType == "ToMe")
            {
                // todo 库存数量未完全转移 未转移完成
                result = ccBll.TransToMe(product_id, transNum, ware_id, serSnIds, LoginUserId);
            }
            else if (transType == "ToLocation")
            {
                result = ccBll.TransToLocation(product_id, transNum, ware_id, serSnIds, toLocaId, LoginUserId, cost_id, costProId);
            }
            context.Response.Write(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 拣货操作
        /// </summary>
        /// <param name="context"></param>
        /// <param name="product_id">产品</param>
        /// <param name="ware_id">仓库</param>
        /// <param name="pickNum">拣货数量</param>
        /// <param name="serNumIds">序列号</param>
        /// <param name="tranType">库存转移方式</param>
        public void PickProduct(HttpContext context, long product_id, long ware_id, int pickNum, string serNumIds, string tranType, long cost_id)
        {
            // tranType  ---  wareHouse    toMe   toItem
            var ccBll  = new ContractCostBLL();
            var result = ccBll.AddCostProduct(cost_id, product_id, ware_id, pickNum, tranType, serNumIds, LoginUserId);

            ccBll.ChangCostStatus(cost_id, LoginUserId);
            // 是否完成销售订单(返回页面进行处理)
            var isDoneOrder = false;

            new SaleOrderBLL().ChangeSaleOrderStatus(cost_id, LoginUserId, out isDoneOrder);
            if (tranType == "toMe")
            {
                result = ccBll.TransToMe(product_id, pickNum, ware_id, serNumIds, LoginUserId);
            }
            else if (tranType == "toItem")
            {
                result = ccBll.TranToItem(product_id, pickNum, ware_id, serNumIds, cost_id, LoginUserId);
            }
            context.Response.Write(new Tools.Serialize().SerializeJson(new { result = result, reason = isDoneOrder }));
        }
Exemplo n.º 10
0
        protected void save_add_Click(object sender, EventArgs e)
        {
            var        param              = GetParam();
            bool       isDelShipCost      = false; // 是否删除 配送的运费成本  为true 时,代表需要删除的成本已经审批提交,此时提示用户
            var        isHasPurchaseOrder = "";    // 是否有采购单需要更改
            ERROR_CODE result             = ERROR_CODE.SUCCESS;

            if (isAdd)
            {
                result = new ContractCostBLL().InsertCost(param, GetLoginUserId());
            }
            else
            {
                result = new ContractCostBLL().UpdateCost(param, GetLoginUserId(), out isDelShipCost, out isHasPurchaseOrder);
            }

            switch (result)
            {
            case ERROR_CODE.SUCCESS:
                if (!string.IsNullOrEmpty(isHasPurchaseOrder))
                {
                    isHasPurchaseOrder = isHasPurchaseOrder.Substring(0, isHasPurchaseOrder.Length - 1);
                    ClientScript.RegisterStartupScript(this.GetType(), "采购单信息提示", "<script>alert('成本有对应的采购订单:" + isHasPurchaseOrder + ",请手工处理。!');</script>");
                }
                var thisURL = "";
                if (isAdd)
                {
                    thisURL = Request.Url.ToString();
                }
                else
                {
                    thisURL = "AddCharges.aspx?";
                    if (contract != null)
                    {
                        thisURL += "&contract_id=" + contract.id;
                    }
                    if (thisTask != null)
                    {
                        thisURL += "&task_id=" + thisTask.id;
                    }
                    if (thisProject != null)
                    {
                        thisURL += "&project_id=" + thisProject.id;
                    }
                }


                if (param.isAddCongigItem)
                {
                    var url = "../ConfigurationItem/ConfigItemWizard.aspx?&cost_id=" + param.cost.id;
                    if (contract != null)
                    {
                        url += "&contract_id=" + contract.id;
                    }
                    if (thisTask != null)
                    {
                        url += "&task_id=" + thisTask.id;
                    }
                    if (thisProject != null)
                    {
                        url += "&project_id=" + thisProject.id;
                    }
                    if (isDelShipCost)
                    {
                        // 运费成本已审批并提交,无法删除。
                        ClientScript.RegisterStartupScript(this.GetType(), "运费成本信息提示", "<script>alert('运费成本已审批并提交,无法删除!');</script>");
                    }

                    ClientScript.RegisterStartupScript(this.GetType(), "打开新窗口", "<script>alert('保存成功!');location.href='" + thisURL + "';window.open('" + url + "','" + (int)EMT.DoneNOW.DTO.OpenWindow.InstalledProductIwarid + "','left= 200, top = 200, width = 960, height = 750', false);self.opener.location.reload();</script>");
                }
                else
                {
                    // ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('保存成功!');location.href='AddCharges.aspx?contract_id=" + contract.id + "';self.opener.location.reload(); </script>");
                    ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('保存成功!');location.href='" + thisURL + "';self.opener.location.reload(); </script>");
                }
                break;

            case ERROR_CODE.PARAMS_ERROR:
                ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('必填参数丢失,请重新填写'); </script>");
                break;

            case ERROR_CODE.USER_NOT_FIND:
                Response.Write("<script>alert('查询不到用户,请重新登陆');</script>");
                Response.Redirect("../Login.aspx");
                break;

            default:
                break;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 批量删除合同成本
        /// </summary>
        public void DeleteCosts(HttpContext context, string ids)
        {
            var result = new ContractCostBLL().DeleteContractCosts(ids, LoginUserId);

            context.Response.Write(result);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 批量更该成本为是否可计费
        /// </summary>
        public void ChangeManyChargeIsBilled(HttpContext context, string ccids, int isBilled)
        {
            var result = new ContractCostBLL().UpdateManyBillStatus(ccids, LoginUserId, isBilled);

            context.Response.Write(result);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 更该成本为是否可计费
        /// </summary>
        public void ChangeChargeIsBilled(HttpContext context, long cid, int isBilled)
        {
            var result = new ContractCostBLL().UpdateBillStatus(cid, LoginUserId, isBilled);

            context.Response.Write(result);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 取消拣货
        /// </summary>
        public void UnPickProduct(HttpContext context, long product_id, long ware_id, int unPickNum, string SerSnIds, long cost_id, long costProId)
        {
            var result = new ContractCostBLL().UnPick(cost_id, product_id, ware_id, unPickNum, SerSnIds, LoginUserId, costProId);

            context.Response.Write(result);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 新增报价项
        /// </summary>
        /// <param name="quote_item"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public ERROR_CODE Insert(crm_quote_item quote_item, Dictionary <long, int> wareDic, long user_id, bool isSaleOrder = false, long?saleOrderId = null)
        {
            if (quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISCOUNT)
            {
                if (quote_item.unit_price == null || quote_item.unit_cost == null || quote_item.quantity == null || quote_item.unit_discount == null)
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
                if (string.IsNullOrEmpty(quote_item.name))
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(quote_item.name))
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
                if (quote_item.discount_percent == null && quote_item.unit_discount == null)
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
            }

            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {
                return(ERROR_CODE.USER_NOT_FIND);
            }
            quote_item.id             = _dal.GetNextIdCom();
            quote_item.tax_cate_id    = quote_item.tax_cate_id == 0 ? null : quote_item.tax_cate_id;
            quote_item.period_type_id = quote_item.period_type_id == 0 ? null : quote_item.period_type_id;
            quote_item.create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote_item.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote_item.create_user_id = user_id;
            quote_item.update_user_id = user_id;

            _dal.Insert(quote_item);
            new sys_oper_log_dal().Insert(new sys_oper_log()
            {
                user_cate           = "用户",
                user_id             = (int)user.id,
                name                = user.name,
                phone               = user.mobile == null ? "" : user.mobile,
                oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.QUOTE_ITEM,
                oper_object_id      = quote_item.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                oper_description    = _dal.AddValue(quote_item),
                remark              = "保存报价项信息"
            });

            var oDal = new crm_opportunity_dal();
            var oppo = oDal.GetOpByItemID(quote_item.id);

            if (oppo != null && oppo.use_quote == 1)
            {
                if (quote_item.optional != 1 && quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES)
                {
                    decimal?changeRevenue = quote_item.quantity * ((quote_item.unit_price ?? 0) - (quote_item.unit_discount ?? 0));
                    decimal?changeCost    = quote_item.quantity * quote_item.unit_cost;

                    switch (quote_item.period_type_id)
                    {
                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME:
                        oppo.one_time_revenue += (changeRevenue ?? 0);
                        oppo.one_time_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.MONTH:
                        oppo.monthly_revenue += (changeRevenue ?? 0);
                        oppo.monthly_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.QUARTER:
                        oppo.quarterly_revenue += (changeRevenue ?? 0);
                        oppo.quarterly_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.HALFYEAR:
                        oppo.semi_annual_revenue += (changeRevenue ?? 0);
                        oppo.semi_annual_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.YEAR:
                        oppo.yearly_revenue += (changeRevenue ?? 0);
                        oppo.yearly_cost    += (changeCost ?? 0);
                        break;

                    default:
                        break;
                    }

                    // var udfDto = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.OPPORTUNITY);
                    // var udfValue =
                    OpportunityAddOrUpdateDto param = new OpportunityAddOrUpdateDto()
                    {
                        general = oppo,
                        udf     = null,
                        notify  = null
                    };
                    new OpportunityBLL().Update(param, user.id);
                }
            }
            if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
            {
                if (wareDic != null && wareDic.Count > 0)
                {
                    var irDal = new ivt_reserve_dal();
                    var iwDal = new ivt_warehouse_dal();
                    foreach (var thisPageWare in wareDic)
                    {
                        var thisWareHouse = iwDal.FindNoDeleteById(thisPageWare.Key);
                        if (thisWareHouse != null && thisPageWare.Value != 0)
                        {
                            var thisReserve = new ivt_reserve()
                            {
                                id             = irDal.GetNextIdCom(),
                                create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                create_user_id = user_id,
                                update_user_id = user_id,
                                quote_item_id  = quote_item.id,
                                warehouse_id   = thisPageWare.Key,
                                quantity       = thisPageWare.Value,
                                resource_id    = thisWareHouse.resource_id,
                            };
                            irDal.Insert(thisReserve);
                            OperLogBLL.OperLogAdd <ivt_reserve>(thisReserve, thisReserve.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "新增库存预留");
                        }
                    }
                }
            }

            if (isSaleOrder && saleOrderId != null && (quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.PRODUCT || quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.DEGRESSION || quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES))
            {
                var cccDal   = new ctt_contract_cost_dal();
                var costList = cccDal.GetListBySaleOrderId((long)saleOrderId);
                if (costList != null && costList.Count > 0)
                {
                    int  status_id    = 0;
                    long cost_code_id = (long)quote_item.object_id;
                    long?product_id   = null;
                    if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
                    {
                        product_id = quote_item.object_id;
                        status_id  = (int)COST_STATUS.PENDING_PURCHASE;
                        var thisProduct = new ivt_product_dal().FindNoDeleteById((long)quote_item.object_id);
                        if (thisProduct != null)
                        {
                            cost_code_id = thisProduct.cost_code_id;
                        }
                        else
                        {
                            return(ERROR_CODE.ERROR);
                        }
                        var appSet = new SysSettingBLL().GetSetById(DTO.SysSettingEnum.CTT_COST_APPROVAL_VALUE);
                        if (appSet != null && !string.IsNullOrEmpty(appSet.setting_value) && thisProduct.does_not_require_procurement == 0) // 该产品走采购流程,并且价格大于设置,则带审批
                        {
                            if (((decimal)quote_item.quantity * (decimal)quote_item.unit_price) > decimal.Parse(appSet.setting_value))      // 金额超出(待审批)
                            {
                                status_id = (int)COST_STATUS.PENDING_APPROVAL;
                            }
                        }
                    }
                    else
                    {
                        status_id = (int)COST_STATUS.PENDING_DELIVERY;
                    }
                    ctt_contract_cost cost = new ctt_contract_cost()
                    {
                        id             = _dal.GetNextIdCom(),
                        opportunity_id = costList[0].opportunity_id,
                        quote_item_id  = quote_item.id,
                        cost_code_id   = cost_code_id,
                        product_id     = product_id,
                        name           = quote_item.name,
                        description    = quote_item.description,
                        date_purchased = DateTime.Now,
                        is_billable    = 1,
                        bill_status    = 0,
                        cost_type_id   = (int)COST_TYPE.OPERATIONA,
                        status_id      = status_id,
                        quantity       = quote_item.quantity ?? 0,
                        unit_price     = (quote_item.unit_price ?? 0) - (quote_item.unit_discount ?? 0),
                        unit_cost      = quote_item.unit_cost,
                        extended_price = ((quote_item.unit_price ?? 0) - (quote_item.unit_discount ?? 0)) * quote_item.quantity,
                        create_user_id = user.id,
                        update_user_id = user.id,
                        create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                        update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                        project_id     = costList[0].project_id,
                        contract_id    = costList[0].contract_id,
                        task_id        = costList[0].task_id,
                        sub_cate_id    = costList[0].sub_cate_id,
                    };
                    cccDal.Insert(cost);
                    OperLogBLL.OperLogAdd <ctt_contract_cost>(cost, cost.id, user_id, OPER_LOG_OBJ_CATE.CONTRACT_COST, "新增成本");
                    if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
                    {
                        var ccBll          = new ContractCostBLL();
                        var irDal          = new ivt_reserve_dal();
                        var thisPro        = new ivt_product_dal().FindNoDeleteById((long)quote_item.object_id);
                        var thisProResList = irDal.GetListByItemId(quote_item.id);
                        if (thisProResList != null && thisProResList.Count > 0 && thisPro != null)
                        {
                            foreach (var thisProRes in thisProResList)
                            {
                                ccBll.AddCostProduct(cost.id, thisPro.id, thisProRes.warehouse_id, thisProRes.quantity, "", "", user.id);

                                irDal.SoftDelete(thisProRes, user.id);
                                OperLogBLL.OperLogDelete <ivt_reserve>(thisProRes, thisProRes.id, user.id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "删除产品预留");
                            }
                            ccBll.ChangCostStatus(cost.id, user_id);
                        }
                    }
                }
            }

            return(ERROR_CODE.SUCCESS);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 编辑报价项
        /// </summary>
        /// <param name="quote_item"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public ERROR_CODE Update(crm_quote_item quote_item, Dictionary <long, int> wareDic, long user_id, bool isSaleOrder = false, long?saleOrderId = null)
        {
            if (quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISCOUNT)
            {
                if (quote_item.unit_price == null || quote_item.unit_cost == null || quote_item.quantity == null || quote_item.unit_discount == null)
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
                if (string.IsNullOrEmpty(quote_item.name))
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(quote_item.name))
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
                if (quote_item.discount_percent == null && quote_item.unit_discount == null)
                {
                    return(ERROR_CODE.PARAMS_ERROR);
                }
            }
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {
                return(ERROR_CODE.USER_NOT_FIND);
            }
            var old_quote_item = _dal.GetQuoteItem(quote_item.id);
            int?oldPeriod      = old_quote_item.period_type_id;

            quote_item.oid            = old_quote_item.oid;
            quote_item.update_user_id = user_id;
            quote_item.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote_item.tax_cate_id    = quote_item.tax_cate_id == 0 ? null : quote_item.tax_cate_id;
            _dal.Update(quote_item);
            new sys_oper_log_dal().Insert(new sys_oper_log()
            {
                user_cate           = "用户",
                user_id             = (int)user.id,
                name                = user.name,
                phone               = user.mobile == null ? "" : user.mobile,
                oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.QUOTE_ITEM,
                oper_object_id      = quote_item.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                oper_description    = _dal.CompareValue(old_quote_item, quote_item),
                remark              = "编辑报价项信息"
            });

            var oDal = new crm_opportunity_dal();
            var oppo = oDal.GetOpByItemID(quote_item.id);

            if (oppo != null && oppo.use_quote == 1)
            {
                if (quote_item.optional != 1 && quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && quote_item.type_id != (int)DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES)
                {
                    decimal?changeRevenue = quote_item.quantity * quote_item.unit_price;
                    decimal?changeCost    = quote_item.quantity * quote_item.unit_cost;

                    decimal?oldChangeRevenue = old_quote_item.quantity * ((old_quote_item.unit_price ?? 0) - (old_quote_item.unit_discount ?? 0));
                    decimal?oldChangeCost    = old_quote_item.quantity * old_quote_item.unit_cost;
                    switch (oldPeriod)
                    {
                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME:
                        oppo.one_time_revenue = oppo.one_time_revenue - (oldChangeRevenue ?? 0);
                        oppo.one_time_cost    = oppo.one_time_cost - (oldChangeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.MONTH:
                        oppo.one_time_revenue = oppo.one_time_revenue - (oldChangeRevenue ?? 0);
                        oppo.one_time_cost    = oppo.one_time_cost - (oldChangeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.QUARTER:
                        oppo.one_time_revenue = oppo.one_time_revenue - (oldChangeRevenue ?? 0);
                        oppo.one_time_cost    = oppo.one_time_cost - (oldChangeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.HALFYEAR:
                        oppo.one_time_revenue = oppo.one_time_revenue - (oldChangeRevenue ?? 0);
                        oppo.one_time_cost    = oppo.one_time_cost - (oldChangeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.YEAR:
                        oppo.one_time_revenue = oppo.one_time_revenue - (oldChangeRevenue ?? 0);
                        oppo.one_time_cost    = oppo.one_time_cost - (oldChangeCost ?? 0);
                        break;

                    default:
                        break;
                    }

                    switch (quote_item.period_type_id)
                    {
                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME:
                        oppo.one_time_revenue += (changeRevenue ?? 0);
                        oppo.one_time_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.MONTH:
                        oppo.monthly_revenue += (changeRevenue ?? 0);
                        oppo.monthly_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.QUARTER:
                        oppo.quarterly_revenue += (changeRevenue ?? 0);
                        oppo.quarterly_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.HALFYEAR:
                        oppo.semi_annual_revenue += (changeRevenue ?? 0);
                        oppo.semi_annual_cost    += (changeCost ?? 0);
                        break;

                    case (int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.YEAR:
                        oppo.yearly_revenue += (changeRevenue ?? 0);
                        oppo.yearly_cost    += (changeCost ?? 0);
                        break;

                    default:
                        break;
                    }

                    // var udfDto = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.OPPORTUNITY);
                    // var udfValue =
                    OpportunityAddOrUpdateDto param = new OpportunityAddOrUpdateDto()
                    {
                        general = oppo,
                        udf     = null,
                        notify  = null
                    };
                    new OpportunityBLL().Update(param, user.id);
                }
            }


            if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
            {
                var irDal        = new ivt_reserve_dal();
                var iwDal        = new ivt_warehouse_dal();
                var oldReserList = irDal.GetListByItemId(quote_item.id);
                if (wareDic != null && wareDic.Count > 0)
                {
                    if (oldReserList != null && oldReserList.Count > 0)
                    {
                        foreach (var thisPageWare in wareDic)
                        {
                            var thisWareHouse = iwDal.FindNoDeleteById(thisPageWare.Key);

                            var thisOldReser = oldReserList.FirstOrDefault(_ => _.warehouse_id == thisPageWare.Key);
                            if (thisOldReser != null)
                            {
                                oldReserList.Remove(thisOldReser);
                                if (thisWareHouse != null)
                                {
                                    if (thisPageWare.Value == 0)
                                    {
                                        irDal.SoftDelete(thisOldReser, user_id);
                                        OperLogBLL.OperLogDelete <ivt_reserve>(thisOldReser, thisOldReser.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "删除库存预留");
                                        continue;
                                    }
                                    if (thisOldReser.quantity != thisPageWare.Value || thisOldReser.resource_id != thisWareHouse.resource_id)
                                    {
                                        thisOldReser.quantity    = thisPageWare.Value;
                                        thisOldReser.resource_id = thisWareHouse.resource_id;
                                        var thisOld = irDal.FindNoDeleteById(thisOldReser.id);
                                        irDal.Update(thisOldReser);
                                        OperLogBLL.OperLogUpdate <ivt_reserve>(thisOldReser, thisOld, thisOldReser.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "修改库存预留");
                                    }
                                }
                            }
                            else
                            {
                                if (thisWareHouse != null && thisPageWare.Value != 0)
                                {
                                    var thisReserve = new ivt_reserve()
                                    {
                                        id             = irDal.GetNextIdCom(),
                                        create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                        update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                        create_user_id = user_id,
                                        update_user_id = user_id,
                                        quote_item_id  = quote_item.id,
                                        warehouse_id   = thisPageWare.Key,
                                        quantity       = thisPageWare.Value,
                                        resource_id    = thisWareHouse.resource_id,
                                    };
                                    irDal.Insert(thisReserve);
                                    OperLogBLL.OperLogAdd <ivt_reserve>(thisReserve, thisReserve.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "新增库存预留");
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (var thisPageWare in wareDic)
                        {
                            var thisWareHouse = iwDal.FindNoDeleteById(thisPageWare.Key);
                            if (thisWareHouse != null)
                            {
                                var thisReserve = new ivt_reserve()
                                {
                                    id             = irDal.GetNextIdCom(),
                                    create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                    update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                                    create_user_id = user_id,
                                    update_user_id = user_id,
                                    quote_item_id  = quote_item.id,
                                    warehouse_id   = thisPageWare.Key,
                                    quantity       = thisPageWare.Value,
                                    resource_id    = thisWareHouse.resource_id,
                                };
                                irDal.Insert(thisReserve);
                                OperLogBLL.OperLogAdd <ivt_reserve>(thisReserve, thisReserve.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "新增库存预留");
                            }
                        }
                    }
                }

                if (oldReserList != null && oldReserList.Count > 0)
                {
                    oldReserList.ForEach(_ =>
                    {
                        irDal.SoftDelete(_, user_id);
                        OperLogBLL.OperLogDelete <ivt_reserve>(_, _.id, user_id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "删除库存预留");
                    });
                }
            }


            if (isSaleOrder && saleOrderId != null && (quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.PRODUCT || quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.DEGRESSION || quote_item.type_id == (int)DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES))
            {
                var cccDal   = new ctt_contract_cost_dal();
                var thisCost = cccDal.GetSinBuQuoteItem(quote_item.id);
                if (thisCost != null)
                {
                    long?product_id   = thisCost.product_id;
                    int  status_id    = thisCost.status_id;
                    long cost_code_id = thisCost.cost_code_id;
                    if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
                    {
                        product_id = quote_item.object_id;
                        status_id  = thisCost.status_id;
                        var thisProduct = new ivt_product_dal().FindNoDeleteById((long)quote_item.object_id);
                        if (thisProduct != null)
                        {
                            cost_code_id = thisProduct.cost_code_id;
                        }
                        else
                        {
                            return(ERROR_CODE.ERROR);
                        }
                        if (status_id != (int)COST_STATUS.UNDETERMINED && status_id != (int)COST_STATUS.PENDING_APPROVAL && status_id != (int)COST_STATUS.CANCELED)
                        {
                            if (thisCost.quantity != quote_item.quantity)
                            {
                                status_id = (int)COST_STATUS.PENDING_PURCHASE;
                                var appSet = new SysSettingBLL().GetSetById(DTO.SysSettingEnum.CTT_COST_APPROVAL_VALUE);
                                if (appSet != null && !string.IsNullOrEmpty(appSet.setting_value) && thisProduct.does_not_require_procurement == 0)
                                {
                                    if (((decimal)quote_item.quantity * (decimal)quote_item.unit_price) > decimal.Parse(appSet.setting_value)) // 金额超出(待审批)
                                    {
                                        status_id = (int)COST_STATUS.PENDING_APPROVAL;
                                    }
                                }
                            }
                        }
                    }
                    thisCost.product_id   = product_id;
                    thisCost.cost_code_id = cost_code_id;
                    thisCost.name         = quote_item.name;
                    thisCost.description  = quote_item.description;
                    thisCost.unit_price   = (quote_item.unit_price ?? 0) - (quote_item.unit_discount ?? 0);
                    thisCost.unit_cost    = quote_item.unit_cost;
                    thisCost.quantity     = quote_item.quantity;
                    thisCost.status_id    = status_id;

                    var olderCost = cccDal.FindNoDeleteById(thisCost.id);
                    cccDal.Update(thisCost);
                    OperLogBLL.OperLogUpdate <ctt_contract_cost>(thisCost, olderCost, thisCost.id, user_id, OPER_LOG_OBJ_CATE.CONTRACT_COST, "修改成本");
                    if (quote_item.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT)
                    {
                        var ccBll          = new ContractCostBLL();
                        var irDal          = new ivt_reserve_dal();
                        var thisPro        = new ivt_product_dal().FindNoDeleteById((long)quote_item.object_id);
                        var thisProResList = irDal.GetListByItemId(quote_item.id);
                        if (thisProResList != null && thisProResList.Count > 0 && thisPro != null)
                        {
                            foreach (var thisProRes in thisProResList)
                            {
                                ccBll.AddCostProduct(thisCost.id, thisPro.id, thisProRes.warehouse_id, thisProRes.quantity, "", "", user.id);

                                irDal.SoftDelete(thisProRes, user.id);
                                OperLogBLL.OperLogDelete <ivt_reserve>(thisProRes, thisProRes.id, user.id, OPER_LOG_OBJ_CATE.WAREHOUSE_RESERVE, "删除产品预留");
                            }
                            ccBll.ChangCostStatus(thisCost.id, user_id);
                        }
                    }
                }
            }

            return(ERROR_CODE.SUCCESS);
        }