[Astpp-commit] SF.net SVN: astpp: [2171] trunk
Brought to you by:
darrenkw
From: <dar...@us...> - 2007-12-29 04:58:19
|
Revision: 2171 http://astpp.svn.sourceforge.net/astpp/?rev=2171&view=rev Author: darrenkw Date: 2007-12-28 20:58:01 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Commit Realtime Rating Engine cleanups by Sonia Kahn Modified Paths: -------------- trunk/astpp-admin.cgi trunk/astpp-common.pl trunk/astpp-rate-engine.pl Modified: trunk/astpp-admin.cgi =================================================================== --- trunk/astpp-admin.cgi 2007-12-29 04:26:16 UTC (rev 2170) +++ trunk/astpp-admin.cgi 2007-12-29 04:58:01 UTC (rev 2171) @@ -1529,7 +1529,7 @@ ); $template->param( dids => &count_dids( $astpp_db, "" ) ); $template->param( - unbilled_cdrs => &count_unbilled_cdrs( $cdr_db, $accounts ) ); + unbilled_cdrs => &count_unbilled_cdrs( $config, $cdr_db, $accounts ) ); } elsif ( $params->{logintype} == 2 && $astpp_db && $cdr_db ) { $template->param( @@ -1550,7 +1550,7 @@ $template->param( total_owing => &accounts_total_balance($astpp_db,"")/10000 ); $template->param( dids => &count_dids( $astpp_db, "" ) ); $template->param( - unbilled_cdrs => &count_unbilled_cdrs( $cdr_db, "NULL,''" ) ); + unbilled_cdrs => &count_unbilled_cdrs( $config, $cdr_db, "NULL,''" ) ); } return $template->output; @@ -11083,9 +11083,9 @@ $iax2_login = $sql->fetchrow_hashref; $sql->finish; } - my @chargelist = &list_cdrs_account( $cdr_db, $accountinfo->{number}, + my @chargelist = &list_cdrs_account( $config, $cdr_db, $accountinfo->{number}, $accountinfo->{cc} ); - &processlist( $astpp_db, $cdr_db, $config, @chargelist ) + &processlist( $astpp_db, $cdr_db, $config, \@chargelist ) ; # Bill as many calls as we can. $status .= gettext("We rated as many CDRS as we could") . "<br>"; $tmp = @@ -11137,7 +11137,7 @@ filename => '/var/lib/astpp/templates/booth-view.tpl', die_on_bad_params => $config->{template_die_on_bad_params} ); $template->param( booth_name => $params->{booth_name} ); my $balance = &accountbalance( $astpp_db, $params->{booth_name} ) / 10000; - my $unrated = &count_unrated_cdrs_account( $cdr_db, $accountinfo->{number}, + my $unrated = &count_unrated_cdrs_account( $config, $cdr_db, $accountinfo->{number}, $accountinfo->{cc} ); $ASTPP->debug( user=> $param->{username}, debug => $balance); $template->param( unrated_cdrs => $unrated ); Modified: trunk/astpp-common.pl =================================================================== --- trunk/astpp-common.pl 2007-12-29 04:26:16 UTC (rev 2170) +++ trunk/astpp-common.pl 2007-12-29 04:58:01 UTC (rev 2171) @@ -1417,21 +1417,21 @@ # Select a specific cdr from the Asterisk(tm) cdr table. sub get_cdr() { - my ( $cdr_db, $uniqueid,$rating,$dst ) = @_; + my ( $config, $cdr_db, $uniqueid,$rating,$dst ) = @_; my ( $sql, $cdrdata ); if ($dst) { $sql = $cdr_db->prepare( - "SELECT * FROM cdr WHERE uniqueid = " . $cdr_db->quote($uniqueid) . " AND dst = " . $cdr_db->quote($dst) . " ORDER BY cost DESC LIMIT 1" ); + "SELECT * FROM $config->{asterisk_cdr_table} WHERE uniqueid = " . $cdr_db->quote($uniqueid) . " AND dst = " . $cdr_db->quote($dst) . " ORDER BY cost DESC LIMIT 1" ); } elsif ($rating) { $sql = $cdr_db->prepare( - "SELECT * FROM cdr WHERE uniqueid = " . $cdr_db->quote($uniqueid) . " AND cost in ('error','none') ORDER BY cost DESC LIMIT 1" ); + "SELECT * FROM $config->{asterisk_cdr_table} WHERE uniqueid = " . $cdr_db->quote($uniqueid) . " AND cost in ('error','none') ORDER BY cost DESC LIMIT 1" ); } else { $sql = $cdr_db->prepare( - "SELECT * FROM cdr WHERE uniqueid = " . $cdr_db->quote($uniqueid) . " ORDER by cost DESC LIMIT 1" ); + "SELECT * FROM $config->{asterisk_cdr_table} WHERE uniqueid = " . $cdr_db->quote($uniqueid) . " ORDER by cost DESC LIMIT 1" ); } $sql->execute; $cdrdata = $sql->fetchrow_hashref; @@ -1441,8 +1441,8 @@ # Update the cost of a cdr in the Asterisk(tm) cdr table. This is used to denote a cdr that has been rated. sub save_ast_cdr() { - my ( $cdr_db, $uniqueid, $cost,$dst ) = @_; - $cdr_db->do( "UPDATE cdr SET cost = " + my ( $config, $cdr_db, $uniqueid, $cost,$dst ) = @_; + $cdr_db->do( "UPDATE $config->{asterisk_cdr_table} SET cost = " . $cdr_db->quote($cost) . "WHERE uniqueid = " . $cdr_db->quote($uniqueid) @@ -1455,11 +1455,11 @@ # used to select cdrs that have not been billed which have value "none" or those that the rating engine ran # into a problem with which are marked "error". sub list_cdrs_status() { - my ( $cdr_db, $default ) = @_; + my ( $config, $cdr_db, $default ) = @_; my ( $sql, @cdrlist, $row ); $sql = $cdr_db->prepare( - "SELECT * FROM cdr WHERE cost = " . $cdr_db->quote($default) ); + "SELECT * FROM $config->{asterisk_cdr_table} WHERE cost = " . $cdr_db->quote($default) ); $sql->execute; while ( $row = $sql->fetchrow_hashref ) { push @cdrlist, $row->{uniqueid}; @@ -1469,11 +1469,11 @@ # Select all the unbilled CDRS belonging to a specific account. This is mostly used by booths. sub list_cdrs_account() { - my ( $cdr_db, $account, $cc ) = @_; + my ( $config, $cdr_db, $account, $cc ) = @_; my ( $sql, @cdrlist, $row ); $sql = $cdr_db->prepare( - "SELECT * FROM cdr WHERE cost IN ('none', 'error') AND accountcode IN (" . $cdr_db->quote($account) . ", " . $cdr_db->quote($cc) . ") AND disposition REGEXP 'ANSWE.*'"); + "SELECT * FROM $config->{asterisk_cdr_table} WHERE cost IN ('none', 'error') AND accountcode IN (" . $cdr_db->quote($account) . ", " . $cdr_db->quote($cc) . ") AND disposition REGEXP 'ANSWE.*'"); $sql->execute; while ( $row = $sql->fetchrow_hashref ) { push @cdrlist, $row->{uniqueid}; @@ -1484,8 +1484,8 @@ # Update the cost of a cdr in the Asterisk(tm) cdr table. This is used to denote a cdr that has been tagged # to a vendor. sub save_ast_cdr_vendor() { - my ( $cdr_db, $uniqueid, $cost,$dst ) = @_; - $cdr_db->do( "UPDATE cdr SET vendor = " + my ( $config, $cdr_db, $uniqueid, $cost,$dst ) = @_; + $cdr_db->do( "UPDATE $config->{asterisk_cdr_table} SET vendor = " . $cdr_db->quote($cost) . "WHERE uniqueid = " . $cdr_db->quote($uniqueid) @@ -1498,11 +1498,11 @@ # used to select cdrs that have not been tagged to a vendor which have value "none" or those that the rating engine ran # into a problem with which are marked "error". sub list_cdrs_status_vendor() { - my ( $cdr_db, $default ) = @_; + my ( $config, $cdr_db, $default ) = @_; my ( $sql, @cdrlist, $row ); $sql = $cdr_db->prepare( - "SELECT * FROM cdr WHERE vendor = " . $cdr_db->quote($default) ); + "SELECT * FROM $config->{asterisk_cdr_table} WHERE vendor = " . $cdr_db->quote($default) ); $sql->execute; while ( $row = $sql->fetchrow_hashref ) { push @cdrlist, $row->{uniqueid}; @@ -2174,38 +2174,37 @@ # Write ASTPP cdr. I think this one is mostly deprecated but should probably be completely removed. sub post_cdr() { - my ( - $astpp_db, $config, $uniqueid, $account, $clid, - $dest, $disp, $seconds, $cost, $callstart, - $postexternal, $trunk, $notes,$pricelist,$pattern - ) - = @_; + my ( + $astpp_db, $config, $uniqueid, $account, $clid, + $dest, $disp, $seconds, $cost, $callstart, + $postexternal, $trunk, $notes,$pricelist,$pattern + ) = @_; - # The cost is passed in 100ths of a penny. - my ( $tmp, $status ); - $trunk = gettext("N/A") if ( !$trunk ); - $uniqueid = gettext("N/A") if ( !$uniqueid ); - $pricelist = gettext("N/A") if ( !$pricelist ); - $pattern = gettext("N/A") if ( !$pattern ); - $status = 0; - $tmp = -"INSERT INTO cdrs(uniqueid,cardnum,callerid,callednum,trunk,disposition,billseconds," - . "debit,callstart,status,notes,pricelist,pattern) VALUES (" - . $astpp_db->quote($uniqueid) . ", " - . $astpp_db->quote($account) . ", " - . $astpp_db->quote($clid) . ", " - . $astpp_db->quote($dest) . ", " - . $astpp_db->quote($trunk) . ", " - . $astpp_db->quote($disp) . ", " - . $astpp_db->quote($seconds) . ", " - . $astpp_db->quote($cost) . ", " - . $astpp_db->quote($callstart) . ", " - . $astpp_db->quote($status) . ", " - . $astpp_db->quote($notes) . "," - . $astpp_db->quote($pricelist) . "," - . $astpp_db->quote($pattern) . ")"; - print STDERR "$tmp\n"; - $astpp_db->do($tmp); +# The cost is passed in 100ths of a penny. + my ( $tmp, $status ); + $trunk = gettext("N/A") if ( !$trunk ); + $uniqueid = gettext("N/A") if ( !$uniqueid ); + $pricelist = gettext("N/A") if ( !$pricelist ); + $pattern = gettext("N/A") if ( !$pattern ); + $status = 0; + $tmp = + "INSERT INTO cdrs(uniqueid,cardnum,callerid,callednum,trunk,disposition,billseconds," + . "debit,callstart,status,notes,pricelist,pattern) VALUES (" + . $astpp_db->quote($uniqueid) . ", " + . $astpp_db->quote($account) . ", " + . $astpp_db->quote($clid) . ", " + . $astpp_db->quote($dest) . ", " + . $astpp_db->quote($trunk) . ", " + . $astpp_db->quote($disp) . ", " + . $astpp_db->quote($seconds) . ", " + . $astpp_db->quote($cost) . ", " + . $astpp_db->quote($callstart) . ", " + . $astpp_db->quote($status) . ", " + . $astpp_db->quote($notes) . "," + . $astpp_db->quote($pricelist) . "," + . $astpp_db->quote($pattern) . ")"; + print STDERR "$tmp\n"; + $astpp_db->do($tmp); } ############### Integration with AgileBill starts here ################## @@ -3267,10 +3266,10 @@ # Return a list of unbilled cdrs from the Asterisk(TM) cdr database. sub count_unbilled_cdrs() { - my ($cdr_db,$account) = @_; + my ($config, $cdr_db,$account) = @_; my ( $sql, $count, $record ); $sql = - $cdr_db->prepare( "SELECT COUNT(*) FROM cdr WHERE cost = 'error' OR " + $cdr_db->prepare( "SELECT COUNT(*) FROM $config->{asterisk_cdr_table} WHERE cost = 'error' OR " . "accountcode IN (" . $account . ") AND cost ='none'" ); $sql->execute; $record = $sql->fetchrow_hashref; @@ -3358,11 +3357,11 @@ # List unrated CDRS per account sub count_unrated_cdrs_account() { - my ( $cdr_db, $account, $cc ) = @_; + my ( $config, $cdr_db, $account, $cc ) = @_; my ( $sql, @cdrlist, $record, $count ); $sql = $cdr_db->prepare( - "SELECT COUNT(*) FROM cdr WHERE cost IN ('none', 'error') AND accountcode IN (" . $cdr_db->quote($account) . ", " . $cdr_db->quote($cc) . ")"); + "SELECT COUNT(*) FROM $config->{asterisk_cdr_table} WHERE cost IN ('none', 'error') AND accountcode IN (" . $cdr_db->quote($account) . ", " . $cdr_db->quote($cc) . ")"); $sql->execute; $record = $sql->fetchrow_hashref; $count = $record->{"COUNT(*)"}; @@ -3748,21 +3747,18 @@ } sub rating() { # This routine recieves a specific cdr and takes care of rating it and of marking it as rated. It bills resellers as appropriate. - my ( $astpp_db, $cdr_db, $config, $cdrinfo, $carddata, @output ) = @_; + my ( $astpp_db, $cdr_db, $config, $cdrinfo, $carddata, $vars, @output ) = @_; my ( $increment, $numdata, $package, $notes, $status ); print STDERR "----------------------------------------------------------------\n"; print STDERR -"uniqueid: $cdrinfo->{uniqueid}, cardno: $carddata->{number}, phoneno: $cdrinfo->{dst}, Userfield: $cdrinfo->{userfield}\n"; + "uniqueid: $cdrinfo->{uniqueid}, cardno: $carddata->{number}, phoneno: $cdrinfo->{dst}, Userfield: $cdrinfo->{userfield}\n"; print STDERR -"disposition: $cdrinfo->{disposition} Pricelist: $carddata->{pricelist} reseller: $carddata->{reseller}\n"; + "disposition: $cdrinfo->{disposition} Pricelist: $carddata->{pricelist} reseller: $carddata->{reseller}\n"; if ( $cdrinfo->{disposition} =~ /^ANSWERED$/ ) { - $numdata = - &get_route( $astpp_db, $config, $cdrinfo->{dst}, - $carddata->{pricelist}, $carddata, $cdrinfo->{userfield} ); + $numdata = &get_route( $astpp_db, $config, $cdrinfo->{dst}, $carddata->{pricelist}, $carddata, $cdrinfo->{userfield} ); print STDERR "PATTERN: $numdata->{pattern}"; if ( !$numdata->{pattern} ) { - &save_ast_cdr( $cdr_db, $cdrinfo->{uniqueid}, "error",$cdrinfo->{dst} ) - if $config->{astcdr} == 1; + &save_ast_cdr( $config, $cdr_db, $cdrinfo->{uniqueid}, "error",$cdrinfo->{dst} ) if !$vars && $config->{astcdr} == 1; print STDERR "ERROR - ERROR - ERROR - ERROR - ERROR \n"; print STDERR "NO MATCHING PATTERN\n"; print STDERR "----------------------------------------------------------------\n"; @@ -3771,28 +3767,23 @@ print STDERR "FOUND A MATCHING PATTERN.\n"; my $branddata = &get_pricelist( $astpp_db, $carddata->{pricelist} ); print STDERR -"pricelistData: $branddata->{name} $branddata->{markup} $branddata->{inc} $branddata->{status}\n"; + "pricelistData: $branddata->{name} $branddata->{markup} $branddata->{inc} $branddata->{status}\n"; $package = &get_package( $astpp_db, $carddata, $cdrinfo->{dst} ); - if ($package->{id}) { - my $counter = - &get_counter( $astpp_db, $package->{id}, - $carddata->{number} ); + if ($package->{id}) { + my $counter = &get_counter( $astpp_db, $package->{id}, $carddata->{number} ); my $difference; - if ( !$counter->{id}) { - my $tmp = - "INSERT INTO counters (package,account) VALUES (" - . $astpp_db->quote( $package->{id} ) . ", " - . $astpp_db->quote( $carddata->{number} ) . ")"; + if ( !$counter->{id}) { + my $tmp = "INSERT INTO counters (package,account) VALUES (" + . $astpp_db->quote( $package->{id} ) . ", " + . $astpp_db->quote( $carddata->{number} ) . ")"; print STDERR "/n" . $tmp . "/n" if $config->{debug} == 1; - $astpp_db->do($tmp); - $counter = - &get_counter( $astpp_db, $package->{id}, - $carddata->{number} ); + $astpp_db->do($tmp); + $counter = &get_counter( $astpp_db, $package->{id}, $carddata->{number} ); print STDERR "JUST CREATED COUNTER: $counter->{id}\n" if $config->{debug} == 1; - } - if ( $package->{includedseconds} > $counter->{seconds}) { - my $availableseconds = $package->{includedseconds} - $counter->{seconds}; + } + if ( $package->{includedseconds} > $counter->{seconds}) { + my $availableseconds = $package->{includedseconds} - $counter->{seconds}; my $freeseconds; if ($availableseconds >= $cdrinfo->{billsec}) { $freeseconds = $cdrinfo->{billsec}; @@ -3801,23 +3792,18 @@ $freeseconds = $availableseconds; $cdrinfo->{billsec} = $cdrinfo->{billsec} - $availableseconds; } - my $tmp = - "UPDATE counters SET seconds = " - . $astpp_db->quote( - $counter->{seconds} + $freeseconds ) - . " WHERE id = " - . $astpp_db->quote( $counter->{id} ); + my $tmp = "UPDATE counters SET seconds = " + . $astpp_db->quote( $counter->{seconds} + $freeseconds ) + . " WHERE id = " + . $astpp_db->quote( $counter->{id} ); print STDERR $tmp . "/n" if $config->{debug} == 1; - $astpp_db->do($tmp); - } - } + $astpp_db->do($tmp); + } + } if ( $branddata->{markup} ne "" && $branddata->{markup} != 0 ) { - $numdata->{connectcost} = - $numdata->{connectcost} * - ( ( $branddata->{markup} / 10000 ) + 1 ); - $numdata->{cost} = - $numdata->{cost} * ( ( $branddata->{markup} / 10000 ) + 1 ); + $numdata->{connectcost} = $numdata->{connectcost} * ( ( $branddata->{markup} / 10000 ) + 1 ); + $numdata->{cost} = $numdata->{cost} * ( ( $branddata->{markup} / 10000 ) + 1 ); } if ( $numdata->{inc} > 0 ) { $increment = $numdata->{inc}; @@ -3826,24 +3812,22 @@ $increment = $branddata->{inc}; } print STDERR -"$numdata->{connectcost}, $numdata->{cost}, $cdrinfo->{billsec}, $increment, $numdata->{includedseconds}"; + "$numdata->{connectcost}, $numdata->{cost}, $cdrinfo->{billsec}, $increment, $numdata->{includedseconds}"; my $cost = &calc_call_cost( - $numdata->{connectcost}, $numdata->{cost}, - $cdrinfo->{billsec}, $increment, - $numdata->{includedseconds} - ); + $numdata->{connectcost}, $numdata->{cost}, + $cdrinfo->{billsec}, $increment, + $numdata->{includedseconds} + ); $cost = sprintf( "%." . $config->{decimalpoints} . "f", $cost ); print STDERR "Matching pattern is $numdata->{pattern}\n"; - #Blocks all signals so that the program cannot be killed while writing costs. +#Blocks all signals so that the program cannot be killed while writing costs. my $sigset = POSIX::SigSet->new; my $blockset = POSIX::SigSet->new( SIGINT, SIGQUIT, SIGCHLD ); - sigprocmask( SIG_BLOCK, $blockset, $sigset ) - or die "Could not block INT,QUIT,CHLD signals: $!\n"; - &save_ast_cdr( $cdr_db, $cdrinfo->{uniqueid}, $cost,$cdrinfo->{dst} ) - if $config->{astcdr} == 1; + sigprocmask( SIG_BLOCK, $blockset, $sigset ) or die "Could not block INT,QUIT,CHLD signals: $!\n"; + &save_ast_cdr( $config, $cdr_db, $cdrinfo->{uniqueid}, $cost,$cdrinfo->{dst} ) if !$vars && $config->{astcdr} == 1; if ( $cdrinfo->{accountcode} ne $carddata->{number} && $cdrinfo->{accountcode} ne $carddata->{cc}) { $notes = $cdrinfo->{accountcode} . "|" . $numdata->{comment} . "|" . $numdata->{pattern}; } @@ -3851,29 +3835,28 @@ $notes = "|" . $numdata->{comment} . "|" . $numdata->{pattern}; } &post_cdr( - $astpp_db, $config, - $cdrinfo->{uniqueid}, $carddata->{number}, - $cdrinfo->{src}, $cdrinfo->{dst}, - $cdrinfo->{disposition}, $cdrinfo->{billsec}, - $cost, $cdrinfo->{calldate}, - "", $cdrinfo->{trunk}, - $notes,$numdata->{pricelist}, $numdata->{pattern} - ) - if $config->{posttoastpp} == 1; + $astpp_db, $config, + $cdrinfo->{uniqueid}, $carddata->{number}, + $cdrinfo->{src}, $cdrinfo->{dst}, + $cdrinfo->{disposition}, $cdrinfo->{billsec}, + $cost, $cdrinfo->{calldate}, + "", $cdrinfo->{trunk}, + $notes,$numdata->{pricelist}, $numdata->{pattern} + ) + if $config->{posttoastpp} == 1; &print_csv( - $config, $carddata->{number}, $cdrinfo->{disposition}, - $cdrinfo->{calldate}, $cdrinfo->{dst}, - $cdrinfo->{billsec}, $cost, - $carddata->{reseller}, $cdrinfo, @output - ); + $config, $carddata->{number}, $cdrinfo->{disposition}, + $cdrinfo->{calldate}, $cdrinfo->{dst}, + $cdrinfo->{billsec}, $cost, + $carddata->{reseller}, $cdrinfo, @output + ); sigprocmask( SIG_SETMASK, $sigset ) # Restore the passing of signals - or die "Could not restore INT,QUIT,CHLD signals: $!\n"; # - $status = 1; + or die "Could not restore INT,QUIT,CHLD signals: $!\n"; # + $status = 1; } } else { - &save_ast_cdr( $cdr_db, $cdrinfo->{uniqueid}, "error",$cdrinfo->{dst} ) - if $config->{astcdr} == 1; + &save_ast_cdr( $config, $cdr_db, $cdrinfo->{uniqueid}, "error",$cdrinfo->{dst} ) if !$vars && $config->{astcdr} == 1; print STDERR "ERROR - ERROR - ERROR - ERROR - ERROR \n"; print STDERR "DISPOSITION: $cdrinfo->{disposition} \n"; print STDERR "UNIQUEID: $cdrinfo->{uniqueid} \n"; @@ -3891,8 +3874,8 @@ } sub vendor_not_billed() { # Prints the information on calls where the "vendor" field is either none or error. - my ($cdr_db) = @_; - my $tmp = "SELECT * FROM cdr WHERE vendor IN ('none','error')"; + my ($config, $cdr_db) = @_; + my $tmp = "SELECT * FROM $config->{asterisk_cdr_table} WHERE vendor IN ('none','error')"; my $sql = $cdr_db->prepare($tmp); $sql->execute; while ( my $cdr = $sql->fetchrow_hashref ) { @@ -3911,33 +3894,34 @@ sub processlist() { # Deal with a list of calls which have not been rated so far. - my ($astpp_db, $cdr_db, $config, @chargelist) = @_; - my ( $status); - foreach (@chargelist) { + my ($astpp_db, $cdr_db, $config, $chargelist, $vars) = @_; + my ( $status, $cdrinfo); + foreach (@$chargelist) { my $uniqueid = $_; - print STDERR gettext("Processing Uniqueid: ") . $_; - my $cdrinfo = &get_cdr( $cdr_db, $uniqueid ); + print STDERR gettext("Processing Uniqueid: ") . @$chargelist; + $cdrinfo = ($vars) ? $vars : &get_cdr( $config, $cdr_db, $uniqueid ); my $savedcdrinfo = $cdrinfo; - my $tmp = "UPDATE $config->{asterisk_cdr_table} SET cost = 'rating' WHERE uniqueid = " - . $cdr_db->quote($uniqueid) - . " AND cost = 'none'" - . " AND dst = " - . $cdr_db->quote($cdrinfo->{dst}) - . " LIMIT 1"; - $cdr_db->do($tmp); + if(!$vars) { + my $tmp = "UPDATE $config->{asterisk_cdr_table} SET cost = 'rating' WHERE uniqueid = " + . $cdr_db->quote($uniqueid) + . " AND cost = 'none'" + . " AND dst = " + . $cdr_db->quote($cdrinfo->{dst}) + . " LIMIT 1"; + $cdr_db->do($tmp); + } else { + $cdrinfo->{'cost'} = 'rating'; + } if ( $cdrinfo->{accountcode} ) { my $carddata = &get_account( $astpp_db, $cdrinfo->{accountcode} ); if ($carddata->{number}) { - if ( $cdrinfo->{lastapp} eq "MeetMe" ) { # - $cdrinfo->{billsec} = $cdrinfo - ->{duration}; # There is an issue with calls that come out of meetme - } # not having the right billable seconds. - if ( $cdrinfo->{billsec} <= 0 ) { - &save_ast_cdr( $cdr_db, $uniqueid, 0,$cdrinfo->{dst} ) - if $config->{astcdr} == 1; - &save_ast_cdr_vendor( $cdr_db, $uniqueid, 0,$cdrinfo->{dst} ) - if $config->{astcdr} == 1 - && $config->{trackvendorcharges} == 1; + if ( $cdrinfo->{lastapp} eq "MeetMe" ) { # There is an issue with calls that come out of meetmee + $cdrinfo->{billsec} = $cdrinfo->{duration}; + } + if ( $cdrinfo->{billsec} <= 0 ) { # not having the right billable seconds. + &save_ast_cdr( $config, $cdr_db, $uniqueid, 0,$cdrinfo->{dst} ) if !$vars && $config->{astcdr} == 1; + &save_ast_cdr_vendor( $config, $cdr_db, $uniqueid, 0,$cdrinfo->{dst} ) + if !$vars && $config->{astcdr} == 1 && $config->{trackvendorcharges} == 1; print STDERR "\n----------------------\n"; print STDERR "CDR Written - No Billable Seconds\n"; print STDERR @@ -3946,19 +3930,19 @@ print STDERR "----------------------\n"; } elsif ( $cdrinfo->{accountcode} ) { - $status = &rating( $astpp_db, $cdr_db, $config, $cdrinfo, $carddata); - $cdrinfo = &get_cdr( $cdr_db, $uniqueid ); + $status = &rating( $astpp_db, $cdr_db, $config, $cdrinfo, $carddata, $vars); + $cdrinfo = &get_cdr( $config, $cdr_db, $uniqueid ) if !$vars; if ( $status == 1 ) { my $previous_account = $carddata->{number}; while ( $carddata->{reseller} ne "" ) { - $cdrinfo = &get_cdr( $cdr_db, $uniqueid ); + $cdrinfo = &get_cdr( $config, $cdr_db, $uniqueid ) if !$vars; print STDERR "Charge $uniqueid to $carddata->{reseller}" if $config->{debug} == 1; $carddata = &get_account( $astpp_db, $carddata->{reseller} ); - $status = &rating( $astpp_db, $cdr_db, $config, $cdrinfo, $carddata); + $status = &rating( $astpp_db, $cdr_db, $config, $cdrinfo, $carddata, $vars); my $tmp = "SELECT id FROM cdrs WHERE uniqueid = '" . $uniqueid . "' AND cardnum = '" . $previous_account . "' LIMIT 1"; print STDERR "$tmp\n" if $config->{debug} == 1; - my $sql = $astpp_db->prepare($tmp); + my $sql = $astpp_db->prepare($tmp); $sql->execute; my $previous_data = $sql->fetchrow_hashref; $sql->finish; @@ -3966,15 +3950,14 @@ $tmp = "SELECT id,debit,credit FROM cdrs WHERE uniqueid = '" . $uniqueid . "' AND cardnum = '" . $carddata->{number} . "' LIMIT 1"; print STDERR "$tmp\n" if $config->{debug} == 1; - $sql = $astpp_db->prepare($tmp); + $sql = $astpp_db->prepare($tmp); $sql->execute; my $cdrdata = $sql->fetchrow_hashref; $sql->finish; $cdrdata->{cost} = $cdrdata->{debit} - $cdrdata->{credit}; $tmp = "UPDATE cdrs SET cost = " . $cdrdata->{cost} - . " WHERE id = " . $previous_data->{id} . " AND callednum = " - . $cdr_db->quote($cdrinfo->{dst}); + . " WHERE id = " . $previous_data->{id} . " AND callednum = " . $cdr_db->quote($cdrinfo->{dst}); print STDERR "$tmp\n" if $config->{debug} == 1; $astpp_db->do($tmp); $previous_account = $carddata->{number}; @@ -3987,12 +3970,16 @@ print STDERR "ERROR - ERROR - ERROR - ERROR - ERROR \n"; print STDERR "NO ACCOUNT EXISTS IN ASTPP\n"; print STDERR -"uniqueid: $uniqueid, Account: $cdrinfo->{accountcode}, phoneno: $cdrinfo->{dst}\n"; + "uniqueid: $uniqueid, Account: $cdrinfo->{accountcode}, phoneno: $cdrinfo->{dst}\n"; print STDERR "disposition: $cdrinfo->{disposition}\n"; print STDERR "----------------------\n"; - my $tmp = "UPDATE $config->{asterisk_cdr_table} SET cost = 'none' WHERE uniqueid = " - . $uniqueid . " AND cost = 'rating' LIMIT 1"; - $cdr_db->do($tmp); + if(!$vars) { + my $tmp = "UPDATE $config->{asterisk_cdr_table} SET cost = 'none' WHERE uniqueid = " + . $uniqueid . " AND cost = 'rating' LIMIT 1"; + $cdr_db->do($tmp); + } else { + $cdrinfo->{cost} = 'none'; + } } } else { @@ -4000,61 +3987,101 @@ print STDERR "ERROR - ERROR - ERROR - ERROR - ERROR \n"; print STDERR "NO ACCOUNTCODE IN DATABASE\n"; print STDERR -"uniqueid: $uniqueid, cardno: $cdrinfo->{accountcode}, phoneno: $cdrinfo->{dst}\n"; + "uniqueid: $uniqueid, cardno: $cdrinfo->{accountcode}, phoneno: $cdrinfo->{dst}\n"; print STDERR "disposition: $cdrinfo->{disposition}\n"; print STDERR "----------------------\n"; - my $tmp = "UPDATE $config->{asterisk_cdr_table} SET cost = 'none' WHERE uniqueid = " - . $uniqueid . " AND cost = 'rating' LIMIT 1"; - $cdr_db->do($tmp); + if(!$vars) { + my $tmp = "UPDATE $config->{asterisk_cdr_table} SET cost = 'none' WHERE uniqueid = " + . $uniqueid . " AND cost = 'rating' LIMIT 1"; + $cdr_db->do($tmp); + } else { + $cdrinfo->{cost} = 'none'; + } } my $phrase = "none"; - &vendor_process_rating( $astpp_db, $cdr_db, $config, $phrase, $uniqueid ) if $config->{trackvendorcharges} == 1; - + &vendor_process_rating( $astpp_db, $cdr_db, $config, $phrase, $uniqueid, $vars ) if $config->{trackvendorcharges} == 1; } } sub vendor_process_rating() { #Rate Vendor calls. - my ( $astpp_db, $cdr_db, $config, $phrase, $uniqueid ) = @_; + my ( $astpp_db, $cdr_db, $config, $phrase, $uniqueid, $vars ) = @_; my $tmp = "SELECT * FROM trunks ORDER BY LENGTH(path)"; my $sql = $astpp_db->prepare($tmp); print STDERR "$tmp\n" . "\n" if $config->{debug} == 1; $sql->execute; while ( my $trunk = $sql->fetchrow_hashref ) { my $tmp; - if ( $uniqueid ne "" ) { - $tmp = - "SELECT * FROM $config->{asterisk_cdr_table} where lastapp = 'Dial'" - . " AND vendor = " - . $cdr_db->quote($phrase) - . " AND (dstchannel LIKE '$trunk->{tech}/$trunk->{path}%'" - . " OR dstchannel LIKE '$trunk->{tech}\[$trunk->{path}\]%'" - . " OR lastdata LIKE '$trunk->{tech}/$trunk->{path}%'" - . " OR lastdata LIKE '$trunk->{tech}\[$trunk->{path}\]%')" - . " AND uniqueid = " - . $cdr_db->quote($uniqueid) - . " AND disposition = 'ANSWERED'"; - } - else { - $tmp = - "SELECT * FROM $config->{asterisk_cdr_table} where lastapp = 'Dial'" - . " AND vendor = " - . $cdr_db->quote($phrase) - . " AND (dstchannel LIKE '$trunk->{tech}/$trunk->{path}%'" - . " OR dstchannel LIKE '$trunk->{tech}\[$trunk->{path}\]%'" - . " OR lastdata LIKE '$trunk->{tech}/$trunk->{path}%'" - . " OR lastdata LIKE '$trunk->{tech}\[$trunk->{path}\]%')" - . " AND disposition = 'ANSWERED'"; - } - print STDERR "$tmp\n" . "\n" if $config->{debug} == 1; - my $sql1 = $cdr_db->prepare($tmp); - $sql1->execute; - while ( my $cdrinfo = $sql1->fetchrow_hashref ) { - my $tmp = - "SELECT * FROM outbound_routes WHERE " - . $astpp_db->quote( $cdrinfo->{dst} ) - . " RLIKE pattern AND status = 1 AND trunk = " - . $astpp_db->quote( $trunk->{name} ) - . " ORDER by LENGTH(pattern) DESC, cost"; + if(!$vars) { + if ( $uniqueid ne "" ) { + $tmp = + "SELECT * FROM $config->{asterisk_cdr_table} where lastapp = 'Dial'" + . " AND vendor = " + . $cdr_db->quote($phrase) + . " AND (dstchannel LIKE '$trunk->{tech}/$trunk->{path}%'" + . " OR dstchannel LIKE '$trunk->{tech}\[$trunk->{path}\]%'" + . " OR lastdata LIKE '$trunk->{tech}/$trunk->{path}%'" + . " OR lastdata LIKE '$trunk->{tech}\[$trunk->{path}\]%')" + . " AND uniqueid = " + . $cdr_db->quote($uniqueid) + . " AND disposition = 'ANSWERED'"; + } else { + $tmp = "SELECT * FROM $config->{asterisk_cdr_table} where lastapp = 'Dial'" + . " AND vendor = " + . $cdr_db->quote($phrase) + . " AND (dstchannel LIKE '$trunk->{tech}/$trunk->{path}%'" + . " OR dstchannel LIKE '$trunk->{tech}\[$trunk->{path}\]%'" + . " OR lastdata LIKE '$trunk->{tech}/$trunk->{path}%'" + . " OR lastdata LIKE '$trunk->{tech}\[$trunk->{path}\]%')" + . " AND disposition = 'ANSWERED'"; + } + print STDERR "$tmp\n" . "\n" if $config->{debug} == 1; + my $sql1 = $cdr_db->prepare($tmp); + $sql1->execute; + while ( my $cdrinfo = $sql1->fetchrow_hashref ) { + my $tmp = "SELECT * FROM outbound_routes WHERE " + . $astpp_db->quote( $cdrinfo->{dst} ) + . " RLIKE pattern AND status = 1 AND trunk = " + . $astpp_db->quote( $trunk->{name} ) + . " ORDER by LENGTH(pattern) DESC, cost"; + my $sql2 = $astpp_db->prepare($tmp); + $sql2->execute; + print STDERR "$tmp\n" . "\n" if $config->{debug} == 1; + my $pricerecord = $sql2->fetchrow_hashref; + $sql2->finish; + if ( $pricerecord->{id} ) { + my $cost = &calc_call_cost( + $pricerecord->{connectcost}, $pricerecord->{cost}, + $cdrinfo->{billsec}, $pricerecord->{inc}, + $pricerecord->{includedseconds} + ); + $cost = sprintf( "%." . $config->{decimalpoints} . "f", $cost ); + &post_cdr( + $astpp_db, $config, + $cdrinfo->{uniqueid}, $trunk->{provider}, + $cdrinfo->{src}, $cdrinfo->{dst}, + $cdrinfo->{disposition}, $cdrinfo->{billsec}, + $cost * -1, $cdrinfo->{calldate}, + "", $cdrinfo->{trunk}, + $pricerecord->{comment} . "|" . $pricerecord->{pattern} + ) if $config->{posttoastpp} == 1; + &save_ast_cdr_vendor( $config, $cdr_db, $cdrinfo->{uniqueid}, $cost,$cdrinfo->{dst} ); + my $tmp = "UPDATE cdrs SET cost = '" . $cost . "' WHERE uniqueid = '" . + $cdrinfo->{uniqueid} . "' AND cost = 0 " + . " AND cardnum != '" . $trunk->{provider} . "' AND dst = " + . $astpp_db->quote($cdrinfo->{dst}) . " LIMIT 1"; + print STDERR "$tmp\n" if $config->{debug} == 1; + $astpp_db->do($tmp); + } else { + &save_ast_cdr_vendor( $config, $cdr_db, $cdrinfo->{uniqueid}, "error",$cdrinfo->{dst} ); + } + } + } else { + $cardinfo = $vars; + my $tmp = "SELECT * FROM outbound_routes WHERE " + . $astpp_db->quote( $cdrinfo->{dst} ) + . " RLIKE pattern AND status = 1 AND trunk = " + . $astpp_db->quote( $trunk->{name} ) + . " ORDER by LENGTH(pattern) DESC, cost"; my $sql2 = $astpp_db->prepare($tmp); $sql2->execute; print STDERR "$tmp\n" . "\n" if $config->{debug} == 1; @@ -4062,22 +4089,20 @@ $sql2->finish; if ( $pricerecord->{id} ) { my $cost = &calc_call_cost( - $pricerecord->{connectcost}, $pricerecord->{cost}, - $cdrinfo->{billsec}, $pricerecord->{inc}, - $pricerecord->{includedseconds} - ); + $pricerecord->{connectcost}, $pricerecord->{cost}, + $cdrinfo->{billsec}, $pricerecord->{inc}, + $pricerecord->{includedseconds} + ); $cost = sprintf( "%." . $config->{decimalpoints} . "f", $cost ); &post_cdr( - $astpp_db, $config, - $cdrinfo->{uniqueid}, $trunk->{provider}, - $cdrinfo->{src}, $cdrinfo->{dst}, - $cdrinfo->{disposition}, $cdrinfo->{billsec}, - $cost * -1, $cdrinfo->{calldate}, - "", $cdrinfo->{trunk}, - $pricerecord->{comment} . "|" . $pricerecord->{pattern} - ) - if $config->{posttoastpp} == 1; - &save_ast_cdr_vendor( $cdr_db, $cdrinfo->{uniqueid}, $cost,$cdrinfo->{dst} ); + $astpp_db, $config, + $cdrinfo->{uniqueid}, $trunk->{provider}, + $cdrinfo->{src}, $cdrinfo->{dst}, + $cdrinfo->{disposition}, $cdrinfo->{billsec}, + $cost * -1, $cdrinfo->{calldate}, + "", $cdrinfo->{trunk}, + $pricerecord->{comment} . "|" . $pricerecord->{pattern} + ) if $config->{posttoastpp} == 1; my $tmp = "UPDATE cdrs SET cost = '" . $cost . "' WHERE uniqueid = '" . $cdrinfo->{uniqueid} . "' AND cost = 0 " . " AND cardnum != '" . $trunk->{provider} . "' AND dst = " @@ -4085,10 +4110,6 @@ print STDERR "$tmp\n" if $config->{debug} == 1; $astpp_db->do($tmp); } - else { - &save_ast_cdr_vendor( $cdr_db, $cdrinfo->{uniqueid}, "error",$cdrinfo->{dst} ); - } - } } $sql->finish; Modified: trunk/astpp-rate-engine.pl =================================================================== --- trunk/astpp-rate-engine.pl 2007-12-29 04:26:16 UTC (rev 2170) +++ trunk/astpp-rate-engine.pl 2007-12-29 04:58:01 UTC (rev 2171) @@ -60,7 +60,7 @@ my @chargelist; push @chargelist, $uniqueid; #sleep $config->{sleep}; - &processlist($astpp_db, $cdr_db, $config, @chargelist); + &processlist($astpp_db, $cdr_db, $config, \@chargelist); #&cleanup_cdrs($cdr_db, $config); &shutdown(); exit(0); @@ -91,7 +91,7 @@ ); my @chargelist; push @chargelist, $ARGV[16]; - &processlist($astpp_db, $cdr_db, $config, @chargelist); + &processlist($astpp_db, $cdr_db, $config, \@chargelist, \%args); &cleanup_cdrs($cdr_db, $config); } elsif ( $run_type eq "price_only" ) { @@ -144,13 +144,13 @@ if ( !$cdr_db ) { $cdr_db = &connect_db( $config, @output ); } - my $cdrinfo = &get_cdr( $cdr_db, $input->{Uniqueid},1 ); + my $cdrinfo = &get_cdr( $config, $cdr_db, $input->{Uniqueid},1 ); # my $tmp = "UPDATE $config->{asterisk_cdr_table} SET cost = 'rating' WHERE uniqueid = " . $input->{Uniqueid} . " AND cost = 'none' AND dst = " . $cdr_db->quote($cdrinfo->{dst}) . " LIMIT 1"; # print STDERR $tmp if $config->{debug} == 1; # print $tmp if $config->{debug} == 1; # $cdr_db->do($tmp); if ($cdrinfo->{lastapp} eq "MeetMe" || $cdrinfo->{billsec} > 0 || $cdrinfo->{cost} eq "none") { - &processlist($astpp_db, $cdr_db, $config, @chargelist); + &processlist($astpp_db, $cdr_db, $config, \@chargelist); &vendor_process_rating( $astpp_db, $cdr_db, $config, "none", $input->{Uniqueid} ) if $config->{trackvendorcharges} == 1; } # else { &cleanup_cdrs($cdr_db, $config); @@ -166,17 +166,17 @@ &cleanup_cdrs($cdr_db, $config); my @chargelist; my $phrase = "none"; - @chargelist = &list_cdrs_status( $cdr_db, $phrase ); # Grab a list of all calls with "none" assigned in the cost field - &processlist($astpp_db, $cdr_db, $config, @chargelist); # Bill as many calls as we can. + @chargelist = &list_cdrs_status( $config, $cdr_db, $phrase ); # Grab a list of all calls with "none" assigned in the cost field + &processlist($astpp_db, $cdr_db, $config, \@chargelist); # Bill as many calls as we can. $phrase = "error"; - @chargelist = &list_cdrs_status( $cdr_db, $phrase ); # Grab a list of all calls with "none" assigned in the cost field - &processlist($astpp_db, $cdr_db, $config, @chargelist); # See if we can now bill some of the calls that are marked in "error" + @chargelist = &list_cdrs_status( $config, $cdr_db, $phrase ); # Grab a list of all calls with "none" assigned in the cost field + &processlist($astpp_db, $cdr_db, $config, \@chargelist); # See if we can now bill some of the calls that are marked in "error" # print STDERR gettext("START ON VENDOR CALL RATING!") . "\n" if $config->{debug} == 1; # &vendor_process_rating( $astpp_db, $cdr_db, $config, "none", 0 ) if $config->{trackvendorcharges} == 1; # &vendor_process_rating( $astpp_db, $cdr_db, $config. $config, "error", 0 ) if $config->{trackvendorcharges} == 1; # print STDERR gettext("VENDOR CALLS WHICH HAVE NOT BEEN RATED.") . "\n" if $config->{debug} == 1; # Print a list of calls which have not been rated - &vendor_not_billed($cdr_db) if $config->{trackvendorcharges} == 1; + &vendor_not_billed($config, $cdr_db) if $config->{trackvendorcharges} == 1; &cleanup_cdrs($cdr_db, $config); } &shutdown(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |