예제 #1
0
        /// <summary>
        /// 根据商机获取相应项目的值
        /// </summary>
        public void GetPorUdfByOpp(HttpContext context, long oppo_id)
        {
            var thisOpp = new crm_opportunity_dal().FindNoDeleteById(oppo_id);

            if (thisOpp != null)
            {
                var projectUdfList = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.PROJECTS);

                var oppoUdfList   = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.OPPORTUNITY);
                var oppoValueList = new UserDefinedFieldsBLL().GetUdfValue(DicEnum.UDF_CATE.OPPORTUNITY, thisOpp.id, oppoUdfList);

                if (projectUdfList != null && projectUdfList.Count > 0)
                {
                    StringBuilder udfHtml = new StringBuilder();
                    var           sufDal  = new sys_udf_field_dal();
                    foreach (var thisProUdf in projectUdfList)
                    {
                        var thisSysProFile = sufDal.FindNoDeleteById(thisProUdf.id);
                        if (thisSysProFile != null && thisSysProFile.crm_to_project_udf_id != null)
                        {
                            var thisSysOppFile = sufDal.FindNoDeleteById((long)thisSysProFile.crm_to_project_udf_id);
                            var oppoValue      = oppoValueList.FirstOrDefault(_ => _.id == thisSysProFile.crm_to_project_udf_id);
                            if (oppoValue != null && thisSysOppFile != null && !string.IsNullOrEmpty(oppoValue.value.ToString()))
                            {
                                udfHtml.Append($"<tr height='21'><td id ='txtBlack8'>{thisSysProFile.col_comment}</td><td> {thisSysOppFile.col_comment} </td><td>{oppoValue.value.ToString()}<input type='hidden' name='{thisProUdf.id.ToString()}' id='{thisProUdf.id.ToString()}' value='{oppoValue.value.ToString()}' /></ td></ tr>");
                            }
                        }
                    }

                    context.Response.Write(udfHtml.ToString());
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 得到该用户下的所有商机
        /// </summary>
        /// <param name="context"></param>
        /// <param name="account_id"></param>
        private void GetOpportunity(HttpContext context, string account_id)
        {
            try
            {
                StringBuilder opportunitys = new StringBuilder();


                var NoQuoteOpportinotyList = new crm_opportunity_dal().GetNoQuoteOppo(Convert.ToInt64(account_id));
                if (NoQuoteOpportinotyList != null && NoQuoteOpportinotyList.Count > 0)
                {
                    opportunitys.Append("<option value='0'>---无报价商机---</option>");
                    foreach (var opportunity in NoQuoteOpportinotyList)
                    {
                        opportunitys.Append("<option value='" + opportunity.id + "'>" + opportunity.name + "</option>");
                    }
                }

                var HasQuoteOpportinotyList = new crm_opportunity_dal().GetHasQuoteOppo(Convert.ToInt64(account_id));
                if (HasQuoteOpportinotyList != null && HasQuoteOpportinotyList.Count > 0)
                {
                    opportunitys.Append("<option value='0'>---有报价商机---</option>");
                    foreach (var opportunity in HasQuoteOpportinotyList)
                    {
                        opportunitys.Append("<option value='" + opportunity.id + "'>" + opportunity.name + "</option>");
                    }
                }

                context.Response.Write(opportunitys);
            }
            catch (Exception)
            {
                context.Response.End();
            }
        }
예제 #3
0
        /// <summary>
        /// 根据状态,对商机进行分类
        /// </summary>
        public void GetOppByStatus(HttpContext context, long account_id)
        {
            var oppList = new crm_opportunity_dal().FindOpHistoryByAccountId(account_id);

            if (oppList != null && oppList.Count > 0)
            {
                StringBuilder op = new StringBuilder();
                op.Append("<option value=''>   </option>");
                var activeOPList   = oppList.Where(_ => _.status_id == (int)DTO.DicEnum.OPPORTUNITY_STATUS.ACTIVE).ToList();
                var noActiveOPList = oppList.Where(_ => _.status_id != (int)DTO.DicEnum.OPPORTUNITY_STATUS.ACTIVE).ToList();
                if (activeOPList != null && activeOPList.Count > 0)
                {
                    foreach (var thisOp in activeOPList)
                    {
                        op.Append($"<option value='{thisOp.id}'>{thisOp.name}</option>");
                    }
                }
                if (noActiveOPList != null && noActiveOPList.Count > 0)
                {
                    op.Append("<option value=''>-------</option>");
                    foreach (var thisOp in noActiveOPList)
                    {
                        op.Append($"<option value='{thisOp.id}'>{thisOp.name}</option>");
                    }
                }
                context.Response.Write(op.ToString());
            }
        }
예제 #4
0
        public void GetAccOpp(HttpContext context, long account_id)
        {
            var oppList = new crm_opportunity_dal().FindOpHistoryByAccountId(account_id);

            if (oppList != null && oppList.Count > 0)
            {
                StringBuilder op = new StringBuilder();
                op.Append("<option value='0'>   </option>");
                oppList.ForEach(_ => op.Append($"<option value='{_.id}'>{_.name}</option>"));
                context.Response.Write(op.ToString());
            }
        }
예제 #5
0
 /// <summary>
 /// 得到客户下的所有商机
 /// </summary>
 /// <param name="context"></param>
 /// <param name="account_id"></param>
 private void GetOpportunityList(HttpContext context, string account_id)
 {
     try
     {
         StringBuilder opportunitys = new StringBuilder();
         opportunitys.Append("<option value=''></option>");
         var opportinotyList = new crm_opportunity_dal().FindByAccountId(Convert.ToInt64(account_id));
         if (opportinotyList != null)
         {
             foreach (var opportunity in opportinotyList)
             {
                 opportunitys.Append("<option value='" + opportunity.id + "'>" + opportunity.name + "</option>");
             }
         }
         context.Response.Write(opportunitys);
     }
     catch (Exception)
     {
         context.Response.Write("");
     }
 }
예제 #6
0
        protected List <crm_quote_item> degressionItem    = null; // 成本的配置项
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                #region  拉框赋值
                stage_id.DataTextField  = "show";
                stage_id.DataValueField = "val";
                stage_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "opportunity_stage").Value;
                stage_id.DataBind();

                win_reason_type_id.DataTextField  = "show";
                win_reason_type_id.DataValueField = "val";
                win_reason_type_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "oppportunity_win_reason_type").Value;
                win_reason_type_id.DataBind();
                win_reason_type_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

                resource_id.DataTextField  = "show";
                resource_id.DataValueField = "val";
                resource_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "sys_resource").Value;
                resource_id.DataBind();

                competitor_id.DataTextField  = "show";
                competitor_id.DataValueField = "val";
                competitor_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "competition").Value;
                competitor_id.DataBind();
                competitor_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

                // period_type
                period_type.DataTextField  = "show";
                period_type.DataValueField = "val";
                period_type.DataSource     = dic.FirstOrDefault(_ => _.Key == "period_type").Value;
                period_type.DataBind();
                period_type.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

                // notifi_temp 通知模板
                var tempList = new sys_notify_tmpl_dal().GetTempByEvent(DicEnum.NOTIFY_EVENT.OPPORTUNITY_CLOSED);
                notifi_temp.DataTextField  = "name";
                notifi_temp.DataValueField = "id";
                notifi_temp.DataSource     = tempList;
                notifi_temp.DataBind();
                #endregion
                var id         = Request.QueryString["id"];
                var account_id = Request.QueryString["account_id"];
                if (!string.IsNullOrEmpty(id))
                {
                    if (string.IsNullOrEmpty(account_id))
                    {
                        if (!IsPostBack)
                        {
                            opportunity_id.Enabled = false;
                        }
                    }
                    opportunity = new crm_opportunity_dal().GetOpportunityById(long.Parse(id));
                    if (opportunity != null)
                    {
                        account    = new CompanyBLL().GetCompany(opportunity.account_id);
                        account_id = account.id.ToString();
                    }
                }
                if (!string.IsNullOrEmpty(account_id))
                {
                    account = new CompanyBLL().GetCompany(long.Parse(account_id));
                    var oppoList = new crm_opportunity_dal().FindOpHistoryByAccountId(long.Parse(account_id));
                    if (oppoList != null && oppoList.Count > 0)
                    {
                        opportunity_id.DataTextField  = "name";
                        opportunity_id.DataValueField = "id";
                        opportunity_id.DataSource     = oppoList;
                        opportunity_id.DataBind();
                    }
                    else
                    {
                        Response.Write("<script>alert('该客户还没有商机!');window.close();</script>");
                    }

                    //opportunity_id.Items.Insert(0, new ListItem() { Value = "0", Text = "   ", Selected = true });
                    if (string.IsNullOrEmpty(id))
                    {
                        opportunity = oppoList[0];
                    }
                    opportunity_id.SelectedValue = opportunity.id.ToString();
                }

                if (!IsPostBack)
                {
                    if (opportunity != null)
                    {
                        if (opportunity.status_id == (int)OPPORTUNITY_STATUS.CLOSED)
                        {
                            Response.Write("<script>if(!confirm('商机已被关闭,如果继续,系统会重复创建计费项和合同?')){window.close();}</script>");
                        }
                    }
                    if (opportunity.stage_id != null)
                    {
                        stage_id.SelectedValue = opportunity.stage_id.ToString();
                    }
                    else
                    {
                        var stageList    = new d_general_dal().GetGeneralByTableId((int)GeneralTableEnum.OPPORTUNITY_STATUS);
                        var defaultStage = stageList.FirstOrDefault(_ => _.ext1 == "1");
                        if (defaultStage != null)
                        {
                            stage_id.SelectedValue = defaultStage.id.ToString();
                        }
                    }
                    // stage_id.SelectedValue = opportunity.stage_id == null ? "0" : opportunity.stage_id.ToString();
                    resource_id.SelectedValue        = opportunity.resource_id.ToString();
                    competitor_id.SelectedValue      = opportunity.competitor_id == null ? "0" : opportunity.competitor_id.ToString();
                    win_reason_type_id.SelectedValue = opportunity.win_reason_type_id == null ? "0" : opportunity.win_reason_type_id.ToString();
                }
                // 折扣的下拉框不同于别的下拉框-- 需要去两个数据源去赋值
                StringBuilder text     = new StringBuilder();
                var           costCode = new d_cost_code_dal().GetListCostCode((int)COST_CODE_CATE.MATERIAL_COST_CODE);
                text.Append($"<option value='0'>   </option>");
                if (costCode != null && costCode.Count > 0)
                {
                    foreach (var item in costCode)
                    {
                        text.Append($"<option value='{item.id}'>{item.name}</option>");
                    }
                }
                codeSelect.Value = text.ToString();
                var disSource   = "";
                var disCostCode = costCode.Where(_ => _.id == (int)CostCode.NOTAXDISCOUNT || _.id == (int)CostCode.DISCOUNT).ToList();
                if (disCostCode != null && disCostCode.Count > 0)
                {
                    foreach (var item in disCostCode)
                    {
                        disSource += $"<option value='{item.id}'>{item.name}</option>";
                    }
                }
                disCodeSelct.Value        = disSource;
                period_type.SelectedValue = ((int)QUOTE_ITEM_PERIOD_TYPE.MONTH).ToString();
                primaryQuote = new QuoteBLL().GetPrimaryQuote(opportunity.id);


                if (primaryQuote != null)
                {
                    if (!IsPostBack)
                    {
                        if (primaryQuote.project_id != null) // 判断该报价是否关联项目提案,如果关联,默认选中,不关联,灰掉,不可选
                        {
                            activeproject.Checked = true;
                            activeproject.Enabled = true;
                            addRequest.Enabled    = false;
                            isaddRequest.Value    = "1";
                        }
                        else
                        {
                            activeproject.Checked = false;
                            addRequest.Enabled    = true;

                            activeproject.Enabled = false;
                            isactiveproject.Value = "1";
                        }
                    }
                    quoteItemList = new crm_quote_item_dal().GetQuoteItems($" and quote_id = {primaryQuote.id}");
                    if (quoteItemList != null && quoteItemList.Count > 0)
                    {
                        // 如果报价项中包含了服务 / 服务包、初始费用,则可以选中(默认不选)
                        // 此功能需要具有合同模块权限以及修改合同服务/包权限

                        var isServiceChargeItem = quoteItemList.Where(_ => _.type_id == (int)QUOTE_ITEM_TYPE.SERVICE || _.type_id == (int)QUOTE_ITEM_TYPE.SERVICE_PACK || _.type_id == (int)QUOTE_ITEM_TYPE.START_COST).ToList();
                        if (!IsPostBack)
                        {
                            if (isServiceChargeItem != null && isServiceChargeItem.Count > 0)
                            {
                                // todo--需要判断用户权限
                            }
                            else
                            {
                                addContractRequest.Enabled  = false;
                                isAddContractRequest.Value  = "1";
                                addContractServices.Enabled = false;
                                isaddContractServices.Value = "1";
                            }
                        }
                        proAndOneTimeItem = quoteItemList.Where(_ => _.optional != 1).Where(_ => _.type_id == (int)QUOTE_ITEM_TYPE.PRODUCT || _.type_id == (int)QUOTE_ITEM_TYPE.DISCOUNT).ToList();
                        if (!IsPostBack)
                        {
                            if (proAndOneTimeItem != null && proAndOneTimeItem.Count > 0)
                            {
                                isIncludePO.Checked = true;
                            }
                            else
                            {
                                IncludePO.Value     = "1";
                                isIncludePO.Enabled = false;
                            }
                        }
                        shipItem = quoteItemList.Where(_ => _.type_id == (int)QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES && _.optional != 1).ToList();
                        if (!IsPostBack)
                        {
                            if (shipItem != null && shipItem.Count > 0)
                            {
                                isIncludeShip.Checked = true;
                            }
                            else
                            {
                                IncludeShip.Value     = "1";
                                isIncludeShip.Enabled = false;
                            }
                        }
                        degressionItem = quoteItemList.Where(_ => _.type_id == (int)QUOTE_ITEM_TYPE.DEGRESSION & _.optional != 1).ToList();
                        if (!IsPostBack)
                        {
                            if (degressionItem != null && degressionItem.Count > 0)
                            {
                                isIncludeCharges.Checked = true;
                            }
                            else
                            {
                                IncludeCharges.Value     = "1";
                                isIncludeCharges.Enabled = false;
                            }
                        }
                        jqueryCode.Value = ReturnJquery();
                    }
                    else
                    {
                        // activeproject.Enabled = false;
                        //isactiveproject.Value = "1";
                        addContractRequest.Enabled  = false;
                        isAddContractRequest.Value  = "1";
                        addContractServices.Enabled = false;
                        isaddContractServices.Value = "1";
                        IncludePO.Value             = "1";
                        isIncludePO.Enabled         = false;
                        IncludeShip.Value           = "1";
                        isIncludeShip.Enabled       = false;
                        IncludeCharges.Value        = "1";
                        isIncludeCharges.Enabled    = false;
                    }
                }
                else
                {
                    activeproject.Enabled       = false;
                    isactiveproject.Value       = "1";
                    addContractRequest.Enabled  = false;
                    isAddContractRequest.Value  = "1";
                    addContractServices.Enabled = false;
                    isaddContractServices.Value = "1";
                    IncludePO.Value             = "1";
                    isIncludePO.Enabled         = false;
                    IncludeShip.Value           = "1";
                    isIncludeShip.Enabled       = false;
                    IncludeCharges.Value        = "1";
                    isIncludeCharges.Enabled    = false;
                }
            }
            catch (Exception msg)
            {
                Response.End();
            }
        }
