Example #1
0
        /// <summary>
        /// 报价单绑定报价模板
        /// </summary>
        /// <param name="cq"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public bool UpdateQuoteTemp(crm_quote cq, long user_id)
        {
            var user = UserInfoBLL.GetUserInfo(user_id);

            cq.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            cq.update_user_id = user_id;
            if (_dal.Update(cq))
            {
                new sys_oper_log_dal().Insert(new sys_oper_log()
                {
                    user_cate           = "用户",
                    user_id             = user_id,
                    name                = user.name,
                    phone               = user.mobile == null ? "" : user.mobile,
                    oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.QUOTE,

                    oper_object_id = cq.id,// 操作对象id

                    oper_type_id = (int)OPER_LOG_TYPE.UPDATE,

                    oper_description = _dal.AddValue(cq),
                    remark           = "关联报价模板"
                });
            }
            return(true);
        }
Example #2
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();
            }
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            udfList      = new UserDefinedFieldsBLL().GetUdf(DicEnum.UDF_CATE.CONTRACTS);
            resourceList = new DAL.sys_resource_dal().GetSourceList();
            roleList     = new DAL.sys_role_dal().GetList();
            long quoteId = 0;

            if (!string.IsNullOrEmpty(Request.QueryString["quoteId"]) && long.TryParse(Request.QueryString["quoteId"], out quoteId))
            {
                quote = new QuoteBLL().GetQuote(quoteId);
                if (quote != null)
                {
                    account = new CompanyBLL().GetCompany(quote.account_id);
                }
            }

            if (IsPostBack)
            {
                ContractAddDto dto = new ContractAddDto();
                dto.contract = AssembleModel <ctt_contract>();

                if (!string.IsNullOrEmpty(Request.Form["isSdtDefault"]) && Request.Form["isSdtDefault"].Equals("on"))
                {
                    dto.contract.is_sdt_default = 1;
                }

                if (!string.IsNullOrEmpty(Request.Form["needTimeSheet"]) && Request.Form["needTimeSheet"].Equals("on"))
                {
                    dto.contract.timeentry_need_begin_end = 1;
                }
                else
                {
                    dto.contract.timeentry_need_begin_end = 0;
                }

                if (dto.contract.type_id == (int)DicEnum.CONTRACT_TYPE.BLOCK_HOURS)
                {
                    if (!string.IsNullOrEmpty(Request.Form["enableOverage"]) && Request.Form["enableOverage"].Equals("on"))
                    {
                        dto.contract.enable_overage_billing_rate = 1;
                    }
                }

                if (dto.contract.type_id == (int)DicEnum.CONTRACT_TYPE.FIXED_PRICE)
                {
                    if (!string.IsNullOrEmpty(Request.Form["applyPayment"]) && Request.Form["applyPayment"].Equals("on"))
                    {
                        decimal price = 0;
                        if (decimal.TryParse(Request.Form["alreadyReceived"], out price) && price > 0)
                        {
                            dto.alreadyReceived = price;
                        }
                        if (decimal.TryParse(Request.Form["toBeInvoiced"], out price) && price > 0)
                        {
                            dto.toBeInvoiced = price;
                        }
                        long code = 0;
                        if (long.TryParse(Request.Form["defaultCostCode"], out code))
                        {
                            dto.defaultCostCode = code;
                        }
                    }
                }

                if (udfList != null && udfList.Count > 0)                      // 首先判断是否有自定义信息
                {
                    var list = new List <UserDefinedFieldValue>();
                    foreach (var udf in udfList)                            // 循环添加
                    {
                        var new_udf = new UserDefinedFieldValue()
                        {
                            id    = udf.id,
                            value = Request.Form[udf.id.ToString()] == "" ? null : Request.Form[udf.id.ToString()],
                        };
                        list.Add(new_udf);
                    }
                    dto.udf = list;
                }

                // 服务
                dto.serviceList = new List <ServiceInfoDto>();
                if (dto.contract.type_id == (int)DicEnum.CONTRACT_TYPE.SERVICE)
                {
                    if (!string.IsNullOrEmpty(Request.Form["AddServiceIds"]))   // 服务
                    {
                        string[] ids = Request.Form["AddServiceIds"].Split(',');
                        foreach (string id in ids)
                        {
                            ServiceInfoDto si = new ServiceInfoDto();
                            si.price     = decimal.Parse(Request.Form["price" + id]);
                            si.number    = decimal.Parse(Request.Form["num" + id]);
                            si.serviceId = long.Parse(id);
                            si.type      = 1;
                            dto.serviceList.Add(si);
                        }
                    }
                    if (!string.IsNullOrEmpty(Request.Form["AddSerBunIds"]))    // 服务包
                    {
                        string[] ids = Request.Form["AddSerBunIds"].Split(',');
                        foreach (string id in ids)
                        {
                            ServiceInfoDto si = new ServiceInfoDto();
                            si.price     = decimal.Parse(Request.Form["price" + id]);
                            si.number    = decimal.Parse(Request.Form["num" + id]);
                            si.serviceId = long.Parse(id);
                            si.type      = 2;
                            dto.serviceList.Add(si);
                        }
                    }
                }

                // 里程碑
                dto.milestone = new List <ctt_contract_milestone>();
                if (dto.contract.type_id == (int)DicEnum.CONTRACT_TYPE.FIXED_PRICE && (!string.IsNullOrEmpty(Request.Form["milestoneAddList"])))
                {
                    string[] ids = Request.Form["milestoneAddList"].Split(',');
                    foreach (string id in ids)
                    {
                        ctt_contract_milestone mil = new ctt_contract_milestone();
                        mil.name        = Request.Form["MilName" + id];
                        mil.description = Request.Form["MilDetail" + id];
                        decimal dollar = 0;
                        if (!decimal.TryParse(Request.Form["MilAmount" + id], out dollar))
                        {
                            dollar = 0;
                        }
                        mil.dollars      = dollar;
                        mil.due_date     = DateTime.Parse(Request.Form["MilDate" + id]);
                        mil.cost_code_id = long.Parse(Request.Form["MilCode" + id]);
                        mil.status_id    = int.Parse(Request.Form["isBill" + id]);
                        dto.milestone.Add(mil);
                    }
                }

                // 角色费率
                dto.rateList = new List <ContractRateDto>();
                if (dto.contract.type_id != (int)DicEnum.CONTRACT_TYPE.SERVICE &&
                    dto.contract.type_id != (int)DicEnum.CONTRACT_TYPE.PER_TICKET)
                {
                    foreach (var role in roleList)
                    {
                        if (Request.Form["cbRoleRate" + role.id] != null && Request.Form["cbRoleRate" + role.id].Equals("on"))
                        {
                            var roleRate = new ContractRateDto();
                            roleRate.roleId = role.id;
                            roleRate.rate   = decimal.Parse(Request.Form["txtRoleRate" + role.id]);
                            dto.rateList.Add(roleRate);
                        }
                    }
                }

                // 邮件通知
                dto.notifyUserIds = new List <long>();
                foreach (var res in resourceList)
                {
                    if (Request.Form["notify" + res.id] != null && Request.Form["notify" + res.id].Equals("on"))
                    {
                        dto.notifyUserIds.Add(res.id);
                    }
                }
                if (dto.notifyUserIds.Count != 0)
                {
                    dto.notifySubject = Request.Form["notifyTitle"];
                    dto.notifyMessage = Request.Form["notifyContent"];
                    dto.notifyEmails  = Request.Form["notifyEmails"];
                }

                contractId   = bll.Insert(dto, GetLoginUserId());
                contractType = dto.contract.type_id;
                isFinish     = 1;
            }
            else
            {
                if (!int.TryParse(Request.QueryString["type"], out contractType))
                {
                    contractType = 0;
                }
                isFinish = 0;
            }

            Dictionary <string, object> dics = bll.GetField();

            contractCate = dics["cate"] as List <DictionaryEntryDto>;
            periodType   = dics["periodType"] as List <DictionaryEntryDto>;
            periodType.Remove(periodType.Find(pt => pt.val.Equals(((int)DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME).ToString())));
            billPostType = dics["billPostType"] as List <DictionaryEntryDto>;
            slaList      = bll.GetSLAList();

            contractTypeName = bll.GetContractTypeName(contractType);
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                // todo - 商机的重新指派

                var sid = Request.QueryString["id"];
                if (AuthBLL.GetUserSaleorderAuth(LoginUserId, LoginUser.security_Level_id, Convert.ToInt64(sid)).CanView == false)
                {
                    Response.End();
                    return;
                }
                thisBookMark = new IndexBLL().GetSingBook(Request.Url.LocalPath + "?id=" + sid, LoginUserId);

                type        = Request.QueryString["type"];
                sale_order  = new crm_sales_order_dal().GetSingleSale(long.Parse(sid));
                opportunity = new crm_opportunity_dal().GetOpportunityById(sale_order.opportunity_id);
                account     = new CompanyBLL().GetCompany(opportunity.account_id);
                quote       = new QuoteBLL().GetPrimaryQuote(opportunity.id);
                if (sale_order.contact_id != null)
                {
                    contact = new ContactBLL().GetContact((long)sale_order.contact_id);
                }
                switch (type)
                {
                case "activity":
                    actType          = "活动";
                    isShowLeft.Value = "1";
                    break;

                case "todo":
                    actType          = "待办";
                    iframeSrc        = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.TODOS + "&type=" + (int)QueryType.Todos + "&group=131&con676=" + sale_order.id + "&param1=saleorderId&param2=" + sale_order.id;
                    isShowLeft.Value = "1";
                    break;

                case "note":
                    actType          = "备注";
                    iframeSrc        = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.CRM_NOTE_SEARCH + "&type=" + (int)QueryType.CRMNote + "&group=129&con675=" + sale_order.id + "&param1=saleorderId&param2=" + sale_order.id;
                    isShowLeft.Value = "1";
                    break;

                case "ticket":
                    actType = "工单";
                    break;

                case "attachment":
                    actType   = "附件";
                    iframeSrc = "../Common/SearchBodyFrame.aspx?cat=" + (int)DicEnum.QUERY_CATE.SALES_ORDER_VIEW_ATTACHMENT + "&type=" + (int)QueryType.SalesOrderViewAttachment + "&con977=" + sale_order.id;
                    break;

                case "entry":
                    actType   = "报价项";
                    iframeSrc = "../QuoteItem/QuoteItemManage.aspx?isShow=1&quote_id=" + quote.id + "&isSaleOrder=1&sale_order_id=" + sale_order.id;
                    break;

                case "purchaseOrder":
                    actType = "采购订单";
                    break;

                default:
                    actType          = "活动";
                    type             = "activity";
                    isShowLeft.Value = "1";
                    break;
                }

                if (type.Equals("activity"))
                {
                    var typeList = new ActivityBLL().GetCRMActionType();
                    noteType.DataSource     = typeList;
                    noteType.DataTextField  = "name";
                    noteType.DataValueField = "id";
                    noteType.DataBind();
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
Example #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var quote_id = Request.QueryString["quote_id"];

            if (!string.IsNullOrEmpty(quote_id))
            {
                quote = new crm_quote_dal().FindNoDeleteById(long.Parse(quote_id));
            }
            if (quote != null)
            {
                // 如何获取到已经生成配置项 的报价项和为生成配置项的报价项

                // 1 获取产品相关报价项
                // 2 根据产品报价项的数量,去获取相应的配置项数量,数量不足时,将剩余的报价项放入展示的报价项中
                // 3 成本同理

                var cqiDal = new crm_quote_item_dal();
                var cipDal = new crm_installed_product_dal();
                #region 获取相应的产品报价项
                var productList = cqiDal.GetItemByType(quote.id, (int)DTO.DicEnum.QUOTE_ITEM_TYPE.PRODUCT);
                if (productList != null && productList.Count > 0)
                {
                    isShowProduct = true;

                    foreach (var item in productList)
                    {
                        if (item.quantity != null && item.quote_id != null)
                        {
                            var insProList = cipDal.GetInsProByQuoteId((long)item.id, (long)item.quantity);
                            int num        = (int)item.quantity; // 获取多少次 这个报价项
                            if (insProList != null && insProList.Count > 0)
                            {
                                num = (int)item.quantity - insProList.Count;
                                var itemList = cqiDal.GetItemByNum(item.id, insProList.Count);
                                if (itemList != null && itemList.Count > 0)
                                {
                                    ExistProductItemList.AddRange(itemList);
                                }
                            }
                            if (num > 0)
                            {
                                var itemList = cqiDal.GetItemByNum(item.id, num);
                                if (itemList != null && itemList.Count > 0)
                                {
                                    productItemList.AddRange(itemList);
                                }
                            }
                        }
                    }
                }
                #endregion


                #region 获取相应的成本报价项
                var chargeList = cqiDal.GetItemByType(quote.id, (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DEGRESSION);
                if (chargeList != null && chargeList.Count > 0)
                {
                    isShowCharge = true;

                    foreach (var item in chargeList)
                    {
                        if (item.quantity != null && item.quote_id != null)
                        {
                            var insProList = cipDal.GetInsProByQuoteId((long)item.id, (long)item.quantity);
                            int num        = (int)item.quantity; // 获取多少次 这个报价项
                            if (insProList != null && insProList.Count > 0)
                            {
                                num = (int)item.quantity - insProList.Count;
                                var itemList = cqiDal.GetItemByNum(item.id, insProList.Count);
                                if (itemList != null && itemList.Count > 0)
                                {
                                    ExistChargeItemList.AddRange(itemList);
                                }
                            }
                            if (num > 0)
                            {
                                var itemList = cqiDal.GetItemByNum(item.id, num);
                                if (itemList != null && itemList.Count > 0)
                                {
                                    chargeItemList.AddRange(itemList);
                                }
                            }
                        }
                    }
                }

                #endregion

                if (!IsPostBack)
                {
                    rbBuyDate.Enabled = false;
                }
            }
        }
Example #6
0
        protected crm_quote LocationDeal(crm_quote quote)
        {
            try
            {
                // 账单地址和配送地址新增删除处理
                // 首先要整理称谓地址对象  与默认地址的相同更改校验
                // 校验地址必填信息
                // 然后判断新增还是修改进行操作
                var sold_location_id = Request.Params["sold_to_location_id"];

                var old_sold_location = new LocationBLL().GetLocation(long.Parse(sold_location_id));
                if (old_sold_location == null)
                {
                    return(quote);
                }
                var sold_location = new crm_location()
                {
                    id                 = old_sold_location.id,
                    account_id         = old_sold_location.account_id,
                    cate_id            = old_sold_location.cate_id,
                    create_time        = old_sold_location.create_time,
                    create_user_id     = old_sold_location.create_user_id,
                    delete_time        = old_sold_location.delete_time,
                    delete_user_id     = old_sold_location.delete_user_id,
                    is_default         = old_sold_location.is_default,
                    location_label     = old_sold_location.location_label,
                    oid                = old_sold_location.is_default,
                    additional_address = Request.Params["address2"],
                    address            = Request.Params["address"],
                    city_id            = string.IsNullOrEmpty(Request.Params["city_id"]) ? 0 : int.Parse(Request.Params["city_id"]),
                    country_id         = old_sold_location.country_id,
                    district_id        = string.IsNullOrEmpty(Request.Params["district_id"]) ? 0 : int.Parse(Request.Params["district_id"]),
                    postal_code        = Request.Params["postal_code"],
                    province_id        = string.IsNullOrEmpty(Request.Params["province_id"]) ? 0 : int.Parse(Request.Params["province_id"]),
                    town_id            = old_sold_location.town_id,
                };
                if (sold_location.country_id != 0 && sold_location.province_id != 0 && sold_location.city_id != 0 && sold_location.district_id != 0 && (!string.IsNullOrEmpty(sold_location.address)))
                {
                    sold_location.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    sold_location.update_user_id = GetLoginUserId();
                    new LocationBLL().Update(sold_location, GetLoginUserId());
                }

                if (BillLocation.Checked)
                {
                    quote.bill_to_location_id = quote.sold_to_location_id;
                }
                else
                {
                    var bill_id       = Request.Params["bill_to_location_id"];
                    var bill_location = new crm_location()
                    {
                        //id = long.Parse(bill_id),
                        account_id         = quote.account_id,
                        additional_address = Request.Params["bill_address2"],
                        address            = Request.Params["bill_address"],
                        city_id            = string.IsNullOrEmpty(Request.Params["bill_city_id"]) ? 0 : int.Parse(Request.Params["bill_city_id"]),
                        country_id         = 1,
                        district_id        = string.IsNullOrEmpty(Request.Params["bill_district_id"]) ? 0 : int.Parse(Request.Params["bill_district_id"]),
                        is_default         = 0,
                        province_id        = string.IsNullOrEmpty(Request.Params["bill_province_id"]) ? 0 : int.Parse(Request.Params["bill_province_id"]),
                        postal_code        = Request.Params["bill_postcode"],
                    };
                    // 地址必填项未填写暂时不处理???
                    if (bill_location.country_id != 0 && bill_location.province_id != 0 && bill_location.city_id != 0 && bill_location.district_id != 0 && (!string.IsNullOrEmpty(bill_location.address)))
                    {
                        if (!string.IsNullOrEmpty(bill_id))  // 用户界面上存在账单地址 此时代表和客户默认地址相同或者是在更改地址
                        {
                            if (bill_id == sold_location_id)
                            {
                                if (bill_location.city_id != sold_location.city_id || bill_location.city_id != sold_location.city_id || bill_location.district_id != sold_location.district_id || bill_location.address != sold_location.address || bill_location.additional_address != sold_location.additional_address || bill_location.postal_code != sold_location.postal_code)
                                {
                                    bill_location.id = new crm_location_dal().GetNextIdCom();
                                    if (new LocationBLL().Insert(bill_location, GetLoginUserId()))
                                    {
                                        quote.bill_to_location_id = bill_location.id;
                                    }
                                }
                            }
                            else
                            {
                                bill_location.id = long.Parse(bill_id);
                                new LocationBLL().Update(bill_location, GetLoginUserId());
                            }
                        }
                        else
                        {
                            bill_location.id = new crm_location_dal().GetNextIdCom();
                            if (new LocationBLL().Insert(bill_location, GetLoginUserId()))
                            {
                                quote.bill_to_location_id = bill_location.id;
                            }
                        }
                    }
                }

                if (ShipLocation.Checked)
                {
                    quote.ship_to_location_id = quote.sold_to_location_id;
                }
                else
                {
                    var ship_id       = Request.Params["ship_to_location_id"];
                    var ship_location = new crm_location()
                    {
                        //id = long.Parse(bill_id),
                        account_id         = quote.account_id,
                        additional_address = Request.Params["ship_address2"],
                        address            = Request.Params["ship_address"],
                        city_id            = string.IsNullOrEmpty(Request.Params["ship_city_id"]) ? 0 : int.Parse(Request.Params["ship_city_id"]),
                        country_id         = 1,
                        district_id        = string.IsNullOrEmpty(Request.Params["ship_district_id"]) ? 0 : int.Parse(Request.Params["ship_district_id"]),
                        is_default         = 0,
                        province_id        = string.IsNullOrEmpty(Request.Params["ship_province_id"]) ? 0 : int.Parse(Request.Params["ship_province_id"]),
                        postal_code        = Request.Params["ship_postcode"],
                    };
                    // 地址必填项未填写暂时不处理???
                    if (ship_location.country_id != 0 && ship_location.province_id != 0 && ship_location.city_id != 0 && ship_location.district_id != 0 && (!string.IsNullOrEmpty(ship_location.address)))
                    {
                        if (!string.IsNullOrEmpty(ship_id))  // 用户界面上存在账单地址 此时代表和客户默认地址相同或者是在更改地址
                        {
                            if (ship_id == sold_location_id)
                            {
                                if (ship_location.city_id != sold_location.city_id || ship_location.city_id != sold_location.city_id || ship_location.district_id != sold_location.district_id || ship_location.address != sold_location.address || ship_location.additional_address != sold_location.additional_address || ship_location.postal_code != sold_location.postal_code)
                                {
                                    ship_location.id = new crm_location_dal().GetNextIdCom();
                                    if (new LocationBLL().Insert(ship_location, GetLoginUserId()))
                                    {
                                        quote.ship_to_location_id = ship_location.id;
                                    }
                                }
                            }
                            else
                            {
                                ship_location.id = long.Parse(ship_id);
                                new LocationBLL().Update(ship_location, GetLoginUserId());
                            }
                        }
                        else
                        {
                            ship_location.id = new crm_location_dal().GetNextIdCom();
                            if (new LocationBLL().Insert(ship_location, GetLoginUserId()))
                            {
                                quote.ship_to_location_id = ship_location.id;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            return(quote);
        }
Example #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                thisBookMark = new IndexBLL().GetSingBook(Request.RawUrl, LoginUserId);
                tmplList     = new FormTemplateBLL().GetTmplByType((int)DicEnum.FORM_TMPL_TYPE.QUOTE, LoginUserId);
                var id = Request.QueryString["id"];
                dic = new QuoteBLL().GetField();
                #region  拉框配置数据源
                tax_region_id.DataValueField = "val";
                tax_region_id.DataTextField  = "show";
                tax_region_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "taxRegion").Value;
                tax_region_id.DataBind();
                tax_region_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });

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


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

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

                quote_tmpl_id.DataValueField = "id";
                quote_tmpl_id.DataTextField  = "name";
                quote_tmpl_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "quote_tmpl").Value;
                quote_tmpl_id.DataBind();
                quote_tmpl_id.Items.Insert(0, new ListItem()
                {
                    Value = "0", Text = "   ", Selected = true
                });
                var prolist = new pro_project_dal().GetProjectList();
                // project_id
                //project_id.DataValueField = "id";
                //project_id.DataTextField = "name";
                //project_id.DataSource = prolist;
                //project_id.DataBind();
                //project_id.Items.Insert(0, new ListItem() { Value = "0", Text = "   ", Selected = true });
                #endregion

                if (!string.IsNullOrEmpty(id))
                {
                    if (AuthBLL.GetUserQuoteAuth(LoginUserId, LoginUser.security_Level_id, Convert.ToInt64(id)).CanEdit == false)
                    {
                        Response.End();
                        return;
                    }
                    quote = new crm_quote_dal().GetQuote(Convert.ToInt64(id));
                    if (quote != null)
                    {
                        if (string.IsNullOrEmpty(Request.QueryString["copy"]))
                        {
                            isAdd = false;
                        }
                    }
                }
                else
                {
                    var opportunity_id = Request.QueryString["quote_opportunity_id"];
                    if (!string.IsNullOrEmpty(opportunity_id))
                    {
                        opportunity = new crm_opportunity_dal().GetOpportunityById(long.Parse(opportunity_id));
                        account     = new CompanyBLL().GetCompany(opportunity.account_id);
                    }
                }
                if (!IsPostBack)
                {
                    if (!isAdd)
                    {
                        account = new CompanyBLL().GetCompany(quote.account_id);
                        if (account != null)
                        {
                            tax_region_id.SelectedValue = account.tax_region_id != null?account.tax_region_id.ToString() : "0";

                            payment_term_id.SelectedValue = quote.payment_term_id != null?quote.payment_term_id.ToString() : "0";

                            payment_type_id.SelectedValue = quote.payment_type_id != null?quote.payment_type_id.ToString() : "0";   //shipping_type_id

                            shipping_type_id.SelectedValue = quote.shipping_type_id != null?quote.shipping_type_id.ToString() : "0";

                            quote_tmpl_id.SelectedValue = quote.quote_tmpl_id != null?quote.quote_tmpl_id.ToString() : "0";

                            //project_id.SelectedValue = quote.project_id!=null ?  quote.project_id.ToString() : "0";
                            BillLocation.Checked = quote.bill_to_location_id == quote.sold_to_location_id;
                            ShipLocation.Checked = quote.ship_to_location_id == quote.sold_to_location_id;
                        }
                        #region 记录浏览历史
                        var history = new sys_windows_history()
                        {
                            title = $"编辑报价:" + quote.name + " " + (account != null ? account.name : ""),
                            url   = Request.RawUrl,
                        };
                        new IndexBLL().BrowseHistory(history, LoginUserId);
                        #endregion
                    }
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
Example #8
0
        protected void save_open_quote_Click(object sender, EventArgs e)
        {
            var quote = new crm_quote();

            quote = AssembleModel <crm_quote>();
            quote = LocationDeal(quote);
            if (isAdd)
            {
                var result = new QuoteBLL().Insert(quote, GetLoginUserId());
                switch (result)
                {
                case ERROR_CODE.SUCCESS:      //E:\DoneNOW\EMT.DoneNOW.Web\QuoteItem\QuoteItemManage.aspx
                    //ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('添加报价成功!');window.open('../QuoteItem/QuoteItemManage.aspx?quote_id=" + quote.id.ToString() + "','" + OpenWindow.QuoteItemManage + "','left=200,top=200,width=960,height=750', false);</script>");
                    Response.Write("<script>alert('添加报价成功!');");
                    Response.Redirect("../QuoteItem/QuoteItemManage.aspx?quote_id=" + quote.id);
                    break;

                case ERROR_CODE.ERROR:
                    break;

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

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

                default:
                    break;
                }
            }
            else
            {
                quote.id  = this.quote.id;
                quote.oid = this.quote.oid;
                quote.projected_close_date = this.quote.projected_close_date;
                quote.is_primary_quote     = this.quote.is_primary_quote;
                quote.group_by_id          = this.quote.group_by_id;
                var result = new QuoteBLL().Update(quote, GetLoginUserId());
                switch (result)
                {
                case ERROR_CODE.SUCCESS:
                    //ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('修改报价成功!');window.close();</script>");
                    //ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('修改报价成功!');window.open('../QuoteItem/QuoteItemManage.aspx?quote_id=" + quote.id.ToString() + "');</script>");
                    Response.Write("<script>alert('修改报价成功!');self.opener.location.reload();</script>");
                    Response.Redirect("../QuoteItem/QuoteItemManage.aspx?quote_id=" + quote.id);
                    break;

                case ERROR_CODE.ERROR:
                    break;

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

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

                default:
                    break;
                }
            }
        }
Example #9
0
        /// <summary>
        /// 保存并关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void save_close_Click(object sender, EventArgs e)
        {
            var quote = new crm_quote();

            quote = AssembleModel <crm_quote>();
            quote = LocationDeal(quote);
            var bill = BillLocation.Checked;

            if (isAdd)
            {
                var result = new QuoteBLL().Insert(quote, GetLoginUserId());
                switch (result)
                {
                case ERROR_CODE.SUCCESS:
                    ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('添加报价成功!');window.close();self.opener.location.reload();</script>");
                    break;

                case ERROR_CODE.ERROR:
                    break;

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

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

                default:
                    break;
                }
            }
            else
            {
                quote.id  = this.quote.id;
                quote.oid = this.quote.oid;
                quote.projected_close_date = this.quote.projected_close_date;
                quote.is_primary_quote     = this.quote.is_primary_quote;
                quote.group_by_id          = this.quote.group_by_id;
                var result = new QuoteBLL().Update(quote, GetLoginUserId());
                switch (result)
                {
                case ERROR_CODE.SUCCESS:
                    ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('修改报价成功!');window.close();</script>");
                    break;

                case ERROR_CODE.ERROR:
                    break;

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

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

                default:
                    break;
                }
            }
        }
Example #10
0
        protected List <crm_quote_item> serviceItem   = null; // 该报价下的服务报价项
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var quote_id = Request.QueryString["id"];
                quote = new QuoteBLL().GetQuote(long.Parse(quote_id));
                if (quote.is_primary_quote != 1) // 关闭报价只针对主报价
                {
                    Response.Write("<script>alert('关闭报价只针对主报价');window.close();</script>");
                }
                //if (quote.project_id == null)
                //{
                //    Response.Write("<script>alert('请关联项目后进行关闭报价操作');window.close();</script>");
                //}
                opportunity = new crm_opportunity_dal().GetOpportunityById(quote.opportunity_id);
                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
                });

                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 == 37 || _.id == 43).ToList();
                if (disCostCode != null && disCostCode.Count > 0)
                {
                    foreach (var item in disCostCode)
                    {
                        disSource += $"<option value='{item.id}'>{item.name}</option>";
                    }
                }
                disCodeSelct.Value = disSource;


                quoteItemList = new crm_quote_item_dal().GetQuoteItems($"and quote_id = {quote.id}");
                quoteItemList = quoteItemList.Where(_ => _.optional == 0 && _.type_id != (int)QUOTE_ITEM_TYPE.COST && _.type_id != (int)QUOTE_ITEM_TYPE.SERVICE && _.type_id != (int)QUOTE_ITEM_TYPE.WORKING_HOURS).ToList();
                if (quoteItemList != null && quoteItemList.Count > 0)
                {
                    serviceItem = quoteItemList.Where(_ => _.type_id == (int)EMT.DoneNOW.DTO.DicEnum.QUOTE_ITEM_TYPE.SERVICE || _.type_id == (int)EMT.DoneNOW.DTO.DicEnum.QUOTE_ITEM_TYPE.START_COST).ToList();
                    if (serviceItem != null && serviceItem.Count > 0)
                    {
                        Response.Write("<script>alert('报价中包含服务/包、初始费用等,请使用关闭商机向导');window.close();</script>");
                    }

                    jqueryCode.Value = ReturnJquery();
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
Example #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                thisBookMark = new IndexBLL().GetSingBook(Request.RawUrl, LoginUserId);
                // quote_group_by

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


                isShow      = Request.QueryString["isShow"];
                IssaleOrder = !string.IsNullOrEmpty(Request.QueryString["isSaleOrder"]);
                var sid = Request.QueryString["sale_order_id"];
                if (!string.IsNullOrEmpty(sid))
                {
                    sale_order_id = long.Parse(sid);
                }


                var quote_id = Request.QueryString["quote_id"];
                if (!string.IsNullOrEmpty(quote_id))
                {
                    quote = new QuoteBLL().GetQuote(Convert.ToInt64(quote_id));

                    if (quote.quote_tmpl_id != null)
                    {
                        var sys_quote_temp = new QuoteTemplateBLL().GetQuoteTemplate((long)quote.quote_tmpl_id);
                        if (sys_quote_temp != null)
                        {
                            // 获取到该报价的报价模板用于设置税的显示方式和汇总名称
                            show_each_tax_in_tax_group.Value  = sys_quote_temp.show_each_tax_in_tax_group.ToString();
                            show_each_tax_in_tax_period.Value = sys_quote_temp.show_each_tax_in_tax_period.ToString(); // 选中第一个:按照周期分组时起作用,每个周期后显示税 最后的汇总也有税)
                                                                                                                       // var a3 =sys_quote_temp.show_labels_when_grouped;  // 预留字段
                            show_tax_cate.Value             = sys_quote_temp.show_tax_cate.ToString();
                            show_tax_cate_superscript.Value = sys_quote_temp.show_tax_cate_superscript.ToString();
                        }
                    }
                }
                var opportunity_id = Request.QueryString["opportunity_id"];  // 这里是通过商机查看报价项的情况
                if (!string.IsNullOrEmpty(opportunity_id))
                {
                    var oppoQuoteList = new crm_quote_dal().GetQuoteByWhere($" and opportunity_id = {opportunity_id} ");

                    if (oppoQuoteList != null && oppoQuoteList.Count > 0)
                    {
                        quote = oppoQuoteList.FirstOrDefault(_ => _.is_primary_quote == 1);  // 如果该商机下有报价则一定会有主报价
                    }
                }

                if (quote != null)
                {
                    quoteItemList = new crm_quote_item_dal().GetQuoteItems($" and quote_id={quote.id} ");
                    // quoteItemList.Sort(SortCycle);  // 自定义排序测试
                    quoteItemList = quoteItemList.OrderBy(_ => SortQuoteItem(_.period_type_id)).ToList();
                    quoteList     = new crm_quote_dal().GetQuoteByWhere($" and opportunity_id = {quote.opportunity_id} ");
                    var primaryQuote = quoteList.FirstOrDefault(_ => _.is_primary_quote == 1);
                    if (primaryQuote != null)
                    {
                        var thisQuoteItemList = new crm_quote_item_dal().GetQuoteItems($" and quote_id={primaryQuote.id} ");


                        var thisDiscountQIList   = thisQuoteItemList.Where(_ => _.type_id == (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && _.optional == 0).ToList();
                        var thisOneTimeQTList    = thisQuoteItemList.Where(_ => _.period_type_id == (int)DTO.DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME && _.optional == 0).ToList();
                        var thisOptionalItemList = thisQuoteItemList.Where(_ => _.optional == 1).ToList();

                        var totalPrice = ((decimal)((thisQuoteItemList.Sum(_ => (_.unit_discount != null && _.unit_price != null && _.quantity != null) ? (_.unit_price - _.unit_discount) * _.quantity : 0) - thisDiscountQIList.Where(_ => _.discount_percent != null).ToList().Sum(_ => (_.unit_discount != null && _.quantity != null) ? _.unit_discount * _.quantity : 0) - (thisOneTimeQTList != null && thisOneTimeQTList.Count > 0 ? thisDiscountQIList.Where(_ => _.discount_percent != null).ToList().Sum(_ => thisOneTimeQTList.Sum(one => (one.unit_discount != null && one.unit_price != null && one.quantity != null) ? (one.unit_price - one.unit_discount) * one.quantity : 0) * _.discount_percent) : 0)))).ToString("#0.00");
                        quoteList.Remove(primaryQuote);
                        primaryQuote.name = "PRIMARY:" + primaryQuote.name + "(" + totalPrice + ")";
                        quoteList.Add(primaryQuote);
                    }


                    #region // 为报价下拉框赋值
                    quoteDropList.DataValueField = "id";
                    quoteDropList.DataTextField  = "name";
                    quoteDropList.DataSource     = quoteList;
                    quoteDropList.DataBind();
                    quoteDropList.SelectedValue = quote.id.ToString();
                    #endregion
                    if (quoteItemList != null && quoteItemList.Count > 0)
                    {
                        // 用户需要添加折扣类型的报价项,然后可以针对付费周期类型为一次性的报价项进行折扣
                        // 折扣只针对一次性周期的报价项折扣
                        oneTimeList = quoteItemList.Where(_ => _.period_type_id == (int)DTO.DicEnum.QUOTE_ITEM_PERIOD_TYPE.ONE_TIME && _.optional == 0 && _.type_id != (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && _.type_id != (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES).ToList();

                        discountQIList = quoteItemList.Where(_ => _.type_id == (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT && _.optional == 0).ToList();

                        //  获取到可选的报价项,
                        optionalItemList = quoteItemList.Where(_ => _.optional == 1).ToList();   // 获取到可选的报价项
                        // optionalItemList.Sort();

                        // &&optionalItemList.Any(op=>op.id!=_.id)&&oneTimeList.Any(one=>one.id!=_.id)  满足多个报价项过滤条件的,选择其中的一个
                        distributionList = quoteItemList.Where(_ => _.type_id == (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES && _.optional == 0).ToList();   // 配送类型的报价项

                        // 配送,一次性,可选的配置项独立显示,所以在这里分离出来,传到前台后单独处理

                        //  获取到筛选后报价项列表方便分组管理  筛选后的列表不包括可选,一次性的折扣和配送
                        var screenList = quoteItemList.Where(_ => _.type_id != (int)EMT.DoneNOW.DTO.DicEnum.QUOTE_ITEM_TYPE.DISTRIBUTION_EXPENSES && _.optional != 1 && _.type_id != (int)DTO.DicEnum.QUOTE_ITEM_TYPE.DISCOUNT).ToList();

                        if (!string.IsNullOrEmpty(Request.QueryString["group_by"]))
                        {
                            groupByType = Request.QueryString["group_by"];
                        }
                        else
                        {
                            if (quote.group_by_id != null)
                            {
                                groupByType = ((long)quote.group_by_id).ToString();
                            }
                        }
                        //  groupByType = ?((long)quote.group_by_id).ToString():Request.QueryString["group_by"];
                        if (groupByType == ((int)EMT.DoneNOW.DTO.DicEnum.QUOTE_GROUP_BY.CYCLE).ToString())                                                                      // 按周期分组
                        {
                            groupList = screenList.GroupBy(_ => _.period_type_id == null ? "" : _.period_type_id.ToString()).ToDictionary(_ => (object)_.Key, _ => _.ToList()); // as Dictionary<long?,
                            new QuoteBLL().UpdateGroup(quote.id, (int)QUOTE_GROUP_BY.CYCLE, GetLoginUserId());
                            groupBy.SelectedValue = ((int)QUOTE_GROUP_BY.CYCLE).ToString();
                        }
                        else if (groupByType == ((int)QUOTE_GROUP_BY.PRODUCT).ToString())  // 按产品分组
                        {
                            groupList = screenList.GroupBy(_ => _.object_id == null ? "" : ReturnProductID((long)_.object_id)).ToDictionary(_ => (object)_.Key, _ => _.ToList());
                            new QuoteBLL().UpdateGroup(quote.id, (int)QUOTE_GROUP_BY.PRODUCT, GetLoginUserId());
                            groupBy.SelectedValue = ((int)QUOTE_GROUP_BY.PRODUCT).ToString();
                        }
                        else if (groupByType == ((int)QUOTE_GROUP_BY.CYCLE_PRODUCT).ToString())   // 按周期产品分组
                        {
                            new QuoteBLL().UpdateGroup(quote.id, (int)QUOTE_GROUP_BY.CYCLE_PRODUCT, GetLoginUserId());
                            groupBy.SelectedValue = ((int)QUOTE_GROUP_BY.CYCLE_PRODUCT).ToString();
                            doubleGroupList       = screenList.GroupBy(d => d.period_type_id == null ? "" : d.period_type_id.ToString()).ToDictionary(_ => (object)_.Key, _ => _.ToList().GroupBy(d => d.object_id == null ? "" : ReturnProductID((long)d.object_id)).ToDictionary(d => (object)d.Key, d => d.ToList()));
                        }
                        else if (groupByType == ((int)QUOTE_GROUP_BY.PRODUCT_CYCLE).ToString()) // 按产品周期分组
                        {
                            new QuoteBLL().UpdateGroup(quote.id, (int)QUOTE_GROUP_BY.PRODUCT_CYCLE, GetLoginUserId());
                            groupBy.SelectedValue = ((int)QUOTE_GROUP_BY.PRODUCT_CYCLE).ToString();
                            doubleGroupList       = screenList.GroupBy(_ => _.object_id == null ? "" : ReturnProductID((long)_.object_id)).ToDictionary(_ => (object)_.Key, _ => _.ToList().GroupBy(d => d.period_type_id == null ? "" : d.period_type_id.ToString()).ToDictionary(d => (object)d.Key, d => d.ToList()));
                        }
                        else // 不分组
                        {
                            new QuoteBLL().UpdateGroup(quote.id, (int)QUOTE_GROUP_BY.NO, GetLoginUserId());
                            groupBy.SelectedValue = ((int)QUOTE_GROUP_BY.NO).ToString();
                        }
                        //switch (groupByType)
                        //{
                        //    case "cycle":
                        //        // 按照周期分组
                        //        break;
                        //    case "product":
                        //        break;
                        //    default:
                        //        groupByType = "no";
                        //        break;
                        //}
                        // ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script> $(\"#groupBy\").val('"+groupBy+"')</script>");
                        if (discountQIList != null && discountQIList.Count > 0)
                        {
                            discountQIList.ForEach(_ => { if (_.discount_percent != null)
                                                          {
                                                              _.discount_percent = _.discount_percent / 100;
                                                          }
                                                   });
                        }
                    }
                }
                else
                {
                    Response.End();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #12
0
        /// <summary>
        /// 插入报价
        /// </summary>
        /// <param name="quote"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public ERROR_CODE Insert(crm_quote quote, long user_id)
        {
            if (quote.account_id == 0 || string.IsNullOrEmpty(quote.name) || (quote.contact_id == 0 && quote.opportunity_id == 0))
            {
                return(ERROR_CODE.PARAMS_ERROR);
            }
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {
                return(ERROR_CODE.USER_NOT_FIND);
            }



            #region 3.保存商机
            if (quote.opportunity_id == 0)  // 代表用户未选择商机,此时自动创建商机
            {
                var opportunity = new crm_opportunity()
                {
                    id                   = _dal.GetNextIdCom(),
                    name                 = quote.name,
                    account_id           = quote.account_id,
                    resource_id          = user_id,
                    stage_id             = (int)OPPORTUNITY_STAGE.NEW_CLUE, // todo 取到商机阶段中的最小值
                    status_id            = (int)OPPORTUNITY_STATUS.ACTIVE,
                    create_time          = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    projected_close_date = quote.projected_close_date,
                    use_quote            = 1,
                    one_time_cost        = 0,
                    one_time_revenue     = 0,
                    monthly_cost         = 0,
                    monthly_revenue      = 0,
                    quarterly_cost       = 0,
                    quarterly_revenue    = 0,
                    semi_annual_cost     = 0,
                    semi_annual_revenue  = 0,
                    yearly_cost          = 0,
                    yearly_revenue       = 0,
                    ext1                 = 0,
                    ext2                 = 0,
                    ext3                 = 0,
                    ext4                 = 0,
                    ext5                 = 0,
                    spread_value         = 0,
                    // create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    create_user_id = user_id,
                    update_user_id = user_id,
                };
                new crm_opportunity_dal().Insert(opportunity);
                new sys_oper_log_dal().Insert(new sys_oper_log()
                {
                    user_cate           = "用户",
                    user_id             = (int)user.id,
                    name                = user.name,
                    phone               = user.mobile == null ? "" : user.mobile,
                    oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                    oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.OPPORTUNITY,
                    oper_object_id      = opportunity.id,// 操作对象id
                    oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                    oper_description    = _dal.AddValue(opportunity),
                    remark              = "保存商机信息"
                });
                quote.opportunity_id = opportunity.id;
            }
            quote.is_primary_quote = 1;
            #endregion
            // 验证该商机下是否有报价,如果是第一个添加的报价,则设置成为主报价
            var quoteList = new crm_quote_dal().GetQuoteByWhere($" and opportunity_id = {quote.opportunity_id} ");
            if (quoteList != null && quoteList.Count > 0)
            {
                quote.is_primary_quote = null;
            }


            #region 1.保存报价
            quote.id               = _dal.GetNextIdCom();
            quote.create_time      = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote.update_time      = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote.create_user_id   = user_id;
            quote.update_user_id   = user_id;
            quote.payment_term_id  = quote.payment_term_id == 0 ? null : quote.payment_term_id;
            quote.payment_type_id  = quote.payment_type_id == 0 ? null : quote.payment_type_id;
            quote.shipping_type_id = quote.shipping_type_id == 0 ? null : quote.shipping_type_id;
            quote.tax_region_id    = quote.tax_region_id == 0 ? null : quote.tax_region_id;
            quote.quote_tmpl_id    = quote.quote_tmpl_id == 0 ? null : quote.quote_tmpl_id;
            quote.project_id       = quote.project_id == 0 ? null : quote.project_id;
            _dal.Insert(quote);
            new sys_oper_log_dal().Insert(new sys_oper_log()
            {
                user_cate           = "用户",
                user_id             = user.id,
                name                = user.name,
                phone               = user.mobile == null ? "" : user.mobile,
                oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.QUOTE,
                oper_object_id      = quote.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                oper_description    = _dal.AddValue(quote),
                remark              = "保存报价信息"
            });
            #endregion

            #region 2.保存通知
            #endregion

            #region 更新客户最后活动时间
            crm_account thisAccount = new CompanyBLL().GetCompany(quote.account_id);
            if (thisAccount != null)
            {
                thisAccount.last_activity_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); new CompanyBLL().EditAccount(thisAccount, user_id);
            }
            #endregion



            return(ERROR_CODE.SUCCESS);
        }
Example #13
0
        public ERROR_CODE Update(crm_quote quote, long user_id)
        {
            if (quote.account_id == 0 || string.IsNullOrEmpty(quote.name) || (quote.contact_id == 0 && quote.opportunity_id == 0))
            {
                return(ERROR_CODE.PARAMS_ERROR);
            }
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {
                return(ERROR_CODE.USER_NOT_FIND);
            }
            var old_quote = _dal.GetQuote(quote.id);

            //if (quote.opportunity_id == 0)  // 代表用户未选择商机,此时自动创建商机
            //{
            //    var opportunity = new crm_opportunity()
            //    {
            //        id = _dal.GetNextIdCom(),
            //        name = quote.name,
            //        resource_id = user_id,
            //        stage_id = (int)OPPORTUNITY_STAGE.NEW_CLUE,  // todo 取到商机阶段中的最小值
            //        status_id = (int)OPPORTUNITY_STATUS.ACTIVE,
            //        create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
            //        projected_close_date = quote.projected_close_date,
            //        use_quote = 1,
            //        one_time_cost = 0,
            //        one_time_revenue = 0,
            //        monthly_cost = 0,
            //        monthly_revenue = 0,
            //        quarterly_cost = 0,
            //        quarterly_revenue = 0,
            //        semi_annual_cost = 0,
            //        semi_annual_revenue = 0,
            //        yearly_cost = 0,
            //        yearly_revenue = 0,
            //        ext1 = 0,
            //        ext2 = 0,
            //        ext3 = 0,
            //        ext4 = 0,
            //        ext5 = 0,
            //        // create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
            //        update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
            //        create_user_id = user_id,
            //        update_user_id = user_id,

            //    };
            //    new crm_opportunity_dal().Insert(opportunity);
            //    new sys_oper_log_dal().Insert(new sys_oper_log()
            //    {
            //        user_cate = "用户",
            //        user_id = (int)user.id,
            //        name = user.name,
            //        phone = user.mobile == null ? "" : user.mobile,
            //        oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
            //        oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.OPPORTUNITY,
            //        oper_object_id = opportunity.id,// 操作对象id
            //        oper_type_id = (int)OPER_LOG_TYPE.ADD,
            //        oper_description = _dal.AddValue(opportunity),
            //        remark = "保存商机信息"
            //    });
            //    quote.opportunity_id = opportunity.id;
            //}
            quote.account_id       = old_quote.account_id;
            quote.oid              = old_quote.oid;
            quote.opportunity_id   = old_quote.opportunity_id;
            quote.payment_term_id  = quote.payment_term_id == 0 ? null : quote.payment_term_id;
            quote.payment_type_id  = quote.payment_type_id == 0 ? null : quote.payment_type_id;
            quote.shipping_type_id = quote.shipping_type_id == 0 ? null : quote.shipping_type_id;
            quote.tax_region_id    = quote.tax_region_id == 0 ? null : quote.tax_region_id;
            quote.quote_tmpl_id    = old_quote.quote_tmpl_id;
            quote.create_time      = old_quote.create_time;
            quote.create_user_id   = old_quote.create_user_id;
            quote.update_time      = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            quote.update_user_id   = user_id;
            _dal.Update(quote);
            new sys_oper_log_dal().Insert(new sys_oper_log()
            {
                user_cate           = "用户",
                user_id             = user.id,
                name                = user.name,
                phone               = user.mobile == null ? "" : user.mobile,
                oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.QUOTE,
                oper_object_id      = quote.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                oper_description    = _dal.CompareValue(old_quote, quote),
                remark              = "修改报价信息"
            });

            #region 更新客户最后活动时间
            crm_account thisAccount = new CompanyBLL().GetCompany(quote.account_id);
            if (thisAccount != null)
            {
                thisAccount.last_activity_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); new CompanyBLL().EditAccount(thisAccount, user_id);
            }
            #endregion
            return(ERROR_CODE.SUCCESS);
        }