예제 #1
0
        /// <summary>
        ///  根据税区和条目税种计算税额
        /// </summary>
        private void GetTaxSum(HttpContext context, long tax_id, string accDedIds)
        {
            if (tax_id == 0 || string.IsNullOrEmpty(accDedIds))
            {
                context.Response.Write("0.00");
                return;
            }

            decimal totalMoney = 0;
            // 所有需要计算的条目的Id的集合
            var accDedIdList = accDedIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (accDedIdList != null && accDedIdList.Count() > 0)
            {
                var adDal = new crm_account_deduction_dal();
                foreach (var accDedId in accDedIdList)
                {
                    var accDedList = adDal.GetInvDedDtoList($" and id={accDedId}");
                    var thisAccDed = adDal.FindNoDeleteById(long.Parse(accDedId));
                    if (accDedList != null && accDedList.Count > 0)
                    {
                        var accDed = accDedList.FirstOrDefault(_ => _.id.ToString() == accDedId);
                        if (accDed.tax_category_id != null)
                        {
                            var thisTax = new d_tax_region_cate_dal().GetSingleTax(tax_id, (long)accDed.tax_category_id);
                            if (thisTax != null && thisAccDed.extended_price != null)
                            {
                                totalMoney += (decimal)(thisAccDed.extended_price * thisTax.total_effective_tax_rate);
                            }
                        }
                    }
                }
            }
            context.Response.Write(totalMoney.ToString("#0.00"));
        }