예제 #7
0
        /// <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);
        }
예제 #8
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();
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
0
파일: ProductBLL.cs 프로젝트: evelh/Done
        /// <summary>
        /// 产品删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ERROR_CODE DeleteProduct(long id, long user_id, out string returnvalue)
        {
            returnvalue = string.Empty;
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {   // 查询不到用户,用户丢失
                return(ERROR_CODE.USER_NOT_FIND);
            }
            StringBuilder result = new StringBuilder();

            result.Append("产品不能被删除,因为它被以下对象引用\n");
            var opportunitylist       = new crm_opportunity_dal().FindListBySql($"select * from crm_opportunity where primary_product_id={id} and delete_time=0");
            var installed_productlist = new crm_installed_product_dal().FindListBySql($"select * from crm_installed_product where product_id={id} and delete_time=0");
            var warehouse_productlist = new ivt_warehouse_product_dal().FindListBySql($"select * from ivt_warehouse_product where product_id={id} and delete_time=0");
            var contract_costlist     = new ctt_contract_cost_dal().FindListBySql($"select * from ctt_contract_cost where product_id={id} and delete_time=0");
            int n = 1;

            if (opportunitylist.Count > 0)
            {
                result.Append($"{opportunitylist.Count} 商机\n");
                //foreach (var op in opportunitylist) {

                //    result.Append("N"+(n++)+"   "+op.id + "\n");
                //}
            }
            if (installed_productlist.Count > 0)
            {
                result.Append($"{installed_productlist.Count} 配置项\n");
                //foreach (var op in installed_productlist)
                //{
                //    result.Append("N" + (n++) + "  " + op.id + "\n");
                //}
            }
            if (warehouse_productlist.Count > 0)
            {
                result.Append($"{warehouse_productlist.Count} 库存\n");
                //foreach (var op in warehouse_productlist)
                //{
                //    result.Append("N" + (n++) + "  " + op.id + "\n");
                //}
            }
            if (contract_costlist.Count > 0)
            {
                result.Append($"{contract_costlist.Count} 工单\n");
                //foreach (var op in contract_costlist)
                //{
                //    result.Append("N" + (n++) + "  " + op.id + "\n");
                //}
            }
            if (contract_costlist.Count > 0 || warehouse_productlist.Count > 0 || installed_productlist.Count > 0 || opportunitylist.Count > 0)
            {
                returnvalue = result.ToString();
                return(ERROR_CODE.EXIST);
            }
            var product_del = _dal.FindSignleBySql <ivt_product>($"select * from ivt_product where id={id} and delete_time=0");

            if (product_del == null)
            {
                return(ERROR_CODE.ERROR);
            }
            product_del.delete_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            product_del.delete_user_id = user.id;
            if (!_dal.Update(product_del))
            {
                return(ERROR_CODE.ERROR);
            }
            //操作日志
            var add_log = 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.PRODUCT, //
                oper_object_id      = product_del.id,                 // 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.DELETE,
                oper_description    = _dal.AddValue(product_del),
                remark              = "删除产品信息"
            };                                      // 创建日志

            new sys_oper_log_dal().Insert(add_log); // 插入日志


            var del = _dal.FindSignleBySql <ivt_product>($"select * from ivt_product where id={id} and delete_time=0");

            return(ERROR_CODE.SUCCESS);
        }
