Calculate total amount and remaining amount