This article explains how you can mark an invoice that has been paid with the wrong reference code as paid.
1. Open Account transactions on the dashboard, select the account transaction that you want to allocate and click "Add to invoice":
2. Select the "Add to sales invoice" option. This takes you to the invoice list where you can select the invoice you want to allocate the payment to.