예제 #12
0
        /// <summary>
        /// 新增附件
        /// </summary>
        /// <param name="objType">对象类型</param>
        /// <param name="objId">对象id</param>
        /// <param name="typeId">附件类型</param>
        /// <param name="title">附件名</param>
        /// <param name="attLink">附件内容</param>
        /// <param name="fileName">上传的文件名</param>
        /// <param name="fileSaveName">文件保存服务器的名称</param>
        /// <param name="contentType">文件类型</param>
        /// <param name="size">文件大小</param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool AddAttachment(int objType, long objId, int typeId, string title, string attLink, string fileName, string fileSaveName, string contentType, int size, long userId, string pubTypeId = "")
        {
            com_attachment att = new com_attachment();


            att.object_type_id = objType;
            att.object_id      = objId;

            // 备注和附件的下级备注和附件不能再添加附件
            if (objType == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES)
            {
                var note = new com_activity_dal().FindById(objId);
                if (note.object_type_id == (int)DicEnum.OBJECT_TYPE.NOTES)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES;
                    att.object_id      = note.object_id;
                }
                else if (note.object_type_id == (int)DicEnum.OBJECT_TYPE.ATTACHMENT)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT;
                    att.object_id      = note.object_id;
                }
            }
            else if (objType == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT)
            {
                var attachment = dal.FindById(objId);
                if (attachment.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES;
                    att.object_id      = attachment.object_id;
                }
                else if (attachment.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT;
                    att.object_id      = attachment.object_id;
                }
            }
            else if (objType == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.LABOUR)
            {
                var labour = new sdk_work_entry_dal().FindById(objId);
                if (labour.parent_id != null)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.LABOUR;
                    att.object_id      = (long)labour.parent_id;
                }
                else if (labour.parent_attachment_id != null)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT;
                    att.object_id      = (long)labour.parent_attachment_id;
                }
                else if (labour.parent_note_id != null)
                {
                    att.object_type_id = (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES;
                    att.object_id      = (long)labour.parent_note_id;
                }
            }

            if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.ATTACHMENT)
            {
                var attachment = dal.FindById(att.object_id);
                att.account_id = attachment.account_id;
                att.parent_id  = attachment.id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.NOTES)
            {
                var note = new com_activity_dal().FindById(att.object_id);
                att.account_id = note.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.OPPORTUNITY)
            {
                var opp = new crm_opportunity_dal().FindById(att.object_id);
                att.account_id = opp.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.SALES_ORDER)
            {
                var so  = new crm_sales_order_dal().FindById(att.object_id);
                var opp = new crm_opportunity_dal().FindById(so.opportunity_id);
                att.account_id = opp.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.CONTRACT)
            {
                var contract = new ctt_contract_dal().FindById(att.object_id);
                att.account_id = contract.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.COMPANY)
            {
                att.account_id = att.object_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.PROJECT)
            {
                var project = new pro_project_dal().FindNoDeleteById(att.object_id);
                att.account_id = project.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.EXPENSE_REPORT)
            {
                // 从报表添加附件 - 默认使用声联(oid=0) 的客户
                var defaultAccount = new CompanyBLL().GetDefaultAccount();
                att.account_id = defaultAccount.id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.TASK)
            {
                var task = new sdk_task_dal().FindNoDeleteById(att.object_id);
                if (task != null)
                {
                    att.account_id = task.account_id;
                    #region 更新客户最后活动时间
                    crm_account thisAccount = new CompanyBLL().GetCompany(task.account_id);
                    if (thisAccount != null)
                    {
                        thisAccount.last_activity_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); new CompanyBLL().EditAccount(thisAccount, userId);
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(pubTypeId))
                {
                    att.publish_type_id = int.Parse(pubTypeId);
                }
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.LABOUR)
            {
                var labour = new sdk_work_entry_dal().FindNoDeleteById(att.object_id);
                if (labour == null)
                {
                    return(false);
                }
                var ticket = new sdk_task_dal().FindNoDeleteById(labour.task_id);
                if (ticket == null)
                {
                    return(false);
                }
                att.account_id = ticket.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.KNOWLEDGE)
            {
                var thisArt = new sdk_kb_article_dal().FindNoDeleteById(att.object_id);
                if (thisArt == null)
                {
                    return(false);
                }
                att.account_id = thisArt.account_id;
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.RESOURCE)
            {
            }
            else if (att.object_type_id == (int)DicEnum.ATTACHMENT_OBJECT_TYPE.CONFIGITEM)
            {
                crm_installed_product insPro = new crm_installed_product_dal().FindNoDeleteById(att.object_id);
                if (insPro == null)
                {
                    return(false);
                }
                att.account_id = insPro.account_id;
            }
            else
            {
                return(false);
            }

            att.id             = dal.GetNextIdCom();
            att.create_time    = Tools.Date.DateHelper.ToUniversalTimeStamp();
            att.create_user_id = userId;
            att.update_time    = att.create_time;
            att.update_user_id = userId;
            att.title          = title;
            att.type_id        = typeId;
            if (typeId == (int)DicEnum.ATTACHMENT_TYPE.FILE_LINK ||
                typeId == (int)DicEnum.ATTACHMENT_TYPE.FOLDER_LINK)
            {
                att.uncpath  = attLink;
                att.filename = @"file://" + attLink;
            }
            else if (typeId == (int)DicEnum.ATTACHMENT_TYPE.URL)
            {
                if (attLink.IndexOf(@"http://") == 0)
                {
                    attLink      = attLink.Remove(0, 7);
                    att.urlpath  = attLink;
                    att.filename = @"http://" + attLink;
                }
                else if (attLink.IndexOf(@"https://") == 0)
                {
                    attLink      = attLink.Remove(0, 8);
                    att.urlpath  = attLink;
                    att.filename = @"https://" + attLink;
                }
                else
                {
                    att.urlpath  = attLink;
                    att.filename = @"http://" + attLink;
                }
            }
            else if (typeId == (int)DicEnum.ATTACHMENT_TYPE.ATTACHMENT)
            {
                att.href         = fileSaveName;
                att.filename     = fileName;
                att.sizeinbyte   = size;
                att.content_type = contentType;
            }
            else
            {
                return(false);
            }

            dal.Insert(att);
            OperLogBLL.OperLogAdd <com_attachment>(att, att.id, userId, DicEnum.OPER_LOG_OBJ_CATE.ATTACHMENT, "新增附件");
            return(true);
        }
