Exemple #1
0
        protected decimal befotMoveNum;  // 转移前的数量 (余额)
        protected void Page_Load(object sender, EventArgs e)
        {
            long id = 0;

            if (!string.IsNullOrEmpty(Request.QueryString["id"]) && long.TryParse(Request.QueryString["id"], out id))
            {
                deduction = invBll.GetDeduction(id);
            }

            if (deduction != null)
            {
                vItem = new DAL.v_widget_posted_item_dal().FindById(deduction.id);
                if (deduction.contract_id != null)
                {
                    contract = new ContractBLL().GetContract((long)deduction.contract_id);
                }
                if (deduction.contract_block_id != null)
                {
                    block = new ContractBlockBLL().GetBlockById((long)deduction.contract_block_id);
                }
                if (block != null)
                {
                    contract = new ContractBLL().GetContract(block.contract_id);
                }

                string contractTypeSql = string.Empty;  // 合同类型过滤
                if (contract?.type_id == (int)EMT.DoneNOW.DTO.DicEnum.CONTRACT_TYPE.RETAINER)
                {
                    contractTypeSql = $" and cc.type_id = {(int)EMT.DoneNOW.DTO.DicEnum.CONTRACT_TYPE.RETAINER} ";
                    dedNum          = deduction.extended_price;

                    if (block != null)
                    {
                        befotMoveNum = Convert.ToDecimal(new DAL.crm_account_dal().GetSingle($"SELECT round(b.rate*b.quantity - ifnull((SELECT sum(extended_price)FROM crm_account_deduction WHERE contract_block_id = b.id	AND delete_time = 0	),0),2) AS rate FROM ctt_contract_block b WHERE b.delete_time = 0 and b.id = {block.id} "));
                    }
                }
                else if (contract?.type_id == (int)EMT.DoneNOW.DTO.DicEnum.CONTRACT_TYPE.BLOCK_HOURS)
                {
                    contractTypeSql = $" and cc.type_id = {(int)EMT.DoneNOW.DTO.DicEnum.CONTRACT_TYPE.BLOCK_HOURS} ";
                    dedNum          = deduction.quantity;
                    if (block != null)
                    {
                        befotMoveNum = Convert.ToDecimal(new DAL.crm_account_dal().GetSingle($"SELECT sum(round(b.rate - ifnull((SELECT sum(extended_price)FROM crm_account_deduction WHERE contract_block_id = b.id AND delete_time = 0 ),0),2)) AS rate FROM ctt_contract_block b WHERE b.delete_time = 0 and b.id ={block.id} "));
                    }
                }
                var dtoList = new CompanyBLL().GetBySql <MoveDeductionDto>($@"SELECT ccb.id,ccb.start_date,ccb.end_date,cc.id as contract_id,cc.name as contract_name, ca.id as account_id, ca.name as account_name,ccb.status_id,
case cc.type_id 
when {(int)EMT.DoneNOW.DTO.DicEnum.CONTRACT_TYPE.RETAINER} 
then round(ccb.rate*ccb.quantity - ifnull((SELECT sum(extended_price)FROM crm_account_deduction WHERE contract_block_id = ccb.id	AND delete_time = 0	),0),2) 
when  {(int)EMT.DoneNOW.DTO.DicEnum.CONTRACT_TYPE.BLOCK_HOURS} 
then round(ccb.rate - ifnull((SELECT sum(extended_price)FROM crm_account_deduction WHERE contract_block_id = ccb.id AND delete_time = 0 ),0),2)
else 0 end as balance from ctt_contract_block ccb 
INNER JOIN  ctt_contract cc on ccb.contract_id = cc.id
INNER JOIN crm_account ca on cc.account_id = ca.id
where ccb.delete_time =0 and cc.delete_time =0 and (cc.account_id = {deduction.account_id} or ca.parent_id = {deduction.account_id}) {contractTypeSql} and (round(ccb.rate*ccb.quantity - ifnull((SELECT sum(extended_price)FROM crm_account_deduction WHERE contract_block_id = ccb.id	AND delete_time = 0	),0),2) >0 or round(ccb.rate - ifnull((SELECT sum(extended_price)FROM crm_account_deduction WHERE contract_block_id = ccb.id AND delete_time = 0 ),0),2)>0)"    );
                if (dtoList != null && dtoList.Count > 0)
                {
                    dtoList = dtoList.OrderBy(_ => _.start_date).ToList();
                    dic     = dtoList.GroupBy(_ => _.contract_id).ToDictionary(_ => _.Key, _ => _.ToList());
                }
            }
            else
            {
                Response.Write("<script>alert('未获取到相关条目!');window.close();</script>");
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            long id = 0;

            if (!string.IsNullOrEmpty(Request.QueryString["id"]) && long.TryParse(Request.QueryString["id"], out id))
            {
                deduction = invBll.GetDeduction(id);
            }

            //if (deduction == null)
            //{
            //    Response.Write("<script>alert('未获取到相关条目');window.close();</script>");
            //}
            long blockId = 0;

            if (!string.IsNullOrEmpty(Request.QueryString["blockId"]) && long.TryParse(Request.QueryString["blockId"], out blockId))
            {
                block = new ContractBlockBLL().GetBlockById(blockId);
            }

            if (deduction != null)
            {
                vItem   = new DAL.v_widget_posted_item_dal().FindById(deduction.id);
                rate    = vItem?.rate;
                account = new CompanyBLL().GetCompany(deduction.account_id);
                if (deduction.contract_id != null)
                {
                    contract = new ContractBLL().GetContract((long)deduction.contract_id);
                }
                if (deduction.task_id != null)
                {
                    task = new TicketBLL().GetTask((long)deduction.task_id);
                }
                labour = new WorkEntryBLL().GetEntryById((long)deduction.object_id);
                if (vItem?.tax_category_id != null && vItem?.tax_region_id != null)
                {
                    var thisTax = new DAL.d_tax_region_cate_dal().GetSingleTax((long)vItem?.tax_region_id, (long)vItem?.tax_category_id);
                    taxRate = thisTax?.total_effective_tax_rate;
                }
                if (vItem?.resource_id != null)
                {
                    resource = new UserResourceBLL().GetResourceById((long)vItem.resource_id);
                }
                if (deduction.contract_block_id != null)
                {
                    dedBlock = new ContractBlockBLL().GetBlockById((long)deduction.contract_block_id);
                }
            }
            if (block != null)
            {
                contract = new ContractBLL().GetContract(block.contract_id);
                if (contract != null)
                {
                    account      = new CompanyBLL().GetCompany(contract.account_id);
                    contractType = new GeneralBLL().GetSingleGeneral(contract.type_id);
                }
            }
            if (block == null && deduction == null)
            {
                Response.Write("<script>alert('未获取到相关条目');window.close();</script>");
            }
        }