Hi,
1. In your TN you have to add
where T1.DocStatus = 'O' and CardCode .. (and the rest that you have)
2. You need to create a query more or less like this:
SELECT 'True' from OCRD T0 Where T0.[CardCode] =$[OPOR.CardCode] and (SELECTCount(t1.docentry)FROM OPOR t1
where T1.CardCode=(Select T1.DocStatus = 'O' and Cardcode from OPOR )))< 6
3. In the approval you have to remove the always and select "When The Following Applies"
4. in the query name you have to select the query that you created in 2.
Hope it helps,
Augusto