示例#1
0
        /// <summary>
        /// 根据系统设置获取自己可以审批的员工信息
        /// </summary>
        public List <sys_resource> GetAgentUser(long userId, out bool isAgent)
        {
            isAgent = false;
            List <sys_resource> resList = null;
            var entryProxySet           = new SysSettingBLL().GetValueById(SysSettingEnum.SDK_ENTRY_PROXY);

            if (entryProxySet == ((int)DicEnum.PROXY_TIME_ENTRY.DISABLED).ToString())
            {
                isAgent = false;
            }
            else
            {
                isAgent = true;
                if (entryProxySet == ((int)DicEnum.PROXY_TIME_ENTRY.ENABLED_TIMESHEET_APPROVERS).ToString())
                {
                    resList = new sys_resource_dal().FindListBySql($"select sr.* from sys_resource_approver srp INNER JOIN sys_resource sr on srp.resource_id = sr.id where srp.approve_type_id=673 and srp.approver_resource_id={userId} union SELECT * from sys_resource where id = {userId} and delete_time = 0 ");
                }
                else if (entryProxySet == ((int)DicEnum.PROXY_TIME_ENTRY.ENABLED_TIMESHEET_APPROVERS_ADMINISTRATORS).ToString())
                {
                    var powerRes = new sys_resource_dal().FindListBySql("select *  from sys_resource where  security_level_id=1");
                    if (powerRes != null && powerRes.Count > 0)
                    {
                        if (powerRes.Any(_ => _.id == userId))
                        {
                            return(new sys_resource_dal().GetSourceList());
                        }
                    }
                    resList = new sys_resource_dal().FindListBySql($"select sr.* from sys_resource_approver srp INNER JOIN sys_resource sr on srp.resource_id = sr.id where srp.approve_type_id=673 and srp.approver_resource_id={userId} union SELECT * from sys_resource where id = {userId} and delete_time = 0 ");
                }
            }
            return(resList);
        }
示例#2
0
文件: ProductBLL.cs 项目: evelh/Done
        /// <summary>
        /// 获取产品的成本(根据系统设置相关)
        /// </summary>
        /// <param name="ipId"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public decimal?GetProCost(long ipId, long user_id)
        {
            decimal?thisCost = null;
            var     thisPro  = _dal.FindNoDeleteById(ipId);

            if (thisPro != null)
            {
                if (thisPro.unit_cost != null)
                {
                    thisCost = (decimal)thisPro.unit_cost;
                }
                var onHandNum = _dal.GetProOnHand(thisPro.id);
                if (onHandNum != null && (Convert.ToInt32(onHandNum)) > 0)  // 可用数要大于0
                {
                    var thisSysSet = new SysSettingBLL().GetSetById(DTO.SysSettingEnum.INVENTORY_ACCOUNTING_METHOD);
                    if (thisSysSet != null)
                    {
                        var iopDal = new ivt_order_product_dal();
                        if (thisSysSet.setting_value == ((int)INVENTORY_ACCOUNTING_METHOD.AVERAGE_COST).ToString())
                        {
                            var avgCosr = iopDal.GetAvgByPro(thisPro.id);
                            if (avgCosr != null)
                            {
                                thisCost = (decimal)avgCosr;
                            }
                        }
                        else if (thisSysSet.setting_value == ((int)INVENTORY_ACCOUNTING_METHOD.FIFO).ToString())
                        {
                            var firCosr = iopDal.GetFirstByPro(thisPro.id);
                            if (firCosr != null)
                            {
                                thisCost = (decimal)firCosr;
                            }
                        }
                        else if (thisSysSet.setting_value == ((int)INVENTORY_ACCOUNTING_METHOD.LIFO).ToString())
                        {
                            var lasCosr = iopDal.GetLastByPro(thisPro.id);
                            if (lasCosr != null)
                            {
                                thisCost = (decimal)lasCosr;
                            }
                        }
                    }
                }
                else
                {
                    return(thisCost);
                }
            }

            return(thisCost);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
0
文件: QuoteBLL.cs 项目: evelh/Done
        /// <summary>
        /// 丢失报价
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="quoteId"></param>
        /// <param name="reasonType">丢失原因类型</param>
        /// <param name="reasonDetail">丢失原因详情</param>
        /// <returns></returns>
        public string LossQuote(long userId, long quoteId, int reasonType, string reasonDetail)
        {
            DicEnum.SYS_CLOSE_OPPORTUNITY needReasonType;
            var type  = new SysSettingBLL().GetValueById(SysSettingEnum.CRM_OPPORTUNITY_LOSS_REASON);
            int value = 0;

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

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

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

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

            new sys_oper_log_dal().Insert(new sys_oper_log()
            {
                user_cate           = "用户",
                user_id             = userId,
                name                = user.name,
                phone               = user.mobile == null ? "" : user.mobile,
                oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.OPPORTUNITY,
                oper_object_id      = oppor.id,// 操作对象id
                oper_type_id        = (int)OPER_LOG_TYPE.UPDATE,
                oper_description    = opporDal.CompareValue(oldOppor, oppor),
                remark              = "丢失报价"
            });

            // 新增通知信息
            var notify_email_dal = new com_notify_email_dal();
            var notify_email     = new com_notify_email()
            {
                id              = notify_email_dal.GetNextIdCom(),
                cate_id         = (int)NOTIFY_CATE.CRM,
                event_id        = 1,          // TODO:
                to_email        = "",         // TODO:
                notify_tmpl_id  = 1,          // TODO:
                from_email      = user.email, // todo
                from_email_name = user.name,  // todo
                subject         = "",         // TODO:
                body_text       = "",         // TODO:
                is_html_format  = 0,          // 内容是否是html格式,0纯文本 1html
                create_user_id  = user.id,
                update_user_id  = user.id,
                create_time     = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                update_time     = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
            };

            notify_email_dal.Insert(notify_email);
            new sys_oper_log_dal().Insert(new sys_oper_log()
            {
                user_cate           = "用户",
                user_id             = user.id,
                name                = user.name,
                phone               = user.mobile == null ? "" : user.mobile,
                oper_time           = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now),
                oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.OPPORTUNITY,
                oper_object_id      = notify_email.id,
                oper_type_id        = (int)OPER_LOG_TYPE.ADD,
                oper_description    = notify_email_dal.AddValue(notify_email),
                remark              = "新增通知",
            });  // 插入日志

            return("");
        }