Dial plan for two lines - not finding out how

after installing asterix and freepbx, i did create 2 trunks, one for psnt, using a spa-3102 and another for voip, using voipcheap service.
My problem is how to define dialling rules, in other to place outgoing call thru pstn or voipcheap.
All outgoing calls are made dialling 9 first.
So, when i had only pstn, the pattern 9|. worked very well.
After adding voipcheap, i’m not finding out how to route calls.
My needs are:
local numbers: 8 digits
area codes: 2 or 3 digits.
dialling 9XXXXXXXX strips 9 and places pstn (with dial rule 9|.)
dialling 9031NNXXXXXXXX strips 9 and places pstn.
dialling 9005521XXXXXXXX strips 9005521 and places pstn
dialling 90055NNXXXXXXXX strips 9055XX and prepends 031NN to the dialing number and places pstn.
dialling 121XXXXXXXX strips 121 and places pstn
dialling 1NNXXXXXXXX replaces 1NN by 031NN and places pstn.
dialling 900NNXXXXXXX. strips 9 and places voipcheap.
I would like to get some help in order to build these rules. Is there any help i can get?
Thx in advance,