All fines and forfeitures for the violation of ordinances and all moneys collected for licenses or otherwise shall be paid into the treasury of the city or town at such times and in such manner as may be prescribed by ordinance, or, if there is no ordinance referring to the case, it shall be paid to the treasurer at once.