The script works as it expected except in callcdr  which is supposed to update a table in database with the called number of the calls with duration less than 120 second  the finished calls of calls of course  but it update the table the table once the call starts and of course its duration is less than 120 second at the start time