I want to buy invoices. How do I account for the gain that I make from buying accounts receivable?

The gain counts as financial income. It must therefore be recorded in your income statement in a category 75 account (sundry operating incomes).