It is legal, but it must have been something the client or customer had notice of  or agreed to prior to it being billed. Any billing arrangement is legal--for example, flat fee, time-based, mileage-based, cost plus profit, etc., or some combination of the above--but it must be disclosed in advance.