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); }
void GetQuote(HttpContext context) { var quoteId = context.Request.QueryString["quoteId"]; if (!string.IsNullOrEmpty(quoteId)) { var item = new crm_quote_dal().FindNoDeleteById(long.Parse(quoteId)); if (item != null) { WriteResponseJson(item); } } }
/// <summary> /// 判断crm_quote表是否引用当前报价模板 /// </summary> /// <returns></returns> public ERROR_CODE is_quote(int id) { string sql = $"select * from crm_quote where quote_tmpl_id = {id} and delete_time = 0"; var crm_quote_dal = new crm_quote_dal(); var templ = crm_quote_dal.FindSignleBySql <crm_quote>(sql); if (templ != null) { return(ERROR_CODE.ERROR); } return(ERROR_CODE.SUCCESS); }
/// <summary> /// 根据报价税区 和税种 返回税率 /// </summary> public void GetTax(HttpContext context) { var quote_id = context.Request.QueryString["quote_id"]; var tax_cate_id = context.Request.QueryString["tax_cate_id"]; if (!string.IsNullOrEmpty(quote_id) && !string.IsNullOrEmpty(tax_cate_id)) { var thisQuote = new crm_quote_dal().FindNoDeleteById(long.Parse(quote_id)); if (thisQuote != null && thisQuote.tax_region_id != null) { var taxCate = new d_tax_region_cate_dal().GetSingleTax((long)thisQuote.tax_region_id,long.Parse(tax_cate_id)); if (taxCate != null) { context.Response.Write(taxCate.total_effective_tax_rate); } } } }
/// <summary> /// 商机计算 /// </summary> private void GetQuoteItemMoney(HttpContext context, long oid) { var oppo = new crm_opportunity_dal().FindNoDeleteById(oid); if (oppo != null) { // 将一次性,按月,季度,赋值之后 , 需要将配送的金额和折扣的金额 存储之后计算 var priQuote = new crm_quote_dal().GetPriQuote(oid); if (priQuote != null) { decimal oneTimeRevenue = 0; decimal oneTimeCost = 0; decimal monthRevenue = 0; decimal monthCost = 0; decimal quarterRevenue = 0; decimal quarterCost = 0; decimal halfRevenue = 0; decimal halfCost = 0; decimal yearRevenue = 0; decimal yearCost = 0; decimal shipRevenue = 0; decimal shipCost = 0; decimal discount = 0; var itemList = new crm_quote_item_dal().GetAllQuoteItem(priQuote.id); if (itemList != null && itemList.Count > 0) { var thisItem = itemList.Where(_ => _.type_id != (int)EMT.DoneNOW.DTO.DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES && _.optional != 1 && _.type_id != (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT).ToList(); var shipList = itemList.Where(_ => _.type_id == (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES && _.optional == 0).ToList(); // 配送类型的报价项 var thisOneTimeList = itemList.Where(_ => _.period_type_id == (int)DTO.DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME && _.optional == 0 && _.type_id != (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && _.type_id != (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES).ToList(); var discountQIList = itemList.Where(_ => _.type_id == (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && _.optional == 0).ToList(); if (shipList != null && shipList.Count > 0) { var totalPrice = shipList.Sum(_ => (_.unit_discount != null && _.unit_price != null && _.quantity != null) ? (_.unit_price - _.unit_discount) * _.quantity : 0); shipRevenue = (decimal)totalPrice; var totalCost = shipList.Sum(_ => (_.unit_cost != null && _.quantity != null) ? _.unit_cost * _.quantity : 0); shipCost = (decimal)totalCost; } if (discountQIList != null && discountQIList.Count > 0) { var totalPrice = (discountQIList.Where(_ => _.discount_percent == null).ToList().Sum(_ => (_.unit_discount != null && _.quantity != null) ? _.unit_discount * _.quantity : 0) + (thisOneTimeList != null && thisOneTimeList.Count > 0 ? discountQIList.Where(_ => _.discount_percent != null).ToList().Sum(_ => thisOneTimeList.Sum(one => (one.unit_discount != null && one.unit_price != null && one.quantity != null) ? (one.unit_price - one.unit_discount) * one.quantity : 0) * _.discount_percent * 100 / 100) : 0)); discount = (decimal)totalPrice; } if (thisItem != null && thisItem.Count > 0) { var oneTimeList = thisItem.Where(_ => _.period_type_id == (int)DTO.DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME).ToList(); var monthList = thisItem.Where(_ => _.period_type_id == (int)DTO.DicEnum.QUOTE_ITEM_PERIOD_TYPE.MONTH).ToList(); var quarterList = thisItem.Where(_ => _.period_type_id == (int)DTO.DicEnum.QUOTE_ITEM_PERIOD_TYPE.QUARTER).ToList(); var halfList = thisItem.Where(_ => _.period_type_id == (int)DTO.DicEnum.QUOTE_ITEM_PERIOD_TYPE.HALFYEAR).ToList(); var yearList = thisItem.Where(_ => _.period_type_id == (int)DTO.DicEnum.QUOTE_ITEM_PERIOD_TYPE.YEAR).ToList(); if (oneTimeList != null && oneTimeList.Count > 0) { oneTimeRevenue = (decimal)oneTimeList.Sum(_ => (_.unit_price != null && _.quantity != null) ? (((_.unit_price ?? 0) - (_.unit_discount ?? 0)) * _.quantity) : 0); oneTimeCost = (decimal)oneTimeList.Sum(_ => (_.unit_cost != null && _.quantity != null) ? (_.unit_cost * _.quantity) : 0); } if (monthList != null && monthList.Count > 0) { monthRevenue = (decimal)monthList.Sum(_ => (_.unit_price != null && _.quantity != null) ? (((_.unit_price ?? 0) - (_.unit_discount ?? 0)) * _.quantity) : 0); monthCost = (decimal)monthList.Sum(_ => (_.unit_cost != null && _.quantity != null) ? (_.unit_cost * _.quantity) : 0); } if (quarterList != null && quarterList.Count > 0) { quarterRevenue = (decimal)quarterList.Sum(_ => (_.unit_price != null && _.quantity != null) ? (((_.unit_price ?? 0) - (_.unit_discount ?? 0)) * _.quantity) : 0); quarterCost = (decimal)quarterList.Sum(_ => (_.unit_cost != null && _.quantity != null) ? (_.unit_cost * _.quantity) : 0); } if (halfList != null && halfList.Count > 0) { halfRevenue = (decimal)halfList.Sum(_ => (_.unit_price != null && _.quantity != null) ? (((_.unit_price ?? 0) - (_.unit_discount ?? 0)) * _.quantity) : 0); halfCost = (decimal)halfList.Sum(_ => (_.unit_cost != null && _.quantity != null) ? (_.unit_cost * _.quantity) : 0); } if (yearList != null && yearList.Count > 0) { yearRevenue = (decimal)yearList.Sum(_ => (_.unit_price != null && _.quantity != null) ? (((_.unit_price ?? 0) - (_.unit_discount ?? 0)) * _.quantity) : 0); yearCost = (decimal)yearList.Sum(_ => (_.unit_cost != null && _.quantity != null) ? (_.unit_cost * _.quantity) : 0); } } } context.Response.Write(new EMT.Tools.Serialize().SerializeJson(new { oneTimeRevenue = oneTimeRevenue, oneTimeCost = oneTimeCost, monthRevenue = monthRevenue, monthCost = monthCost, quarterRevenue = quarterRevenue, quarterCost = quarterCost, halfRevenue = halfRevenue, halfCost = halfCost, yearRevenue = yearRevenue, yearCost = yearCost, shipRevenue = shipRevenue, shipCost = shipCost, discount = discount })); } } // quoteItemList.Where(_ => _.type_id != (int)EMT.DoneNOW.DTO.DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES && _.optional != 1&&_.type_id != (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT).ToList(); }
protected void Page_Load(object sender, EventArgs e) { try { var id = Request.QueryString["id"]; if (AuthBLL.GetUserOppAuth(LoginUserId, LoginUser.security_Level_id, Convert.ToInt64(id)).CanView == false) { Response.End(); return; } opportunity = new crm_opportunity_dal().GetOpportunityByOtherId(Convert.ToInt64(id)); type = Request.QueryString["type"]; if (opportunity != null) { dic = new OpportunityBLL().GetField(); quoteList = new crm_quote_dal().GetQuoteByOpportunityId(opportunity.id); account = new CompanyBLL().GetCompany(opportunity.account_id); if (opportunity.contact_id != null) { contact = new ContactBLL().GetContact((long)opportunity.contact_id); } thisBookMark = new IndexBLL().GetSingBook(Request.Url.LocalPath + "?id=" + opportunity.id, LoginUserId); switch (type) // 根据传过来的不同的类型,为页面中的iframe控件选择不同的src { case "todo": iframeSrc = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.TODOS + "&type=" + (int)QueryType.Todos + "&group=112&con660=" + opportunity.id + "¶m1=opportunityId¶m2=" + opportunity.id; // 待办 actType = "待办"; break; case "note": iframeSrc = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.CRM_NOTE_SEARCH + "&type=" + (int)QueryType.CRMNote + "&group=110&con647=" + opportunity.id + "¶m1=opportunityId¶m2=" + opportunity.id; // 备注 actType = "备注"; break; case "activity": iframeSrc = ""; // 活动 actType = "活动"; break; case "ticket": iframeSrc = "../Common/SearchBodyFrame.aspx?cat=" + (int)EMT.DoneNOW.DTO.DicEnum.QUERY_CATE.MY_QUEUE_ACTIVE + "&type=" + (int)EMT.DoneNOW.DTO.QueryType.MY_QUEUE_ACTIVE + "&group=215&con5603=" + opportunity.id + "¶m1=ShowPara"; actType = "工单"; break; case "quoteItem": var oppoQuoteList = new crm_quote_dal().GetQuoteByWhere($" and opportunity_id = {opportunity.id} "); if (oppoQuoteList != null && oppoQuoteList.Count > 0) { iframeSrc = "../QuoteItem/QuoteItemManage?isShow=show&opportunity_id=" + opportunity.id; // 报价项 isAddQuote.Value = "0"; } else { isAddQuote.Value = "1"; //ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>if(confirm('商机尚未创建报价,需要现在创建吗?')){window.open('../Quote/QuoteAddAndUpdate.aspx?quote_opportunity_id=" + opportunity.id + "', '" + (int)EMT.DoneNOW.DTO.OpenWindow.QuoteAdd + "', 'left=200,top=200,width=960,height=750', false);}</script>"); //Response.Write("<script>debugger;</script>"); } actType = "报价项"; break; case "att": iframeSrc = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.OPPORTUNITY_VIEW_ATTACHMENT + "&type=" + (int)QueryType.OpportunityViewAttachment + "&con976=" + opportunity.id; actType = "附件"; break; default: iframeSrc = ""; // 默认 actType = "活动"; type = "activity"; break; } if (type == "activity" || type == "note" || type == "todo") { isHide.Value = "show"; } if (type.Equals("activity")) { var typeList = new ActivityBLL().GetCRMActionType(); noteType.DataSource = typeList; noteType.DataTextField = "name"; noteType.DataValueField = "id"; noteType.DataBind(); } } else { Response.End(); } } catch (Exception) { Response.End(); } }
protected long quote_id; // 报价ID protected void Page_Load(object sender, EventArgs e) { try { isSaleOrder = !string.IsNullOrEmpty(Request.QueryString["isSaleOrder"]); var sId = Request.QueryString["sale_order_id"]; if (!string.IsNullOrEmpty(sId)) { saleOrderId = long.Parse(sId); } type = Request.QueryString["type_id"]; // 报价项类型 var quote_id = Request.QueryString["quote_id"]; // 报价ID 需要根据报价ID 添加报价项 if (!string.IsNullOrEmpty(quote_id)) { this.quote_id = long.Parse(quote_id); } var quote_item_id = Request.QueryString["id"]; thisQuoteId.Value = quote_id; dic = new QuoteItemBLL().GetField(); if (!string.IsNullOrEmpty(quote_item_id)) { quote_item = new crm_quote_item_dal().GetQuoteItem(long.Parse(quote_item_id)); if (quote_item != null) { if (quote_item.quote_id != null) { this.quote_id = (long)quote_item.quote_id; } isAdd = false; if (!IsPostBack) { _optional.Checked = quote_item.optional == 1; } ItemTypeId.Value = quote_item.type_id.ToString(); switch (quote_item.type_id) // todo 不同类型的报价项 { case (int)QUOTE_ITEM_TYPE.WORKING_HOURS: type = "工时"; break; case (int)QUOTE_ITEM_TYPE.COST: type = "费用"; break; case (int)QUOTE_ITEM_TYPE.DEGRESSION: type = "成本"; break; case (int)QUOTE_ITEM_TYPE.DISCOUNT: type = "折扣"; break; case (int)QUOTE_ITEM_TYPE.PRODUCT: type = "产品"; break; case (int)QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES: type = "配送费用"; break; case (int)QUOTE_ITEM_TYPE.SERVICE: type = "服务"; break; case (int)QUOTE_ITEM_TYPE.START_COST: type = "初始费用"; break; default: break; } #region 记录浏览历史 var accountName = ""; if (quote_item.quote_id != null) { var quote = new crm_quote_dal().FindNoDeleteById((long)quote_item.quote_id); if (quote != null) { var account = new CompanyBLL().GetCompany(quote.account_id); accountName = account != null ? account.name : ""; } } var history = new sys_windows_history() { title = $"编辑报价项:" + quote_item.name + " " + accountName, url = Request.RawUrl, }; new IndexBLL().BrowseHistory(history, LoginUserId); #endregion } } else { ItemTypeId.Value = type; switch (Convert.ToInt64(type)) // todo 不同类型的报价项 { case (int)QUOTE_ITEM_TYPE.WORKING_HOURS: type = "工时"; break; case (int)QUOTE_ITEM_TYPE.COST: type = "费用"; break; case (int)QUOTE_ITEM_TYPE.DEGRESSION: type = "成本"; break; case (int)QUOTE_ITEM_TYPE.DISCOUNT: type = "折扣"; break; case (int)QUOTE_ITEM_TYPE.PRODUCT: type = "产品"; break; case (int)QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES: type = "配送费用"; break; case (int)QUOTE_ITEM_TYPE.SERVICE: type = "服务"; break; case (int)QUOTE_ITEM_TYPE.START_COST: type = "初始费用"; break; default: Response.End(); // 未传类型,暂不创建 break; } } //if (string.IsNullOrEmpty(quote_id)) //{ // //Response.End(); //} // var type_id = Convert.ToInt64(type); #region 拉框配置数据源 // 税收种类 tax_cate_id.DataTextField = "show"; tax_cate_id.DataValueField = "val"; tax_cate_id.DataSource = dic.FirstOrDefault(_ => _.Key == "quote_item_tax_cate").Value; tax_cate_id.DataBind(); tax_cate_id.Items.Insert(0, new ListItem() { Value = "0", Text = " ", Selected = true }); // 期间类型 period_type_id.DataTextField = "show"; period_type_id.DataValueField = "val"; period_type_id.DataSource = dic.FirstOrDefault(_ => _.Key == "quote_item_period_type").Value; period_type_id.DataBind(); period_type_id.Items.Insert(0, new ListItem() { Value = "0", Text = " ", Selected = true }); period_type_id.SelectedValue = ((int)QUOTE_ITEM_PERIOD_TYPE.ONE_TIME).ToString(); period_type_id.Enabled = true; #endregion if (!isAdd) { if (quote_item.tax_cate_id != null) { tax_cate_id.SelectedValue = quote_item.tax_cate_id.ToString(); } if (quote_item.period_type_id != null) { period_type_id.SelectedValue = quote_item.period_type_id.ToString(); } if (quote_item.type_id == (int)DTO.DicEnum.QUOTE_ITEM_TYPE.PRODUCT) { thisReserList = new ivt_reserve_dal().GetListByItemId(quote_item.id); } } } catch (Exception) { Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { try { thisBookMark = new IndexBLL().GetSingBook(Request.RawUrl, LoginUserId); // quote_group_by groupBy.DataTextField = "show"; groupBy.DataValueField = "val"; groupBy.DataSource = dic.FirstOrDefault(_ => _.Key == "quote_group_by").Value; groupBy.DataBind(); isShow = Request.QueryString["isShow"]; IssaleOrder = !string.IsNullOrEmpty(Request.QueryString["isSaleOrder"]); var sid = Request.QueryString["sale_order_id"]; if (!string.IsNullOrEmpty(sid)) { sale_order_id = long.Parse(sid); } var quote_id = Request.QueryString["quote_id"]; if (!string.IsNullOrEmpty(quote_id)) { quote = new QuoteBLL().GetQuote(Convert.ToInt64(quote_id)); if (quote.quote_tmpl_id != null) { var sys_quote_temp = new QuoteTemplateBLL().GetQuoteTemplate((long)quote.quote_tmpl_id); if (sys_quote_temp != null) { // 获取到该报价的报价模板用于设置税的显示方式和汇总名称 show_each_tax_in_tax_group.Value = sys_quote_temp.show_each_tax_in_tax_group.ToString(); show_each_tax_in_tax_period.Value = sys_quote_temp.show_each_tax_in_tax_period.ToString(); // 选中第一个:按照周期分组时起作用,每个周期后显示税 最后的汇总也有税) // var a3 =sys_quote_temp.show_labels_when_grouped; // 预留字段 show_tax_cate.Value = sys_quote_temp.show_tax_cate.ToString(); show_tax_cate_superscript.Value = sys_quote_temp.show_tax_cate_superscript.ToString(); } } } var opportunity_id = Request.QueryString["opportunity_id"]; // 这里是通过商机查看报价项的情况 if (!string.IsNullOrEmpty(opportunity_id)) { var oppoQuoteList = new crm_quote_dal().GetQuoteByWhere($" and opportunity_id = {opportunity_id} "); if (oppoQuoteList != null && oppoQuoteList.Count > 0) { quote = oppoQuoteList.FirstOrDefault(_ => _.is_primary_quote == 1); // 如果该商机下有报价则一定会有主报价 } } if (quote != null) { quoteItemList = new crm_quote_item_dal().GetQuoteItems($" and quote_id={quote.id} "); // quoteItemList.Sort(SortCycle); // 自定义排序测试 quoteItemList = quoteItemList.OrderBy(_ => SortQuoteItem(_.period_type_id)).ToList(); quoteList = new crm_quote_dal().GetQuoteByWhere($" and opportunity_id = {quote.opportunity_id} "); var primaryQuote = quoteList.FirstOrDefault(_ => _.is_primary_quote == 1); if (primaryQuote != null) { var thisQuoteItemList = new crm_quote_item_dal().GetQuoteItems($" and quote_id={primaryQuote.id} "); var thisDiscountQIList = thisQuoteItemList.Where(_ => _.type_id == (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && _.optional == 0).ToList(); var thisOneTimeQTList = thisQuoteItemList.Where(_ => _.period_type_id == (int)DTO.DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME && _.optional == 0).ToList(); var thisOptionalItemList = thisQuoteItemList.Where(_ => _.optional == 1).ToList(); var totalPrice = ((decimal)((thisQuoteItemList.Sum(_ => (_.unit_discount != null && _.unit_price != null && _.quantity != null) ? (_.unit_price - _.unit_discount) * _.quantity : 0) - thisDiscountQIList.Where(_ => _.discount_percent != null).ToList().Sum(_ => (_.unit_discount != null && _.quantity != null) ? _.unit_discount * _.quantity : 0) - (thisOneTimeQTList != null && thisOneTimeQTList.Count > 0 ? thisDiscountQIList.Where(_ => _.discount_percent != null).ToList().Sum(_ => thisOneTimeQTList.Sum(one => (one.unit_discount != null && one.unit_price != null && one.quantity != null) ? (one.unit_price - one.unit_discount) * one.quantity : 0) * _.discount_percent) : 0)))).ToString("#0.00"); quoteList.Remove(primaryQuote); primaryQuote.name = "PRIMARY:" + primaryQuote.name + "(" + totalPrice + ")"; quoteList.Add(primaryQuote); } #region // 为报价下拉框赋值 quoteDropList.DataValueField = "id"; quoteDropList.DataTextField = "name"; quoteDropList.DataSource = quoteList; quoteDropList.DataBind(); quoteDropList.SelectedValue = quote.id.ToString(); #endregion if (quoteItemList != null && quoteItemList.Count > 0) { // 用户需要添加折扣类型的报价项,然后可以针对付费周期类型为一次性的报价项进行折扣 // 折扣只针对一次性周期的报价项折扣 oneTimeList = quoteItemList.Where(_ => _.period_type_id == (int)DTO.DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME && _.optional == 0 && _.type_id != (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && _.type_id != (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES).ToList(); discountQIList = quoteItemList.Where(_ => _.type_id == (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && _.optional == 0).ToList(); // 获取到可选的报价项, optionalItemList = quoteItemList.Where(_ => _.optional == 1).ToList(); // 获取到可选的报价项 // optionalItemList.Sort(); // &&optionalItemList.Any(op=>op.id!=_.id)&&oneTimeList.Any(one=>one.id!=_.id) 满足多个报价项过滤条件的,选择其中的一个 distributionList = quoteItemList.Where(_ => _.type_id == (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES && _.optional == 0).ToList(); // 配送类型的报价项 // 配送,一次性,可选的配置项独立显示,所以在这里分离出来,传到前台后单独处理 // 获取到筛选后报价项列表方便分组管理 筛选后的列表不包括可选,一次性的折扣和配送 var screenList = quoteItemList.Where(_ => _.type_id != (int)EMT.DoneNOW.DTO.DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES && _.optional != 1 && _.type_id != (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT).ToList(); if (!string.IsNullOrEmpty(Request.QueryString["group_by"])) { groupByType = Request.QueryString["group_by"]; } else { if (quote.group_by_id != null) { groupByType = ((long)quote.group_by_id).ToString(); } } // groupByType = ?((long)quote.group_by_id).ToString():Request.QueryString["group_by"]; if (groupByType == ((int)EMT.DoneNOW.DTO.DicEnum.QUOTE_GROUP_BY.CYCLE).ToString()) // 按周期分组 { groupList = screenList.GroupBy(_ => _.period_type_id == null ? "" : _.period_type_id.ToString()).ToDictionary(_ => (object)_.Key, _ => _.ToList()); // as Dictionary<long?, new QuoteBLL().UpdateGroup(quote.id, (int)QUOTE_GROUP_BY.CYCLE, GetLoginUserId()); groupBy.SelectedValue = ((int)QUOTE_GROUP_BY.CYCLE).ToString(); } else if (groupByType == ((int)QUOTE_GROUP_BY.PRODUCT).ToString()) // 按产品分组 { groupList = screenList.GroupBy(_ => _.object_id == null ? "" : ReturnProductID((long)_.object_id)).ToDictionary(_ => (object)_.Key, _ => _.ToList()); new QuoteBLL().UpdateGroup(quote.id, (int)QUOTE_GROUP_BY.PRODUCT, GetLoginUserId()); groupBy.SelectedValue = ((int)QUOTE_GROUP_BY.PRODUCT).ToString(); } else if (groupByType == ((int)QUOTE_GROUP_BY.CYCLE_PRODUCT).ToString()) // 按周期产品分组 { new QuoteBLL().UpdateGroup(quote.id, (int)QUOTE_GROUP_BY.CYCLE_PRODUCT, GetLoginUserId()); groupBy.SelectedValue = ((int)QUOTE_GROUP_BY.CYCLE_PRODUCT).ToString(); doubleGroupList = screenList.GroupBy(d => d.period_type_id == null ? "" : d.period_type_id.ToString()).ToDictionary(_ => (object)_.Key, _ => _.ToList().GroupBy(d => d.object_id == null ? "" : ReturnProductID((long)d.object_id)).ToDictionary(d => (object)d.Key, d => d.ToList())); } else if (groupByType == ((int)QUOTE_GROUP_BY.PRODUCT_CYCLE).ToString()) // 按产品周期分组 { new QuoteBLL().UpdateGroup(quote.id, (int)QUOTE_GROUP_BY.PRODUCT_CYCLE, GetLoginUserId()); groupBy.SelectedValue = ((int)QUOTE_GROUP_BY.PRODUCT_CYCLE).ToString(); doubleGroupList = screenList.GroupBy(_ => _.object_id == null ? "" : ReturnProductID((long)_.object_id)).ToDictionary(_ => (object)_.Key, _ => _.ToList().GroupBy(d => d.period_type_id == null ? "" : d.period_type_id.ToString()).ToDictionary(d => (object)d.Key, d => d.ToList())); } else // 不分组 { new QuoteBLL().UpdateGroup(quote.id, (int)QUOTE_GROUP_BY.NO, GetLoginUserId()); groupBy.SelectedValue = ((int)QUOTE_GROUP_BY.NO).ToString(); } //switch (groupByType) //{ // case "cycle": // // 按照周期分组 // break; // case "product": // break; // default: // groupByType = "no"; // break; //} // ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script> $(\"#groupBy\").val('"+groupBy+"')</script>"); if (discountQIList != null && discountQIList.Count > 0) { discountQIList.ForEach(_ => { if (_.discount_percent != null) { _.discount_percent = _.discount_percent / 100; } }); } } } else { Response.End(); } } catch (Exception) { throw; } }
/// <summary> /// 插入报价 /// </summary> /// <param name="quote"></param> /// <param name="user_id"></param> /// <returns></returns> public ERROR_CODE Insert(crm_quote quote, long user_id) { if (quote.account_id == 0 || string.IsNullOrEmpty(quote.name) || (quote.contact_id == 0 && quote.opportunity_id == 0)) { return(ERROR_CODE.PARAMS_ERROR); } var user = UserInfoBLL.GetUserInfo(user_id); if (user == null) { return(ERROR_CODE.USER_NOT_FIND); } #region 3.保存商机 if (quote.opportunity_id == 0) // 代表用户未选择商机,此时自动创建商机 { var opportunity = new crm_opportunity() { id = _dal.GetNextIdCom(), name = quote.name, account_id = quote.account_id, resource_id = user_id, stage_id = (int)OPPORTUNITY_STAGE.NEW_CLUE, // todo 取到商机阶段中的最小值 status_id = (int)OPPORTUNITY_STATUS.ACTIVE, create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), projected_close_date = quote.projected_close_date, use_quote = 1, one_time_cost = 0, one_time_revenue = 0, monthly_cost = 0, monthly_revenue = 0, quarterly_cost = 0, quarterly_revenue = 0, semi_annual_cost = 0, semi_annual_revenue = 0, yearly_cost = 0, yearly_revenue = 0, ext1 = 0, ext2 = 0, ext3 = 0, ext4 = 0, ext5 = 0, spread_value = 0, // 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, }; new crm_opportunity_dal().Insert(opportunity); 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.OPPORTUNITY, oper_object_id = opportunity.id,// 操作对象id oper_type_id = (int)OPER_LOG_TYPE.ADD, oper_description = _dal.AddValue(opportunity), remark = "保存商机信息" }); quote.opportunity_id = opportunity.id; } quote.is_primary_quote = 1; #endregion // 验证该商机下是否有报价,如果是第一个添加的报价,则设置成为主报价 var quoteList = new crm_quote_dal().GetQuoteByWhere($" and opportunity_id = {quote.opportunity_id} "); if (quoteList != null && quoteList.Count > 0) { quote.is_primary_quote = null; } #region 1.保存报价 quote.id = _dal.GetNextIdCom(); quote.create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); quote.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); quote.create_user_id = user_id; quote.update_user_id = user_id; quote.payment_term_id = quote.payment_term_id == 0 ? null : quote.payment_term_id; quote.payment_type_id = quote.payment_type_id == 0 ? null : quote.payment_type_id; quote.shipping_type_id = quote.shipping_type_id == 0 ? null : quote.shipping_type_id; quote.tax_region_id = quote.tax_region_id == 0 ? null : quote.tax_region_id; quote.quote_tmpl_id = quote.quote_tmpl_id == 0 ? null : quote.quote_tmpl_id; quote.project_id = quote.project_id == 0 ? null : quote.project_id; _dal.Insert(quote); new sys_oper_log_dal().Insert(new sys_oper_log() { user_cate = "用户", user_id = 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.ADD, oper_description = _dal.AddValue(quote), remark = "保存报价信息" }); #endregion #region 2.保存通知 #endregion #region 更新客户最后活动时间 crm_account thisAccount = new CompanyBLL().GetCompany(quote.account_id); if (thisAccount != null) { thisAccount.last_activity_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); new CompanyBLL().EditAccount(thisAccount, user_id); } #endregion return(ERROR_CODE.SUCCESS); }