print "Connecting to database ..."; dbConnect("billing"); print "connected\n\n"; print "Selecting records for first pass run"; $sql="SELECT id,accountcode,duration,billsec,direction,lcr_carrier,lcr_rate,callee_id_number FROM cdr WHERE lcr_carrier!='' and billsec!='0' and rated='N' limit $maxq"; $result=mysql_query($sql); print "id,accountcode,billsec,carrrier,rate, rated amount"; while ($r=mysql_fetch_array($result)) { $id=$r[id]; print $r[id] . " " . $r[accountcode] . " " . $r[billsec] . " " . $r[lcr_carrier] . " " . $r[lcr_rate] . " Calculate total : "; //nominalize durations $costrate=$r[billsec]/60*$r[lcr_rate]; print "$costrate\n"; $updatesql="update cdr set callcost='$costrate',rated='C' where id='$id'"; //print "$updatesql"; $updateres=mysql_query($updatesql); } print "\n\n Stage 1 Complete (estimated costing), enterning stage 2\\n"; //build rate/overide tables $sql="SELECT dialingaccess.CustomerID, dialingaccess.rulename, dialingaccess.overriderate, localdialing.rulename, localdialing.npanxx, localdialing.city FROM dialingaccess, localdialing WHERE ( dialingaccess.rulename = localdialing.rulename)"; //CustomerID rulename overriderate rulename npanxx city $result=mysql_query($sql); while ($r=mysql_fetch_assoc($result)) { $rate_table[$r[CustomerID]][$r[npanxx]][rate]=$r[overriderate]; $rate_table[$r[CustomerID]][$r[npanxx]][city]=$r[city]; } //print_r($rate_table); $sql="SELECT id,accountcode,duration,billsec,direction,lcr_carrier,lcr_rate,callee_id_number FROM cdr WHERE rated='C' limit $maxq"; $result=mysql_query($sql); while ($r=mysql_fetch_array($result)) { $id=$r[id]; //set min billing seconds 60min 90nex min, per second after $billsec=0; //rest bill sec $billsec=$r[billsec]; $finalprice=0; $callrate=0; if ($r[billsec]<60) {$billsec=60;} if ($r[billsec]>60 && $r[billsec] < 90) {$billsec=90;} //determin if call is local or international $dst=$r[callee_id_number]; $dstlookup=substr("$dst", 0, 4); //check see if destination is nullable //$sql2="SELECT if($rate_table[$r[accountcode]][$dstlookup][rate] !='') { $callrate=$rate_table[$r[accountcode]][$dstlookup][rate]; print "match \n"; } print "$dst - $dstlookup - $billsec - " . $r[accountcode] . " : charge $finalprice\n"; } ?>