Hey,
I am Abraham, Senior VoIP engineer and consultant with robust and extensive Asterisk development experiences and deep knowledge of integration with many CRM solution, already done hundreds of complicated custom dialplans for different causes.
I can not only give you what you want, but even better, fully automatic API that works in real time instead of reading from DB, but that's your decision to make.
The call API I've developed myself and it's ready to be used, for DB I can also develop the dialplan for that too.
Please read more on my profile and contact me to discuss further.
Kindest Regards.