예제 #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var dic = new OpportunityBLL().GetField();
                #region  拉框赋值
                stage_id.DataTextField  = "show";
                stage_id.DataValueField = "val";
                stage_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "opportunity_stage").Value;
                stage_id.DataBind();


                resource_id.DataTextField  = "show";
                resource_id.DataValueField = "val";
                resource_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "sys_resource").Value;
                resource_id.DataBind();


                //opportunity_id.DataTextField = "name";
                //opportunity_id.DataValueField = "id";
                //opportunity_id.DataSource = new crm_opportunity_dal().FindOpHistoryByAccountId(opportunity.account_id);
                //opportunity_id.DataBind();

                loss_reason_type_id.DataTextField  = "show";
                loss_reason_type_id.DataValueField = "val";
                loss_reason_type_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "oppportunity_loss_reason_type").Value;
                loss_reason_type_id.DataBind();
                loss_reason_type_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                // competition  competitor_id
                competitor_id.DataTextField  = "show";
                competitor_id.DataValueField = "val";
                competitor_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "competition").Value;
                competitor_id.DataBind();
                competitor_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                #endregion

                var account_id = Request.QueryString["account_id"];

                var opportunityId = Request.QueryString["id"];
                if (!string.IsNullOrEmpty(opportunityId))
                {
                    if (string.IsNullOrEmpty(account_id))
                    {
                        if (!IsPostBack)
                        {
                            opportunity_id.Enabled = false;
                        }
                    }
                    opportunity = new crm_opportunity_dal().GetOpportunityById(long.Parse(opportunityId));
                    if (opportunity != null)
                    {
                        account    = new CompanyBLL().GetCompany(opportunity.account_id);
                        account_id = account.id.ToString();
                        ownRes     = new UserResourceBLL().GetResourceById(opportunity.resource_id);
                    }
                }
                if (!string.IsNullOrEmpty(account_id))
                {
                    account = new CompanyBLL().GetCompany(long.Parse(account_id));
                    var oppoList = new crm_opportunity_dal().FindOpHistoryByAccountId(long.Parse(account_id));
                    if (oppoList != null && oppoList.Count > 0)
                    {
                        opportunity_id.DataTextField  = "name";
                        opportunity_id.DataValueField = "id";
                        opportunity_id.DataSource     = oppoList;
                        opportunity_id.DataBind();
                    }
                    else
                    {
                        Response.Write("<script>alert('该客户还没有商机!');window.close();</script>");
                    }
                    if (string.IsNullOrEmpty(opportunityId))
                    {
                        opportunity = oppoList[0];
                    }
                    opportunity_id.SelectedValue = opportunity.id.ToString();
                }
                if (opportunity == null)
                {
                    Response.End();
                }
                // 商机已经关闭,丢失提示信息
                if (!IsPostBack)
                {
                    if (opportunity.status_id == (int)OPPORTUNITY_STATUS.CLOSED)
                    {
                        Response.Write("<script>alert('商机已关闭,继续则以前创建的已确认计费项和合同不会受影响!');</script>");
                        Response.Write("<script>if(!confirm('本操作将会改变商机状态,相关的销售订单将被取消,是否继续?')){window.close();}</script>");
                    }
                }


                stage_id.SelectedValue       = opportunity.stage_id == null ? "0" : opportunity.stage_id.ToString();
                resource_id.SelectedValue    = opportunity.resource_id.ToString();
                opportunity_id.SelectedValue = opportunity.id.ToString();
                competitor_id.SelectedValue  = opportunity.competitor_id == null ? "0" : opportunity.competitor_id.ToString();
            }
            catch (Exception)
            {
                Response.End();
            }
        }
