combining different charges to equal particular sum

I work in Accounts Receivable. Often we receive checks for particular payments that don’t reflect total amount due on the statement. The example below shows a payment for $7871.38. Which is the sum of the following charges, $123.66, $2.36, & $7745.36. Now the challenge is figuring out what combination of charges equal what the check was made out for. Right now we are using trial & error. Needless to say that is very time consuming. Is there an equation that exists that I could plug in all the numbers, do some math and figure this out more logically than trial an error?

Due $123.66;

Due $6658.02

Due $142.36

Due $2.36;

Due $1236.07

Due $7745.36;

Due $6554.00

Total Due:$22,461.83

Payment $7871.38