move calculate php to the right place