fix invoices query