The defendant may plead as a counterclaim a cause of action against a plaintiff which tends to diminish or defeat the plaintiff’s recovery, provided the cause of action is embraced within the two subdivisions of section 501 of the Code of Civil Procedure here quoted:
“1. A cause of action, arising out of the contract or transaction set forth in the complaint as the foundation of the plaintiff’s claim, or connected with the subject of the action.
*7 “2. In an action on contract, any oilier cause of action on contract, existing at the commencement of the action.”
The counterclaims set up in the answer are not embraced within the second division, and the question is whether they are embraced within the first subdivision. The first subdivision provides that a cause of action in favor of a defendant, and against a plaintiff, may be pleaded as a counterclaim in case it arises (1) out of the contract set forth in the complaint; (2) out of the transaction set forth in the complaint; (3) or is connected with the subject of the action. The fact that the plaintiff in this action seeks to recover for the defendant’s conversion of money is not decisive of the question under consideration. The first subdivision does not limit the right of a defendant to interpose counterclaims to an action brought on a contract, but gives the right to interpose counterclaims in an action brought to recover damages1 for a tort, if the causes of actions set out in the complaint and in the answer arise out of the same contract or transaction, or relate to the same subject, tior does the subdivision provide that the cause of action set up as a counterclaim must arise out of a contract, but it authorizes the interposition of causes of action arising out of torts as counterclaims. The theory of the Code is to authorize all connected causes of action, whether arising out of contracts or torts, to be litigated in the same action. The cause of action set out in the complaint arises out of the alleged tortious breach, by the defendant, of the written contract of April 1, 1892, to wit, the collection and conversion to his own use of money which, by that contract, he had no right to collect, but which should have been paid by the purchasers of goods to the plaintiff. The plaintiff, as the foundation for his cause of action, alleges what he asserts is the legal effect of the contract of April 1, 1892, which he must introduce in evidence before he will be permitted to give evidence tending to show that the defendant wrongfully broke it All of the counterclaims arise out of the alleged nonperformance by the plaintiff of that contract, and, besides, they are connected with the subject of the action. In other words, the cause of action set out in the complaint and the causes of action set out in the answer as counterclaims arise out of the alleged breach of the same contract, and the causes of action set out in the answer may be pleaded as counterclaims under section 501. In Carpenter v. Insurance Co.,
“The counterclaim must have such a relation to, and connection with, the subject-oí the action, that it will be just and equitable that the controversy between the parties as to the matters alleged in the complaint and in the counterclaim should be settled in one action by one litigation, and that the claim o£ the one should be offset against, or applied upon, the claim of the other.”
Thomson v. Sanders,
