Payment term calculation wrong in sales invoice

I have created payment term template and applied to sales invoice. But it calculate due amount based on total invoice amount not the balance due. How to resolve this.

Payment Terms calculations are still correct in Sales Invoice.
you should not round-of the value of invoice portion (percentage) from 100.0/6.0 = 16.6666667 to 16.67
In System setting change the current float precision value to 7 and then try again to save the invoice.

it should be based on out standing amount not total invoice amount. because we have received advance payment.

in this case it would be 5380 / 6 = 896.67