예제 #2
0
        /// <summary>
        /// 根据Ids撤销所有的审批
        /// </summary>
        public void UnPostAll(HttpContext context, string ids)
        {
            var accDedList = new crm_account_deduction_dal().GetAccDeds(ids);

            if (accDedList != null && accDedList.Count > 0)
            {
                var thisDicList = accDedList.GroupBy(_ => _.type_id).ToDictionary(_ => _.Key, _ => _.ToList());
                foreach (var thisDic in thisDicList)
                {
                    string thisIds = "";
                    foreach (var item in thisDic.Value)
                    {
                        thisIds += item.id.ToString() + ',';
                    }
                    if (string.IsNullOrEmpty(thisIds))
                    {
                        continue;
                    }
                    thisIds = thisIds.Substring(0, thisIds.Length - 1);
                    switch (thisDic.Key)
                    {
                    case (int)ACCOUNT_DEDUCTION_TYPE.CHARGE:
                        Revoke_CHARGES(context, thisIds);
                        break;

                    case (int)ACCOUNT_DEDUCTION_TYPE.MILESTONES:      // 里程碑
                        Revoke_Milestones(context, thisIds);
                        break;

                    case (int)ACCOUNT_DEDUCTION_TYPE.SUBSCRIPTIONS:
                        Revoke_Subscriptions(context, thisIds);
                        break;

                    case (int)ACCOUNT_DEDUCTION_TYPE.SERVICE:
                        Revoke_Recurring_Services(context, thisIds);
                        break;

                    case (int)ACCOUNT_DEDUCTION_TYPE.SERVICE_ADJUST:
                        // Revoke_Recurring_Services(context, thisIds);
                        break;

                    case (int)ACCOUNT_DEDUCTION_TYPE.INITIAL_COST:
                        // Revoke_Recurring_Services(context, thisIds);
                        break;

                    case (int)ACCOUNT_DEDUCTION_TYPE.LABOUR:
                        REVOKE_LABOUR(context, thisIds);
                        break;

                    case (int)ACCOUNT_DEDUCTION_TYPE.EXPENSES:
                        REVOKE_EXPENSE(context, thisIds);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 撤销费用审批
        /// </summary>
        public ERROR_CODE REVOKE_EXPENSE(long user_id, string ids, out string re)
        {
            re = "";
            if (!string.IsNullOrEmpty(ids))
            {
                var           idArr       = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var           cadDal      = new crm_account_deduction_dal();
                var           seDal       = new sdk_expense_dal();
                StringBuilder returnvalue = new StringBuilder();
                var           timeNow     = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                foreach (var accId in idArr)
                {
                    var thisCad = cadDal.FindNoDeleteById(long.Parse(accId));
                    if (thisCad != null)
                    {
                        if (thisCad.invoice_id != null)
                        {
                            var ci = new ctt_invoice_dal().FindNoDeleteById((long)thisCad.invoice_id);
                            if (ci != null && ci.is_voided != 1)
                            {
                                returnvalue.Append(accId + "条目已经生成发票(发票ID:" + thisCad.invoice_id + "),请先作废该发票\n");
                            }
                        }
                        else
                        {
                            #region  除条目信息
                            // var oldCad = cadDal.FindNoDeleteById(long.Parse(accId));
                            cadDal.SoftDelete(thisCad, user_id);
                            OperLogBLL.OperLogDelete <crm_account_deduction>(thisCad, thisCad.id, user_id, OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION, "删除审批并提交条目");
                            #endregion

                            #region 修改费用表
                            if (thisCad.object_id != null)
                            {
                                var se = seDal.FindNoDeleteById((long)thisCad.object_id);
                                if (se != null)
                                {
                                    var oldSe = seDal.FindNoDeleteById((long)thisCad.object_id);
                                    se.approve_and_post_date    = null;
                                    se.approve_and_post_user_id = null;
                                    se.amount_deduction         = null;
                                    se.update_time    = timeNow;
                                    se.update_user_id = user_id;
                                    seDal.Update(se);
                                    OperLogBLL.OperLogUpdate <sdk_expense>(se, oldSe, se.id, user_id, OPER_LOG_OBJ_CATE.SDK_EXPENSE, "修改费用");
                                }
                            }
                            #endregion
                        }
                    }
                }
            }
            return(ERROR_CODE.SUCCESS);
        }
예제 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var ids = Request.QueryString["account_ids"];
                if (!string.IsNullOrEmpty(ids))
                {
                    accDedIds = new List <string>();
                    var accountIDS = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var account_id in accountIDS)
                    {
                        var paramList = new crm_account_deduction_dal().GetInvDedDtoList(" and account_id=" + account_id + " and invoice_id is null");
                        // 区分为包括 采购订单和不包括采购订单
                        if (paramList != null && paramList.Count > 0)
                        {
                            accDedIds.AddRange(paramList.Select(_ => _.id.ToString()));

                            var noPurOrderList = paramList.Where(_ => string.IsNullOrEmpty(_.purchase_order_no
                                                                                           )).ToList(); // 代表无
                            var purchOrderList = paramList.Where(_ => !string.IsNullOrEmpty(_.purchase_order_no
                                                                                            )).ToList();
                            if (noPurOrderList != null && noPurOrderList.Count > 0)
                            {
                                invoiceNum += 1;
                            }
                            if (purchOrderList != null && purchOrderList.Count > 0)
                            {
                                var poDic = purchOrderList.GroupBy(_ => _.purchase_order_no).ToDictionary(_ => _.Key, _ => _.ToList());
                                if (poDic != null && poDic.Count > 0)
                                {
                                    invoiceNum += poDic.Count;
                                }
                            }
                        }
                    }
                }

                if (!IsPostBack)
                {
                    invoice_template_id.DataValueField = "id";
                    invoice_template_id.DataTextField  = "name";
                    invoice_template_id.DataSource     = dic.FirstOrDefault(_ => _.Key == "invoice_tmpl").Value;
                    invoice_template_id.DataBind();
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
예제 #5
0
        /// <summary>
        /// 根据条目ID 恢复相关预付费信息
        /// </summary>
        public bool RecoveryBlock(long cadId, long userId)
        {
            var thisCad = new crm_account_deduction_dal().FindNoDeleteById(cadId);

            if (thisCad != null && thisCad.contract_block_id != null)
            {
                var ccbDal    = new ctt_contract_block_dal();
                var thisBlock = ccbDal.FindNoDeleteById((long)thisCad.contract_block_id);
                if (thisBlock != null)
                {
                    var oldBlock = ccbDal.FindNoDeleteById((long)thisCad.contract_block_id);
                    thisBlock.is_billed      = 0;
                    thisBlock.status_id      = 1;
                    thisBlock.update_time    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    thisBlock.update_user_id = userId;
                    ccbDal.Update(thisBlock);
                    OperLogBLL.OperLogUpdate <ctt_contract_block>(thisBlock, oldBlock, thisBlock.id, userId, OPER_LOG_OBJ_CATE.CONTRACT_BLOCK, "修改合同预付");
                }
            }
            return(true);
        }
예제 #6
0
        /// <summary>
        /// 撤销工时审批
        /// </summary>
        public ERROR_CODE REVOKE_LABOUR(long user_id, string ids, out string re)
        {
            re = "";
            if (!string.IsNullOrEmpty(ids))
            {
                var           idArr       = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var           cadDal      = new crm_account_deduction_dal();
                var           sweDal      = new sdk_work_entry_dal();
                var           ccbDal      = new ctt_contract_block_dal();
                StringBuilder returnvalue = new StringBuilder();
                var           timeNow     = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                foreach (var accId in idArr)
                {
                    var thisCad = cadDal.FindNoDeleteById(long.Parse(accId));
                    if (thisCad != null)
                    {
                        if (thisCad.object_id != null)
                        {
                            var cadList = cadDal.GetListByObjectId((long)thisCad.object_id);

                            if (cadList != null && cadList.Count > 0)
                            {
                                foreach (var cad in cadList)
                                {
                                    if (cad.invoice_id != null)
                                    {
                                        var ci = new ctt_invoice_dal().FindNoDeleteById((long)thisCad.invoice_id);
                                        if (ci != null && ci.is_voided != 1)
                                        {
                                            returnvalue.Append(accId + "条目已经生成发票(发票ID:" + thisCad.invoice_id + "),请先作废该发票\n");
                                        }
                                    }
                                }
                            }


                            if (string.IsNullOrEmpty(returnvalue.ToString()))
                            {
                                if (cadList != null && cadList.Count > 0)
                                {
                                    cadList.ForEach(_ => {
                                        RecoveryBlock(_.id, user_id);
                                        cadDal.SoftDelete(_, user_id);
                                        OperLogBLL.OperLogDelete <crm_account_deduction>(_, _.id, user_id, OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION, "删除审批并提交条目");
                                    });
                                    var swe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                                    if (swe != null)
                                    {
                                        var oldSwe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                                        swe.approve_and_post_date    = null;
                                        swe.approve_and_post_user_id = null;
                                        swe.hours_billed_deduction   = null;
                                        swe.hours_rate_deduction     = null;
                                        swe.update_time    = timeNow;
                                        swe.update_user_id = user_id;
                                        sweDal.Update(swe);
                                        OperLogBLL.OperLogUpdate <sdk_work_entry>(swe, oldSwe, swe.id, user_id, OPER_LOG_OBJ_CATE.SDK_WORK_ENTRY, "修改工时");
                                    }
                                }
                            }
                            else
                            {
                                re = returnvalue.ToString();
                            }
                        }
                        #region  原来的撤销审批的相关逻辑(原来只针对单个条目进行删除,现在批量操作)
                        //if (thisCad.invoice_id!=null)
                        //{
                        //    var ci = new ctt_invoice_dal().FindNoDeleteById((long)thisCad.invoice_id);
                        //    if (ci!=null&&ci.is_voided != 1)
                        //    {
                        //        returnvalue.Append(accId + "条目已经生成发票(发票ID:" + thisCad.invoice_id + "),请先作废该发票\n");
                        //    }
                        //}
                        //else
                        //{
                        //    #region 删除条目信息
                        //    // var oldCad = cadDal.FindNoDeleteById(long.Parse(accId));
                        //    cadDal.SoftDelete(thisCad,user_id);
                        //    OperLogBLL.OperLogDelete<crm_account_deduction>(thisCad, thisCad.id, user_id, OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION, "删除审批并提交条目");
                        //    #endregion

                        //    #region 修改工时表
                        //    if (thisCad.object_id != null)
                        //    {
                        //        var swe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                        //        if (swe != null)
                        //        {
                        //            var oldSwe = sweDal.FindNoDeleteById((long)thisCad.object_id);
                        //            swe.approve_and_post_date = null;
                        //            swe.approve_and_post_user_id = null;
                        //            swe.hours_billed_deduction = null;
                        //            swe.hours_rate_deduction = null;
                        //            swe.update_time = timeNow;
                        //            swe.update_user_id = user_id;
                        //            sweDal.Update(swe);
                        //            OperLogBLL.OperLogUpdate<sdk_work_entry>(swe, oldSwe, swe.id, user_id, OPER_LOG_OBJ_CATE.SDK_WORK_ENTRY, "修改工时");
                        //        }
                        //    }
                        //    #endregion

                        //    #region 修改预付费信息
                        //    if (thisCad.contract_block_id != null)
                        //    {
                        //        var thisCcb = ccbDal.FindNoDeleteById((long)thisCad.contract_block_id);
                        //        if (thisCcb != null)
                        //        {
                        //            var oldCcb = ccbDal.FindNoDeleteById((long)thisCad.contract_block_id);
                        //            thisCcb.is_billed = 0;
                        //            thisCcb.status_id = 1;
                        //            thisCcb.update_time = timeNow;
                        //            thisCcb.update_user_id = user_id;
                        //            ccbDal.Update(thisCcb);
                        //            OperLogBLL.OperLogUpdate<ctt_contract_block>(thisCcb, oldCcb, thisCcb.id, user_id, OPER_LOG_OBJ_CATE.CONTRACT_BLOCK, "修改合同预付");
                        //        }

                        //    }
                        //    #endregion
                        //}
                        #endregion
                    }
                    else
                    {
                    }
                }
            }
            return(ERROR_CODE.SUCCESS);
        }
예제 #7
0
        /// <summary>
        /// /撤销成本审批
        /// </summary>
        /// <param name="user_id"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public ERROR_CODE Revoke_CHARGES(long user_id, string ids, out string re)
        {
            re = string.Empty;
            var user = UserInfoBLL.GetUserInfo(user_id);

            if (user == null)
            {   // 查询不到用户,用户丢失
                return(ERROR_CODE.USER_NOT_FIND);
            }
            var cadDal = new crm_account_deduction_dal();
            var sweDal = new sdk_work_entry_dal();
            crm_account_deduction  cad         = new crm_account_deduction();
            ctt_contract_block     ccb         = new ctt_contract_block();
            ctt_contract_cost      ccc         = new ctt_contract_cost();
            ctt_contract_cost_dal  ccc_dal     = new ctt_contract_cost_dal();
            ctt_contract_block_dal ccb_dal     = new ctt_contract_block_dal();
            StringBuilder          returnvalue = new StringBuilder();

            //该条目已经生成发票(发票ID:发票ID),请先作废该发票
            if (!string.IsNullOrEmpty(ids))
            {
                var timeNow = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                var idList  = ids.Split(',');
                foreach (var id in idList)
                {
                    var oldcad = cad = GetAccountDed(long.Parse(id));

                    if (cad != null)
                    {
                        if (cad.object_id != null)
                        {
                            var cadList = cadDal.GetListByObjectId((long)cad.object_id);
                            if (cadList != null && cadList.Count > 0)
                            {
                                foreach (var thisCad in cadList)
                                {
                                    if (thisCad.invoice_id != null)
                                    {
                                        var ci = new ctt_invoice_dal().FindNoDeleteById((long)thisCad.invoice_id);
                                        if (ci != null && ci.is_voided != 1)
                                        {
                                            returnvalue.Append(id + "条目已经生成发票(发票ID:" + thisCad.invoice_id + "),请先作废该发票\n");
                                        }
                                    }
                                }
                            }


                            if (string.IsNullOrEmpty(returnvalue.ToString()))
                            {
                                if (cadList != null && cadList.Count > 0)
                                {
                                    cadList.ForEach(_ => {
                                        RecoveryBlock(_.id, user_id);
                                        cadDal.SoftDelete(_, user_id);
                                        OperLogBLL.OperLogDelete <crm_account_deduction>(_, _.id, user_id, OPER_LOG_OBJ_CATE.ACCOUNT_DEDUCTION, "删除审批并提交条目");
                                    });
                                    var oldccc = ccc = ccc_dal.FindNoDeleteById((long)cad.object_id);
                                    if (ccc != null)
                                    {
                                        // var oldSwe = sweDal.FindNoDeleteById((long)cad.object_id);
                                        ccc.update_time    = timeNow;
                                        ccc.update_user_id = user.id;
                                        ccc.bill_status    = 0;
                                        ccc.extended_price = ccc.unit_price * ccc.quantity;
                                        ccc_dal.Update(ccc);
                                        OperLogBLL.OperLogUpdate <ctt_contract_cost>(ccc, oldccc, ccc.id, user_id, OPER_LOG_OBJ_CATE.CONTRACT_COST, "修改合同成本");
                                    }
                                }
                            }
                            else
                            {
                                re = returnvalue.ToString();
                            }
                        }
                    }


                    #region 原有的撤销成本审批相关逻辑
                    //if (cad.invoice_id != null)
                    //{
                    //    var ci = new ctt_invoice_dal().FindNoDeleteById((long)cad.invoice_id);
                    //    if (ci.is_voided != 1)
                    //    {
                    //        returnvalue.Append(id + "条目已经生成发票(发票ID:" + cad.invoice_id + "),请先作废该发票\n");
                    //    }
                    //}
                    //else
                    //{
                    //    cad.delete_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    //    cad.delete_user_id = user.id;
                    //    var add1_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.ACCOUNT_DEDUCTION,
                    //        oper_object_id = cad.id,// 操作对象id
                    //        oper_type_id = (int)OPER_LOG_TYPE.DELETE,
                    //        oper_description = cad_dal.CompareValue(oldcad, cad),
                    //        remark = "删除审批并提交"
                    //    };          // 创建日志
                    //    new sys_oper_log_dal().Insert(add1_log);       // 插入日志
                    //    if (!cad_dal.Update(cad))
                    //    {
                    //        return ERROR_CODE.ERROR;
                    //    }
                    //    //合同成本
                    //    var oldccc = ccc = ccc_dal.FindSignleBySql<ctt_contract_cost>($"select * from ctt_contract_cost where id={cad.object_id} and delete_time=0");
                    //    if (ccc != null)
                    //    {
                    //        ccc.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    //        ccc.update_user_id = user.id;
                    //        ccc.bill_status = 0;
                    //        ccc.extended_price = ccc.unit_price * ccc.quantity;
                    //        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.CONTRACT_COST,
                    //            oper_object_id = ccc.id,// 操作对象id
                    //            oper_type_id = (int)OPER_LOG_TYPE.UPDATE,
                    //            oper_description = cad_dal.CompareValue(oldccc, ccc),
                    //            remark = "修改合同成本"
                    //        };          // 创建日志
                    //        new sys_oper_log_dal().Insert(add_log);       // 插入日志
                    //        if (!ccc_dal.Update(ccc))
                    //        {
                    //            return ERROR_CODE.ERROR;
                    //        }
                    //        if (cad.contract_block_id != null)
                    //        {
                    //            //合同预付
                    //            var oldccb = ccb = ccb_dal.FindSignleBySql<ctt_contract_block>($" select * from ctt_contract_block where id={cad.contract_block_id} and delete_time=0");
                    //            if (ccb != null)
                    //            {
                    //                ccb.is_billed = 0;
                    //                ccb.status_id = 1;
                    //                ccb.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
                    //                ccb.update_user_id = user.id;
                    //                var add3_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.CONTRACT_BLOCK,
                    //                    oper_object_id = ccc.id,// 操作对象id
                    //                    oper_type_id = (int)OPER_LOG_TYPE.UPDATE,
                    //                    oper_description = cad_dal.CompareValue(oldccb, ccb),
                    //                    remark = "修改合同预付"
                    //                };          // 创建日志
                    //                new sys_oper_log_dal().Insert(add3_log);       // 插入日志
                    //                if (!ccb_dal.Update(ccb))
                    //                {
                    //                    return ERROR_CODE.ERROR;
                    //                }
                    //            }
                    //        }
                    //    }

                    //}
                    #endregion
                }
            }
            if (!string.IsNullOrEmpty(returnvalue.ToString()))
            {
                re = returnvalue.ToString();
                return(ERROR_CODE.EXIST);
            }
            return(ERROR_CODE.SUCCESS);
        }
예제 #8
0
        /// <summary>
        /// 根据第一页的查询条件,显示第二页的内容
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbnext_Click(object sender, EventArgs e)
        {
            var accountId           = account_idHidden.Value;
            var showChildAcc        = ckchildAccounts.Checked;
            var showserviceContract = ckserviceContract.Checked;
            var showFixPrice        = ckFixPrice.Checked;
            var showPriceZero       = ckPirceZero.Checked;
            var project_id          = project_idHidden.Value;
            var department          = department_id.SelectedValue;
            var startDate           = itemStartDate.Value;
            var endDate             = itemEndDate.Value;
            var contractType        = contract_type_id.SelectedValue;
            var contractCate        = contract_cate_id.SelectedValue;
            var project_item        = projectItem.SelectedValue;
            var type   = thisItemTypeId.Value; // 条目类型-多选--toTest
            var cadDal = new crm_account_deduction_dal();

            var chooseAccount = new CompanyBLL().GetCompany(long.Parse(accountId));

            if (chooseAccount == null)
            {
                return;
            }

            //accDedList = cadDal.GetAccDed(chooseAccount.id);  // 将要在页面上显示的条目
            //if (accDedList == null)
            //    accDedList = new List<crm_account_deduction>();

            StringBuilder sqlWhere = new StringBuilder();

            if (!string.IsNullOrEmpty(project_id))
            {
                sqlWhere.Append($" and project_id={project_id}");
            }
            if ((!string.IsNullOrEmpty(department)) && (department != "0"))
            {
                sqlWhere.Append($" and department_id={department}");
            }
            if (!string.IsNullOrEmpty(startDate))
            {
                sqlWhere.Append($" and item_date>='{startDate}'");
            }
            if (!string.IsNullOrEmpty(endDate))
            {
                sqlWhere.Append($" and item_date<='{endDate}'");
            }
            if (!string.IsNullOrEmpty(type))
            {
                sqlWhere.Append($" and item_type in ({type}) ");
            }
            if ((!string.IsNullOrEmpty(contractType)) && contractType != "0")
            {
                sqlWhere.Append($" and contract_type_id={contractType}");
            }
            if ((!string.IsNullOrEmpty(contractCate)) && contractCate != "0")
            {
                sqlWhere.Append($" and contract_cate_id={contractCate}");
            }
            if (project_item == "onlyProject")
            {
                sqlWhere.Append($" and project_id is not null");
            }
            if (project_item == "onlyNoProject")
            {
                sqlWhere.Append($" and project_id is null");
            }

            // todo 其余三个Show的过滤

            if (!showserviceContract)
            {
                sqlWhere.Append($" and (item_type in(1318,1319) and contract_type_id not in(1199) or  item_type not in(1318,1319) )");
            }
            if (!showFixPrice)
            {
                sqlWhere.Append($" and  (item_type in(1318,1319) and contract_type_id not in(1201) or  item_type not in(1318,1319) )");
            }
            if (showPriceZero)
            {
                sqlWhere.Append($" and dollars <>0");
            }

            List <InvoiceDeductionDto> deeList = null;
            var sortOrder = Request.QueryString["sortOrder"];

            switch (sortOrder)
            {
            case "1":        // 客户
                deeList = cadDal.GetInvDedDtoList(sqlWhere.ToString() + " and account_id=" + chooseAccount.id.ToString() + " and    invoice_id is null and purchase_order_no is null");
                break;

            case "2":        // ticket
                deeList = cadDal.GetInvDedDtoList(sqlWhere.ToString() + " and account_id=" + chooseAccount.id.ToString() + " and    invoice_id is null and purchase_order_no is null AND project_id is null");
                break;

            case "3":        // 项目
                var thisProject = Request.QueryString["thisProject"];
                deeList = cadDal.GetInvDedDtoList(sqlWhere.ToString() + " and account_id=" + chooseAccount.id.ToString() + " and    invoice_id is null and purchase_order_no is null AND project_id = " + thisProject);
                break;

            case "4":        // 采购订单
                var thisPurOrder = Request.QueryString["thisPurOrder"];
                if (!string.IsNullOrEmpty(thisPurOrder))
                {
                    thisPurOrder = thisPurOrder.Substring(5, thisPurOrder.Length - 5);
                    deeList      = cadDal.GetInvDedDtoList(sqlWhere.ToString() + " and account_id=" + chooseAccount.id.ToString() + " and    invoice_id is null and purchase_order_no =" + thisPurOrder);
                }
                break;

            default:
                break;
            }


            #region  加上子公司的条目
            if (showChildAcc) // 代表用户选中展示子客户条目
            {
                var childAccList = new crm_account_dal().GetSubsidiariesById(chooseAccount.id);
                if (childAccList != null && childAccList.Count > 0)
                {
                    foreach (var childAcc in childAccList)
                    {
                        var childAccDedList = cadDal.GetInvDedDtoList(sqlWhere.ToString() + " and account_id=" + childAcc.id);  //+ " and bill_account_id <>"+ chooseAccount.id
                        if (childAccDedList != null && childAccDedList.Count > 0)
                        {
                            childAccDedList.ForEach(_ => {
                                _.isSub = "1";
                            });
                            deeList.AddRange(childAccDedList); // 循环添加子客户条目
                        }
                    }
                }
            }
            StringBuilder dedHtml = new StringBuilder();
            if (deeList != null && deeList.Count > 0)
            {
                deeList = deeList.Distinct().ToList();
                foreach (var invDedDto in deeList)
                {
                    // 1 代表是不可选的子客户
                    // 2 待定 可选但是默认不选
                    var ischeck = invDedDto.isSub == "1" ? "disabled" : invDedDto.isSub == "2"?"": "checked";

                    var imgSrc = invDedDto.type_icon;         // 根据类型选择图片位置

                    var itemName       = invDedDto.item_name; // todo 部分有下标名
                    var rate           = invDedDto.rate == null ? "" : ((decimal)invDedDto.rate).ToString("#0.00");
                    var quantity       = invDedDto.quantity == null ? "" : ((decimal)invDedDto.quantity).ToString("#0.00");
                    var dollars        = invDedDto.dollars == null ? "" : ((decimal)invDedDto.dollars).ToString("#0.00");
                    var bill_to_parent = string.IsNullOrEmpty(invDedDto.bill_to_parent) ? "" : "√";
                    var bill_to_sub    = string.IsNullOrEmpty(invDedDto.bill_to_sub) ? "" : "√";

                    dedHtml.Append($"<tr><td align='center' style='width: 20px;'><input type='checkbox' class='thisDedCheck' style='margin: 0;' value='{invDedDto.id}' {ischeck}></td><td width='20px' align='center'><img src='{imgSrc}' /></td> <td width='20' align='center'>{invDedDto.item_date}</td><td>{itemName}</td><td>{invDedDto.account_name}</td><td>{invDedDto.contract_name}</td><td>{invDedDto.department_name}</td><td>{invDedDto.cost_code_name}</td><td>{invDedDto.resource_name}</td><td>{invDedDto.role_name}</td><td>{invDedDto.project_name}</td><td>{rate}</td><td>{quantity}</td><td>{dollars}</td><td>{invDedDto.tax_category_name}</td><td>{bill_to_parent}</td><td>{bill_to_sub}</td></tr>");
                    //showAccountDed
                }
                //ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script></script>");
            }


            ClientScript.RegisterStartupScript(this.GetType(), "页面跳转", "<script>document.getElementById('showAccountDed').innerHTML=\"" + dedHtml.ToString() + "\";document.getElementsByClassName('Workspace1')[0].style.display = 'none';document.getElementsByClassName('Workspace2')[0].style.display = '';document.getElementById('date_range_from').value=\"" + startDate + "\";document.getElementById('date_range_to').value=\"" + endDate + "\";</script>");

            #endregion
        }