예제 #14
0
파일: QuoteBLL.cs 프로젝트: evelh/Done
        public ERROR_CODE CloseQuote(long user_id, QuoteCloseDto param)
        {
            // 此向导将会把产品、一次性折扣、配送、成本转为计费项。可选项和费用不会被转换。如果有产品,会生成销售订单。
            // 报价中如果有服务 / 包或初始费用,将不会被转换为计费项,也不会创建定期服务合同
            // 如果商机状态已经是“关闭”或“已实施”,将会为此商机生成重复的计费项。


            // 报价项中如果有物料代码为空的,则需要设置。如果没有需要配置的,则此界面不显示

            // 计费项将会生成,是否需要创建发票

            // 打开新建的销售订单(链接)——如果创建了销售单才显示



            // 关闭报价是关闭商机的另一种方式,

            // -- 必填项校验-- 根据系统设置来判断 TODO
            var user = UserInfoBLL.GetUserInfo(user_id);

            // 1.更新商机信息

            #region 1.更新商机信息
            // 根据系统设置来选择商机的阶段-- todo
            param.opportunity.status_id = (int)DicEnum.OPPORTUNITY_STATUS.CLOSED;

            var stageList    = new d_general_dal().GetGeneralByTableId((int)GeneralTableEnum.OPPORTUNITY_STATUS);
            var defaultStage = stageList.FirstOrDefault(_ => _.ext1 == "1");
            if (defaultStage != null)
            {
                param.opportunity.stage_id = defaultStage.id;
            }
            var old_opportunity = new crm_opportunity_dal().GetOpportunityById(param.opportunity.id);
            new crm_opportunity_dal().Update(param.opportunity);
            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.OPPORTUNITY,
                oper_object_id      = param.opportunity.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                oper_description    = _dal.CompareValue(old_opportunity, param.opportunity),
                remark              = "修改商机信息"
            });

            #endregion

            // 2.更新客户信息
            #region 2.更新客户信息
            var account = new CompanyBLL().GetCompany(param.quote.account_id);
            if (account.type_id != (int)DicEnum.ACCOUNT_TYPE.CUSTOMER)
            {
                account.type_id = (int)DicEnum.ACCOUNT_TYPE.CUSTOMER;
                new crm_account_dal().Update(account);
                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.CUSTOMER,
                    oper_object_id      = param.quote.account_id,// 操作对象id
                    oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                    oper_description    = _dal.CompareValue(new CompanyBLL().GetCompany(param.quote.account_id), account),
                    remark              = "修改客户信息"
                });
            }

            #endregion

            long?contact_id = null;
            if (param.opportunity.contact_id != null)
            {
                crm_contact contact = new ContactBLL().GetContact((long)param.opportunity.contact_id);
                if (contact.is_active == 1)
                {
                    contact_id = contact.id;
                }
            }



            // 3.保存项目信息
            #region 3.如果项目关联了项目提案,修改项目提案信息
            if (param.quote.project_id != null)
            {
                var project = new pro_project_dal().GetProjectById((long)param.quote.project_id);
                if (project != null)
                {
                    if (project.type_id != (int)PROJECT_TYPE.ACCOUNT_PROJECT)
                    {
                        project.type_id        = (int)PROJECT_TYPE.ACCOUNT_PROJECT;
                        project.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                        project.update_user_id = user.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.PROJECT,
                            oper_object_id      = project.id,// 操作对象id
                            oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                            oper_description    = _dal.CompareValue(new pro_project_dal().GetProjectById((long)param.quote.project_id), project),
                            remark              = "修改项目提案类型"
                        });
                        new pro_project_dal().Update(project);
                    }
                    param.project_id = project.id;
                }
                string costIds = "";
                new OpportunityBLL().InsertContract(param.dic, param.opportunity, user, null, out costIds, param.project_id, null);

                if (!string.IsNullOrEmpty(costIds))
                {
                    var aapBLL = new ApproveAndPostBLL();
                    costIds = costIds.Substring(0, costIds.Length - 1);
                    var costList = costIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var costId in costList)
                    {
                        // 审批并提交
                        aapBLL.Post_Charges(int.Parse(costId), int.Parse(DateTime.Now.ToString("yyyyMMdd")), user);
                    }
                }
            }
            #endregion

            // 4.新增工单信息
            #region 4.如果报价未关联项目提案,有需要转换的计费项
            // todo 关联sdk_ticket

            #endregion


            // 5.转换为工单/项目成本
            #region 5.转换为工单/项目成本
            // todo 关联sdk_ticket_charge
            // 一次性折扣根据需要拆分为两行——收税的、不收税的,分别计算折扣额。计算时仍然按照全部周期为一次性的报价项,而不是排除了服务和工时等报价项。


            #endregion

            // 将报价项转换为计费项
            #region  将报价项转换为计费项并审批提交 todo-需要项目ID 或者工单ID才可以进行操作
            //string costIds ="";
            //new OpportunityBLL().InsertContract(param.dic,param.opportunity,user,null,out costIds, param.project_id,null);

            //if (!string.IsNullOrEmpty(costIds))
            //{
            //    var aapBLL = new ApproveAndPostBLL();
            //    costIds = costIds.Substring(0,costIds.Length-1);
            //    var costList = costIds.Split(new char[] { ','},StringSplitOptions.RemoveEmptyEntries);
            //    foreach (var costId in costList)
            //    {
            //        // 审批并提交
            //        aapBLL.Post_Charges(int.Parse(costId),int.Parse(DateTime.Now.ToString("yyyyMMdd")),user);
            //    }
            //}
            #endregion

            // 6.新增销售订单
            #region 6.当有产品/一次性折扣、成本、配送转为计费项时,销售订单就会自动生成。Crm_sales_order
            if (param.dic != null && param.dic.Count > 0)
            {
                var saleOrder = new crm_sales_order_dal().GetSingleSalesOrderByWhere($" and opportunity_id = {param.opportunity.id} ");
                if (saleOrder == null)
                {
                    saleOrder = new crm_sales_order()
                    {
                        id = _dal.GetNextIdCom(),

                        opportunity_id    = param.opportunity.id,
                        status_id         = (int)SALES_ORDER_STATUS.OPEN,
                        contact_id        = contact_id,
                        owner_resource_id = param.opportunity.resource_id,
                        begin_date        = DateTime.Now,
                        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),
                    };
                    new crm_sales_order_dal().Insert(saleOrder);
                    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.SALE_ORDER,
                        oper_object_id      = saleOrder.id,// 操作对象id
                        oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                        oper_description    = _dal.AddValue(saleOrder),
                        remark              = "关闭报价,新增销售订单"
                    });
                    param.saleOrderId = saleOrder.id;
                }
            }


            #endregion

            // 7.新增项目备注
            #region 7.转为项目计费项时,会生成备注
            if (param.quote.project_id != null)
            {
                com_activity addActivity = new com_activity()
                {
                    id             = _dal.GetNextIdCom(),
                    cate_id        = (int)ACTIVITY_CATE.PROJECT_NOTE,
                    action_type_id = (int)ACTIVITY_TYPE.PROJECT_NOTE,
                    parent_id      = null,
                    object_id      = (long)param.quote.project_id,
                    object_type_id = (int)OBJECT_TYPE.PROJECT,
                    // todo发布范围
                    account_id     = param.opportunity.account_id,
                    contact_id     = contact_id,
                    resource_id    = param.opportunity.resource_id,
                    contract_id    = contact_id,
                    opportunity_id = param.opportunity.id,
                    ticket_id      = null,
                    // todo 标题
                    description          = $"", // todo 内容描述拼接
                    status_id            = null,
                    complete_description = null,
                    complete_time        = null,
                    create_user_id       = user.id,
                    create_time          = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    update_user_id       = user.id,
                    update_time          = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    is_system_generate   = 1,
                };
                new com_activity_dal().Insert(addActivity);
                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.ACTIVITY,
                    oper_object_id      = addActivity.id,// 操作对象id
                    oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                    oper_description    = _dal.AddValue(addActivity),
                    remark              = "商机关闭,新增项目备注"
                });
            }

            #endregion

            // 8.新增备注(商机关闭)
            #region 8.商机关闭时,会自动生成备注

            com_activity closeOppoActivity = new com_activity()
            {
                id                   = _dal.GetNextIdCom(),
                cate_id              = (int)ACTIVITY_CATE.NOTE,
                action_type_id       = (int)ACTIVITY_TYPE.OPPORTUNITYUPDATE,
                parent_id            = null,
                object_id            = param.opportunity.id,
                object_type_id       = (int)OBJECT_TYPE.OPPORTUNITY,
                account_id           = param.opportunity.account_id,
                contact_id           = contact_id,
                resource_id          = param.opportunity.resource_id,
                contract_id          = null, // todo 如果转为合同成本,则为“合同”;否则为空
                opportunity_id       = param.opportunity.id,
                ticket_id            = null,
                start_date           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(DateTime.Now.ToShortDateString() + " 12:00:00")),    // todo 从页面获取时间,去页面时间的12:00:00
                end_date             = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(DateTime.Now.ToShortDateString() + " 12:00:00")),
                description          = $"关闭时间:{DateTime.Now.ToString("dd/MM/yyyy")}/r通知人:{user.email}/r主题:{param.opportunity.name}已经关闭/r内容:商机关闭向导定义", // todo 内容描述拼接
                status_id            = null,
                complete_description = null,
                complete_time        = null,
                create_user_id       = user.id,
                create_time          = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                update_user_id       = user.id,
                update_time          = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                is_system_generate   = 1,
            };

            new com_activity_dal().Insert(closeOppoActivity);
            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.ACTIVITY,
                oper_object_id      = closeOppoActivity.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                oper_description    = _dal.AddValue(closeOppoActivity),
                remark              = "新增关闭商机的备注"
            });

            #endregion

            return(ERROR_CODE.SUCCESS);
        }
