When a person is committed to such workhouse under sentence that he stand committed to such workhouse until the fine and costs of prosecution assessed against him are paid, as provided in section eighteen, such person may pay in money, in whole or in part, to the board of workhouse directors, such fine and costs assessed against him, and such board shall receive and turn the same, quarterly, into the treasury of the county from which such person was committed: Provided, That such person was so committed for the violation of any law of the state; and when any person so committed for the violation of an ordinance of a municipal corporation shall make such payment to such board, it shall be its duty to receive and quarterly turn the same into the treasury of the municipal corporation from which such person was committed.