Example #1
0
        //删除前的数据校验
        public ERROR_CODE Delete_Valid(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);
            }
            var data = _dal.FindById(id);

            if (data == null)
            {
                return(ERROR_CODE.ERROR);
            }
            if (data.is_system > 0)
            {
                return(ERROR_CODE.SYSTEM);
            }
            //d_general、ivt_product、crm_installed_product
            //有n个产品种类、n个产品、n个配置项
            int installed_product = new crm_installed_product_dal().ExecuteSQL($"select * from crm_installed_product where cate_id={id} and delete_time=0");
            int product           = new ivt_product_dal().ExecuteSQL($"select * from ivt_product where installed_product_cate_id={id} and delete_time=0");
            int product_cate      = _dal.ExecuteSQL($"select * from d_general where ext1='{id.ToString()}' and delete_time=0");

            if (installed_product > 0 || product > 0 || product_cate > 0)
            {
                returnvalue = @"有" + product_cate + "个产品种类、" + product + "个产品、" + installed_product + "个配置项关联此配置项类型。如果删除,则相关产品种类、产品、配置项上的配置项类型信息将会被清空,并且配置项上将会显示全部相关自定义字段。是否继续";
                return(ERROR_CODE.EXIST);
            }
            return(ERROR_CODE.SUCCESS);
        }
Example #2
0
        /// <summary>
        /// 获取配置项相关详情数据
        /// </summary>
        private void GetInsProDetail(HttpContext context)
        {
            var insProId = context.Request.QueryString["insProId"];

            if (!string.IsNullOrEmpty(insProId))
            {
                var insPr = new crm_installed_product_dal().FindNoDeleteById(long.Parse(insProId));
                if (insPr != null)
                {
                    string name        = "";
                    string contactName = "";
                    string contactId   = "";
                    string insTime     = "";
                    string insUser     = "";
                    string insWarnTime = "";  // 保修期
                    string vendorId    = "";
                    string vendorName  = "";
                    string insService  = "";
                    int    relateNum   = 0;    // 相关配置项
                    var    thisPro     = new ivt_product_dal().FindNoDeleteById(insPr.product_id);
                    if (thisPro != null)
                    {
                        name = thisPro.name;
                    }
                    if (insPr.contact_id != null)
                    {
                        var contact = new crm_contact_dal().FindNoDeleteById((long)insPr.contact_id);
                        if (contact != null)
                        {
                            contactId   = contact.id.ToString();
                            contactName = contact.name;
                        }
                    }
                    if (insPr.installed_resource_id != null)
                    {
                        var insRes = new sys_resource_dal().FindNoDeleteById((long)insPr.installed_resource_id);
                        if (insRes != null)
                        {
                            insUser = insRes.name;
                        }
                    }
                    if (insPr.vendor_account_id != null)
                    {
                        var thisVnedor = new CompanyBLL().GetCompany((long)insPr.vendor_account_id);
                        if (thisVnedor != null)
                        {
                            vendorId   = thisVnedor.id.ToString();
                            vendorName = thisVnedor.name;
                        }
                    }
                    insTime = Tools.Date.DateHelper.ConvertStringToDateTime(insPr.create_time).ToString("yyyy-MM-dd");



                    context.Response.Write(new Tools.Serialize().SerializeJson(new { id = insPr.id, name = name, contactId = contactId, contactName = contactName, insTime = insTime, insUser = insUser, insWarnTime = insWarnTime, vendorId = vendorId, vendorName = vendorName, insService = insService, relateNum = relateNum }));
                }
            }
        }
Example #3
0
        /// <summary>
        /// 获取成本已拣货的相关信息
        /// </summary>
        public void GetCostPicked(HttpContext context, long cost_id)
        {
            var pickedList = new ivt_product_dal().GetCostWareNoNeed(cost_id);

            if (pickedList != null && pickedList.Count > 0)
            {
                context.Response.Write(new Tools.Serialize().SerializeJson(pickedList));
            }
        }
Example #4
0
        /// <summary>
        /// 根据产品Id获取相应的库存信息
        /// </summary>
        public void GetPageWare(HttpContext context, long product_id)
        {
            var wareList = new ivt_product_dal().GetPageWareList(product_id);

            if (wareList != null && wareList.Count > 0)
            {
                context.Response.Write(new Tools.Serialize().SerializeJson(wareList));
            }
        }
Example #5
0
        /// <summary>
        /// 获取供应商相关信息
        /// </summary>
        public void GetVendorInfo(HttpContext context, long product_id)
        {
            var vendor = new ivt_product_dal().FindSignleBySql <ivt_product>($"SELECT a.name as name,v.vendor_product_no as vendor_product_no from crm_account a INNER join ivt_product_vendor v on a.id = v.vendor_account_id where product_id={product_id}");

            if (vendor != null)
            {
                context.Response.Write(new EMT.Tools.Serialize().SerializeJson(new { name = vendor.name, vendor_product_no = vendor.vendor_product_no }));
            }
        }
Example #6
0
        /// <summary>
        /// 获取到产品的信息并返回
        /// </summary>
        /// <param name="context"></param>
        /// <param name="product_id"></param>
        public void GetProduct(HttpContext context, long product_id)
        {
            var product = new ivt_product_dal().FindSignleBySql <ivt_product>($"select * from ivt_product where id= {product_id}");

            if (product != null)
            {
                context.Response.Write(new EMT.Tools.Serialize().SerializeJson(product));
            }
        }