예제 #15
0
파일: QuoteBLL.cs 프로젝트: evelh/Done
        /// <summary>
        /// 丢失报价
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="quoteId"></param>
        /// <param name="reasonType">丢失原因类型</param>
        /// <param name="reasonDetail">丢失原因详情</param>
        /// <returns></returns>
        public string LossQuote(long userId, long quoteId, int reasonType, string reasonDetail)
        {
            DicEnum.SYS_CLOSE_OPPORTUNITY needReasonType;
            var type  = new SysSettingBLL().GetValueById(SysSettingEnum.CRM_OPPORTUNITY_LOSS_REASON);
            int value = 0;

            if (!int.TryParse(type, out value))
            {
                needReasonType = DicEnum.SYS_CLOSE_OPPORTUNITY.NEED_NONE;
            }
            else
            {
                needReasonType = (DicEnum.SYS_CLOSE_OPPORTUNITY)value;
            }

            // 更新商机状态为丢失
            var opporDal = new crm_opportunity_dal();
            var quote    = _dal.FindById(quoteId);
            var oppor    = opporDal.FindById(quote.opportunity_id);
            var oldOppor = opporDal.FindById(quote.opportunity_id);

            oppor.status_id      = (int)DicEnum.OPPORTUNITY_STATUS.LOST;
            oppor.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            oppor.update_user_id = userId;
            if (needReasonType == SYS_CLOSE_OPPORTUNITY.NEED_TYPE_DETAIL)
            {
                oppor.loss_reason = reasonDetail;
            }
            if (needReasonType != SYS_CLOSE_OPPORTUNITY.NEED_NONE)
            {
                oppor.loss_reason_type_id = reasonType;
            }
            opporDal.Update(oppor);

            // 保存操作商机日志
            var user = UserInfoBLL.GetUserInfo(userId);

            new sys_oper_log_dal().Insert(new sys_oper_log()
            {
                user_cate           = "用户",
                user_id             = userId,
                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      = oppor.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                oper_description    = opporDal.CompareValue(oldOppor, oppor),
                remark              = "丢失报价"
            });

            // 新增通知信息
            var notify_email_dal = new com_notify_email_dal();
            var notify_email     = new com_notify_email()
            {
                id              = notify_email_dal.GetNextIdCom(),
                cate_id         = (int)NOTIFY_CATE.CRM,
                event_id        = 1,          // TODO:
                to_email        = "",         // TODO:
                notify_tmpl_id  = 1,          // TODO:
                from_email      = user.email, // todo
                from_email_name = user.name,  // todo
                subject         = "",         // TODO:
                body_text       = "",         // TODO:
                is_html_format  = 0,          // 内容是否是html格式,0纯文本 1html
                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),
            };

            notify_email_dal.Insert(notify_email);
            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.OPPORTUNITY,
                oper_object_id      = notify_email.id,
                oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                oper_description    = notify_email_dal.AddValue(notify_email),
                remark              = "新增通知",
            });  // 插入日志

            return("");
        }