As I wrote above I like the idea but I am not comfortable with this particular implementation just yet.
Just out of curiosity are Customer Receipts also automatically allocated in your implementation?
The attached script works for me after changing SQL and creating an $Allocated flag to manage display of "Allocate this payment" hyperlink.
The only lines that were changed from GIT are 527, 529, 532, 537, 695-697.
Can somebody verify my work? Likely a better solution...