Why is the closing balance of the ledger not matching with the pending invoices of the customer?

It might be possible that the advance payment is recorded from the customer ledger and it has not yet been settled against a pending sales document.

We suggest you to please settle pending invoice with advance payment.
Step 1: Go to “Sales” and click on “Record payment”.

Step 2: Select the option to “Settle from Advance Payments” and click on “Update the payment”.

Step 3: View the Ledger.