The court may order a criminal action, whether prosecuted upon indictment or complaint, to be dismissed. The court may order dismissal of an action either on its own motion or upon motion of the prosecuting attorney and in furtherance of justice. If the court dismisses an action, the reasons for the dismissal must be set forth in the order and entered upon the minutes. The recommendations of the prosecuting officer in reference to dismissal, with reasons for dismissal, must be stated in writing and filed as a public record with the official files of the case.