Use SQL query to fetch lines to pay

issue3846
review5091003