When an order with a prepayment that was not paid previously, and then, the order not invoiced totally and then closed, and the amount of the prepayment was great than the invoiced value, that prepayment remains pending with the diference -> That prepayment should be also closed
Similarly, but when the prepayment was paid before, the rest of the amount to deduct should be available to be refunded
Regards
Manel