Esempio n. 1
0
 /// <summary>
 /// 判断报价是否包含初始费 并且 合同中是否也有初始费用
 /// </summary>
 /// <param name="context"></param>
 /// <param name="quote_id"></param>
 /// <param name="contract_id"></param>
 public void CompareSetupFee(HttpContext context, long quote_id, long contract_id)
 {
     var quote = new QuoteBLL().GetQuote(quote_id);
     var contract = new ctt_contract_dal().GetSingleContract(contract_id);
     bool isHasSetupFee = false;
     if (quote != null && contract != null)
     {
         var quoteItemList = new crm_quote_item_dal().GetQuoteItems($" and quote_id = {quote.id}");
         if (quoteItemList != null && quoteItemList.Count > 0)
         {
             var setupFeeItem = quoteItemList.Where(_ => _.type_id == (int)QUOTE_ITEM_TYPE.START_COST).ToList();
             if (setupFeeItem != null && setupFeeItem.Count > 0 && contract.setup_fee != null)
             {
                 isHasSetupFee = true;
             }
         }
     }
     context.Response.Write(isHasSetupFee);
 }
Esempio n. 2
0
        /// <summary>
        /// 报价是否可以进行关闭报价操作
        /// </summary>
        public bool CanCloseQuote(long quote_id, out string reason)
        {
            reason = "";
            bool result = true;

            try
            {
                var thisQuote = _dal.FindNoDeleteById(quote_id);
                if (thisQuote != null)
                {
                    if (thisQuote.is_primary_quote != 1)
                    {
                        reason = "该报价不是主报价";
                        return(false);
                    }
                    var thisQuoItemList = new crm_quote_item_dal().GetQuoteItems($"and quote_id = {quote_id}");
                    if (thisQuoItemList != null && thisQuoItemList.Count > 0)
                    {
                        var serItemList = thisQuoItemList.Where(_ => _.type_id == (int)EMT.DoneNOW.DTO.DicEnum.QUOTE_ITEM_TYPE.SERVICE || _.type_id == (int)EMT.DoneNOW.DTO.DicEnum.QUOTE_ITEM_TYPE.START_COST).ToList();
                        if (serItemList != null && serItemList.Count > 0)
                        {
                            reason = "报价中包含服务/包、初始费用等";
                            return(false);
                        }
                    }
                    else
                    {
                        result = true;
                    }
                }
                else
                {
                    reason = "没有找到该报价";
                }
            }
            catch (Exception msg)
            {
                return(false);
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 判断报价和合同是否有重复的服务
        /// </summary>
        /// <param name="context"></param>
        /// <param name="quote_id"></param>
        /// <param name="contract_id"></param>
        public void CompareService(HttpContext context, long quote_id, long contract_id)
        {
            
            var quote = new QuoteBLL().GetQuote(quote_id);
            var conSerList = new ctt_contract_service_dal().GetConSerList(contract_id);
            bool isHasService = false;
            if (quote != null && conSerList != null && conSerList.Count>0)
            {
                var quoteItemList = new crm_quote_item_dal().GetQuoteItems($" and quote_id = {quote.id}");
                if (quoteItemList != null && quoteItemList.Count > 0)
                {
                    var serviceItem = quoteItemList.Where(_ => _.type_id == (int)QUOTE_ITEM_TYPE.SERVICE).ToList();
                    if(conSerList.Any(_=> serviceItem.Any(item => item.object_id == _.object_id)))
                    {
                        isHasService = true;
                    }
                }
            }

            context.Response.Write(isHasService);
        }
Esempio n. 4
0
        /// <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();
        }
Esempio n. 5
0
        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;
            }
        }