public bool SetPrimaryQuote(long user_id, long quote_id) { var user = UserInfoBLL.GetUserInfo(user_id); var quote = new crm_quote_dal().GetQuote(quote_id); if (quote != null) { var quoteList = new crm_quote_dal().GetQuoteByWhere($" and opportunity_id = {quote.opportunity_id} "); var primaryQuote = quoteList.FirstOrDefault(_ => _.is_primary_quote == 1); if (primaryQuote != null && quote.id != primaryQuote.id) { primaryQuote.is_primary_quote = null; primaryQuote.update_user_id = user.id; primaryQuote.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); var oldPrimaryQuote = new QuoteBLL().GetQuote(primaryQuote.id); 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, oper_object_id = primaryQuote.id,// 操作对象id oper_type_id = (int)OPER_LOG_TYPE.UPDATE, oper_description = _dal.CompareValue(oldPrimaryQuote, primaryQuote), remark = "更改主报价为报价" }); new crm_quote_dal().Update(primaryQuote); quote.is_primary_quote = 1; quote.update_user_id = user.id; quote.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); 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, oper_object_id = quote.id,// 操作对象id oper_type_id = (int)OPER_LOG_TYPE.UPDATE, oper_description = _dal.CompareValue(new crm_quote_dal().GetQuote(quote_id), quote), remark = "更改报价为主报价" }); new crm_quote_dal().Update(quote); } return(true); } return(false); }
/// <summary> /// 删除报价项 /// </summary> /// <param name="quote_item_id"></param> /// <param name="user_id"></param> /// <returns></returns> public bool DeleteQuoteItem(long quote_item_id, long user_id) { // todo 报价如果关联了销售订单,则不可删除报价项 -- 验证 var quote_item = _dal.GetQuoteItem(quote_item_id); var user = UserInfoBLL.GetUserInfo(user_id); if (quote_item != null && user != null) { var isSaleOrder = new QuoteBLL().CheckRelatSaleOrder(quote_item_id); if (isSaleOrder) { return(false); } quote_item.delete_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); quote_item.delete_user_id = user_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.DELETE, 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; 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); } } return(true); } return(false); }