Example #7
0
        /// <summary>
        /// 根据产品ID去获取到相对应的平均供应商成本和最高的供应商成本
        /// </summary>
        public void GetProData(HttpContext context, long product_id)
        {
            string sql     = $"SELECT AVG(vendor_cost) as unit_cost,MAX(vendor_cost) as unit_price from ivt_product_vendor where product_id = {product_id}";
            var    product = new ivt_product_dal().FindSignleBySql <ivt_product>(sql);

            if (product != null)
            {
                context.Response.Write(new EMT.Tools.Serialize().SerializeJson(new { avg = product.unit_cost, max = product.unit_price }));
            }
        }
Example #8
0
        /// <summary>
        /// 在报价子项中获取object_id,返回一个产品名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetProductName(int id)
        {
            var d = new ivt_product_dal().FindSignleBySql <ivt_product>($"select * from ivt_product where id={id} and delete_time=0");

            if (d != null)
            {
                return(d.name);
            }
            else
            {
                return(string.Empty);
            }
        }
Example #9
0
        /// <summary>
        /// 获取到页面参数
        /// </summary>
        /// <returns></returns>
        protected ConfigurationItemAddDto GetParam(string chooseProId)
        {
            var param = AssembleModel <ConfigurationItemAddDto>();

            if (contract != null)
            {
                param.account_id = contract.account_id;
            }
            if (thisProject != null)
            {
                param.account_id = thisProject.account_id;
            }

            param.installed_by    = (int)LoginUserId;
            param.location        = "";
            param.number_of_users = null;
            param.status          = 1;
            param.contact_id      = null;
            param.contract_id     = null;
            param.service_id      = null;
            var productId = Request.Form[chooseProId + "_product_id"];

            if (productId != "")
            {
                var thisProduct = new ivt_product_dal().FindNoDeleteById(long.Parse(productId));
                if (thisProduct != null)
                {
                    param.product_id = thisProduct.id;
                    if (product.installed_product_cate_id != null)
                    {
                        param.installed_product_cate_id = product.installed_product_cate_id;
                    }
                    else
                    {
                        var thisGeneral = new d_general_dal().GetGeneralById((long)product.cate_id);
                        if (thisGeneral != null)
                        {
                            param.installed_product_cate_id = int.Parse(thisGeneral.ext1);
                        }
                    }
                }
            }

            param.vendor_id        = null;
            param.contract_cost_id = conCost.id;
            // 是否经过合同审核
            param.terms  = new Terms();
            param.notice = new Notice();
            param.udf    = null;
            return(param);
        }
Example #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);
        }
Example #11
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);
        }
Example #12
0
        /// <summary>
        ///  //删除操作
        /// </summary>
        /// <param name="id"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public ERROR_CODE Delete(long id, long user_id)
        {
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {   // 查询不到用户,用户丢失
                return(ERROR_CODE.USER_NOT_FIND);
            }
            var data = _dal.FindById(id);

            if (data == null)
            {
                return(ERROR_CODE.ERROR);
            }
            var udf_data = _dal.FindById(Convert.ToInt64(data.ext1));
            crm_installed_product_dal dal1 = new crm_installed_product_dal();
            ivt_product_dal           dal2 = new ivt_product_dal();

            var installed_product = dal1.FindListBySql($"select * from crm_installed_product where cate_id={id} and delete_time=0");
            var product           = dal2.FindListBySql($"select * from ivt_product where installed_product_cate_id={id} and delete_time=0");
            var product_cate      = _dal.FindListBySql($"select * from d_general where ext1='{id.ToString()}' and delete_time=0");

            if (installed_product.Count > 0)
            {
                foreach (var i in installed_product)
                {
                    i.cate_id        = 0;
                    i.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    i.update_user_id = user_id;
                    if (dal1.Update(i))
                    {
                        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.CONFIGURAITEM, //
                            oper_object_id      = i.id,                                 // 操作对象id
                            oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                            oper_description    = _dal.AddValue(i),
                            remark              = "修改产品配置项"
                        };                                      // 创建日志
                        new sys_oper_log_dal().Insert(add_log); // 插入日志
                    }
                }
            }
            if (product.Count > 0)
            {
                foreach (var i in product)
                {
                    i.installed_product_cate_id = null;
                    i.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    i.update_user_id = user_id;
                    if (dal2.Update(i))
                    {
                        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      = i.id,                           // 操作对象id
                            oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                            oper_description    = _dal.AddValue(i),
                            remark              = "修改产品配置项"
                        };                                      // 创建日志
                        new sys_oper_log_dal().Insert(add_log); // 插入日志
                    }
                }
            }
            if (product_cate.Count > 0)
            {
                foreach (var i in product_cate)
                {
                    i.ext1           = null;
                    i.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    i.update_user_id = user_id;
                    if (_dal.Update(i))
                    {
                        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.General_Code, //
                            oper_object_id      = i.id,                                // 操作对象id
                            oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                            oper_description    = _dal.AddValue(i),
                            remark              = "修改配置项种类"
                        };                                      // 创建日志
                        new sys_oper_log_dal().Insert(add_log); // 插入日志
                    }
                }
            }

            long time = data.delete_time = udf_data.delete_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);

            data.delete_user_id = udf_data.delete_user_id = user.id;
            try
            {
                int n = new sys_udf_group_field_dal().ExecuteSQL($"update sys_udf_group_field set delete_time='{time}' and delete_user_id='{user.id}' where group_id={udf_data.id}");
            }
            catch {
                return(ERROR_CODE.ERROR);
            }
            if (!_dal.Update(data))
            {
                return(ERROR_CODE.ERROR);
            }
            if (!_dal.Update(udf_data))
            {
                return(ERROR_CODE.ERROR);
            }

            return(ERROR_CODE.SUCCESS);
        }