and (1 = 0 or b.profit_sales_user_id = #{scope.userId} or exists (select 1 from sys_user u inner join sys_dept dept on dept.dept_id = u.dept_id where u.user_id = b.profit_sales_user_id and u.del_flag = '0' and (dept.dept_id = #{scope.deptId} or find_in_set(#{scope.deptId}, dept.ancestors))) ) and 1 = 0 where b.status in ('CONFIRMED', 'PARTIAL_WRITTEN_OFF', 'WRITTEN_OFF') and b.generation_status = 'READY' and b.customer_id = #{query.customerId} and b.bill_no like concat('%', #{query.billNo}, '%') and b.ar_bill_id = #{query.arBillId} and b.status = #{query.status} and b.profit_sales_user_id = #{query.salesUserId} and b.bill_date >= #{query.beginBillDate} and b.bill_date <= #{query.endBillDate} b.profit_calc_status = 'READY' and b.total_amount is not null and ((b.profit_customer_area = #{shenzhenArea} and b.product_amount is not null) or (b.profit_customer_area = #{guangzhouArea} and b.redline_amount is not null)) case when b.profit_customer_area = #{shenzhenArea} then b.product_amount when b.profit_customer_area = #{guangzhouArea} then b.redline_amount else null end select b.ar_bill_id, b.bill_no, b.bill_name, b.bill_date, b.customer_code, b.customer_name, b.profit_customer_area as customer_area, b.profit_sales_user_name as sales_user_name, b.currency, b.status, b.total_amount as sales_amount, b.written_off_amount, b.unwritten_amount, case when then else null end as product_amount, case when then b.total_amount - () else null end as sales_gross_profit, case when and b.total_amount != 0 then round((b.total_amount - ()) * 100 / b.total_amount, 4) else null end as sales_gross_margin_rate, case when then 0 else 1 end as profit_incomplete from ar_bill b