[Astpp-commit] SF.net SVN: astpp:[2329] trunk/freeswitch/astpp-callingcards.pl
Brought to you by:
darrenkw
From: <dar...@us...> - 2011-01-15 21:38:35
|
Revision: 2329 http://astpp.svn.sourceforge.net/astpp/?rev=2329&view=rev Author: darrenkw Date: 2011-01-15 21:38:29 +0000 (Sat, 15 Jan 2011) Log Message: ----------- Fixed output on callingcard balance. Also added support to set vendor/trunk information on outgoing calls. Modified Paths: -------------- trunk/freeswitch/astpp-callingcards.pl Modified: trunk/freeswitch/astpp-callingcards.pl =================================================================== --- trunk/freeswitch/astpp-callingcards.pl 2011-01-11 03:19:05 UTC (rev 2328) +++ trunk/freeswitch/astpp-callingcards.pl 2011-01-15 21:38:29 UTC (rev 2329) @@ -9,7 +9,6 @@ # This program is Free Software and is distributed under the # terms of the GNU General Public License version 2. ############################################################################# -#use DBI; use POSIX qw(ceil floor); use POSIX qw(strftime); use Time::HiRes qw( gettimeofday tv_interval ); @@ -51,8 +50,7 @@ } sub set_in_use() -{ # Set the "inuse" flag on the calling cards. This prevents multiple people from - +{ # Set the "inuse" flag on the calling cards. This prevents multiple people from # using the same card. my ( $cardinfo, $status ) = @_; my $sql; @@ -115,7 +113,6 @@ $astpp_db->do($sql); } -# $cardinfo = &get_callingcard( $astpp_db, $cardinfo->{cardnumber} ); if ( $cardinfo->{validfordays} > 0 ) { #Check if the card is set to expire and deal with that as appropriate. my $sql = @@ -189,25 +186,50 @@ } if ( $config->{calling_cards_rate_announce} == 1 ) { if ( $numberinfo->{cost} > 0 ) { + my @call_cost = split( /\./, sprintf( "%.2f", $numberinfo->{cost} / 10000) ); $session->streamFile( $sound->{call_will_cost} ); - $session->execute( "phrase", - "spell," . ceil( $numberinfo->{cost} / 100 ) ); - $session->streamFile( $sound->{currency} ); - my @call_cost = split( /\./, ( $numberinfo->{cost} / 100 ) ); - $session->execute( "phrase", "spell," . @call_cost[0] ); - if ( @call_cost[1] ) { - $session->streamFile( $sound->{point} ); - $session->execute( "phrase", "spell," . @call_cost[1] ); - $session->streamFile( $sound->{sub_currency} ); +$ASTPP->debug( debug => "Call Cost Before Decimal: " . @call_cost[0]); + if (@call_cost[0] > 0) { + $session->execute( "say", "en number pronounced " . @call_cost[0] ); + if (@call_cost[0] == 1) { + $session->streamFile( $sound->{main_currency} ) ; + } else { + $session->streamFile( $sound->{main_currency_plural} ) ; + } + } +$ASTPP->debug( debug => "Call Cost After Decimal: " . @call_cost[1]); + if ( @call_cost[1] > 0 ) { + $session->execute( "say", "en number pronounced " . @call_cost[1] ); + if (@call_cost[1] == 1) { + $session->streamFile( $sound->{sub_currency} ) ; + } else { + $session->streamFile( $sound->{sub_currency_plural} ) ; + } } $session->streamFile( $sound->{per} ); $session->streamFile( $sound->{minute} ); } if ( $numberinfo->{connectcost} > 0 ) { $session->streamFile( $sound->{a_connect_charge} ); - $session->execute( "phrase", - "spell," . ceil( $numberinfo->{connectcost} / 100 ) ); - $session->streamFile( $sound->{sub_currency} ); + my @connect_cost = split( /\./, sprintf( "%.2f", $numberinfo->{connectcost} / 10000) ); +$ASTPP->debug( debug => "Connect Cost Before Decimal: " . @connect_cost[0]); + if (@connect_cost[0] > 0) { + $session->execute( "say", "en number pronounced " . @connect_cost[0] ); + if (@connect_cost[0] == 1) { + $session->streamFile( $sound->{main_currency} ) ; + } else { + $session->streamFile( $sound->{main_currency_plural} ) ; + } + } +$ASTPP->debug( debug => "Connect Cost After Decimal: " . @connect_cost[1]); + if ( @connect_cost[1] > 0 ) { + $session->execute( "say", "en number pronounced " . @connect_cost[1] ); + if (@connect_cost[1] == 1) { + $session->streamFile( $sound->{sub_currency} ) ; + } else { + $session->streamFile( $sound->{sub_currency_plural} ) ; + } + } $session->streamFile( $sound->{will_apply} ); } } @@ -215,13 +237,13 @@ sub timelimit() { #Calculate and say the time limit. my ( $numberinfo, $pricelistinfo, $cardinfo, $phoneno ) = @_; - my ( $connectfee, $cost, $timelimit, $available, $maxtime, $balance ); + my ( $connectcost, $cost, $timelimit, $available, $maxtime, $balance ); # Timelimit is in seconds if ( $cc == 0 ) { $available = ( $cardinfo->{value} - $cardinfo->{used} ) - - $numberinfo->{connectfee}; + $numberinfo->{connectcost}; $ASTPP->debug( debug => "FUNDS AVAILABLE: $available", verbosity => $verbosity @@ -230,7 +252,7 @@ elsif ( $cc == 1 ) { $balance = &accountbalance( $astpp_db, $cardinfo->{number} ); $balance = ( $balance * -1 ) + ( $cardinfo->{credit_limit} ); - $available = ( $balance - $numberinfo->{connectfee} ) / 100; + $available = ( $balance - $numberinfo->{connectcost} ) / 100; } if ( $available > 0 && $numberinfo->{cost} > 0 ) { $timelimit = ( ( $available / $numberinfo->{cost} ) * 60 ); @@ -246,19 +268,18 @@ verbosity => $verbosity ); if ( $brandinfo->{reseller} ne "" ) { - ASTPP->debug( + $ASTPP->debug( debug => "THIS BRAND BELONGS TO $brandinfo->{reseller}!", verbosity => $verbosity ); my $carddata = &get_account( $astpp_db, $brandinfo->{reseller} ); - # ($callstatus, $maxlength) = &max_length($astpp_db, $config, $carddata, $phoneno); # my $routeinfo = &get_route( $astpp_db, $config, $phoneno, $carddata->{pricelist},$carddata ); my $minimumcharge = $numberinfo->{cost}; my $belongs_to_reseller = 1; while ( $belongs_to_reseller == 1 ) { $ASTPP->debug( - debug => "FINDING LIMIT FOR: $carddata->{reseller}", + debug => "FINDING LIMIT FOR: $carddata->{number}", verbosity => $verbosity ); push @resellerlist, $carddata->{number}; @@ -307,18 +328,16 @@ ); } $ASTPP->debug( debug => "TIMELIMIT: $timelimit", verbosity => $verbosity ); - my $minutes = $timelimit / 60; + my $minutes = sprintf( "%.0f", $timelimit /60 ); $ASTPP->debug( debug => "MINUTES: $minutes", verbosity => $verbosity ); if ( $minutes > 0 && $config->{calling_cards_timelimit_announce} == 1 ) { - my $minutes = $timelimit / 60; - $minutes = sprintf( "%.0f", $minutes ); $session->streamFile( $sound->{call_will_last} ); if ( $minutes == 1 ) { - $session->execute( "phrase", "spell," . $minutes ); + $session->execute( "say", "en number pronounced " . $minutes ); $session->streamFile( $sound->{minute} ); } elsif ( $minutes > 1 ) { - $session->execute( "phrase", "spell," . $minutes ); + $session->execute( "say", "en number pronounced " . $minutes ); $session->streamFile( $sound->{minutes} ); } } @@ -331,14 +350,14 @@ debug => "Available: $available", verbosity => $verbosity ); - $ASTPP->debug( debug => "Balance: $balance", verbosity => $verbosity ); - $ASTPP->debug( debug => "Max Time: $maxtime", verbosity => $verbosity ); +# $ASTPP->debug( debug => "Balance: $balance", verbosity => $verbosity ); +# $ASTPP->debug( debug => "Max Time: $maxtime", verbosity => $verbosity ); return $timelimit; } sub say_balance() { #Calculate and say the card balance. my ($cardinfo) = @_; - my ( $connectfee, $cost, $included, $sub_balance, $balance, $main_balance ); + my ( $connectcost, $cost, $included, $sub_balance, $balance, $main_balance ); if ( $cc == 0 ) { $balance = $cardinfo->{value} - $cardinfo->{used}; } @@ -347,25 +366,32 @@ $balance = ( $balance * -1 ) + ( $cardinfo->{credit_limit} ); } if ( $balance > 0 ) { - $balance = $balance / 10000; - $balance = sprintf( "%.2f", $balance ); - $sub_balance = substr( $balance, -2, 2 ); - $main_balance = substr( $balance, 0, -2 ); + my @split_balance = split( /\./, ( sprintf( "%.2f", $balance / 10000) ) ); +# $balance = $balance / 10000; +# $balance = sprintf( "%.2f", $balance ); +# $sub_balance = substr( $balance, -2, 2 ); +# $main_balance = substr( $balance, 0, -2 ); + if ($config->{debug} == 1) { + print STDERR "BALANCE: $balance \n"; + print STDERR "BALANCE: " . sprintf( "%.0f", $balance / 10000) . "\n"; + print STDERR "SPLIT_BALANCE 0: @split_balance[0] \n"; + print STDERR "SPLIT_BALANCE 1: @split_balance[1] \n"; + } $session->streamFile( $sound->{card_has_balance_of} ); - if ( $main_balance == 1 ) { - $session->execute( "phrase", "spell," . $main_balance ); + if ( @split_balance[0] == 1 ) { + $session->execute( "say", "en number pronounced " . @split_balance[0] ); $session->streamFile( $sound->{main_currency} ); } - elsif ( $main_balance > 1 ) { - $session->execute( "phrase", "spell," . $main_balance ); + elsif ( @split_balance[0] > 1 ) { + $session->execute( "say", "en number pronounced " . @split_balance[0] ); $session->streamFile( $sound->{main_currency_plural} ); } - if ( $sub_balance == 1 ) { - $session->execute( "phrase", "spell," . $sub_balance ); + if ( @split_balance[1] == 1 ) { + $session->execute( "say", "en number pronounced " . @split_balance[1] ); $session->streamFile( $sound->{sub_currency} ); } - elsif ( $sub_balance > 1 ) { - $session->execute( "phrase", "spell," . $sub_balance ); + elsif ( @split_balance[1] > 1 ) { + $session->execute( "say", "en number pronounced " . @split_balance[1] ); $session->streamFile( $sound->{sub_currency_plural} ); } } @@ -419,24 +445,35 @@ $count = 0; foreach my $route (@outboundroutes) { my $callstart = localtime(); - my ($accountcode); $callstart = &prettytimestamp if $cc == 1; - $session->execute( "sched_hangup", "+" . $timelimit * 60 ); + $session->execute( "set", "execute_on_answer=sched_hangup +" . $timelimit ); +# $session->execute( "export", "execute_on_answer=sched_hangup +" . $timelimit ); +# $session->execute( "set", "execute_on_answer=sched_broadcast", "+" . $timelimit - 60 . " one_minute_left.wav both"); + my ( $xml_string, $data_string ) = $ASTPP->fs_dialplan_xml_bridge( destination_number => $destination, route_prepend => $route->{prepend}, trunk_name => $route->{trunk} ); + my $sql = $astpp_db->prepare( "SELECT provider FROM trunks WHERE name = '" + . $route->{trunk} ."'" ); + $sql->execute; + my $trunkdata = $sql->fetchrow_hashref; + $sql->finish; + my ( $dialedtime, $uniqueid, $answeredtime, $clid ); + $session->execute( "export", "outbound_route=$route->{id}" ); + $session->execute( "export", "provider=$trunkdata->{provider}" ); + $session->execute( "export", "trunk=$route->{trunk}" ); + $session->execute( "export", "callingcard_destination=$destination" ); + if ( $cc == 1 ) { - $session->execute( "export", "accountcode=CC:$cardinfo->{number}" ); + $session->execute( "export", "accountcode=$cardinfo->{accountcode}" ); $session->execute( "export", "callingcard=$cardinfo->{number}" ); - $session->execute( "export", "calldestination=$destination" ); } else { - $session->execute( "export", "accountcode=CC:$cardinfo->{cardnumber}" ); + $session->execute( "export", "accountcode=$cardinfo->{accountcode}" ); $session->execute( "export", "callingcard=$cardinfo->{cardnumber}" ); - $session->execute( "export", "calldestination=$destination" ); } $session->execute( "bridge", "$data_string" ); return 1; @@ -510,14 +547,10 @@ sub print_console() #Dump string to the console { my ($output) = @_; - freeswitch::consoleLog( "ASTPP", $output . "\n" ); +# $session->consoleLog( "ASTPP", $output . "\n" ); + print STDERR "ASTPP:" . $output . "\n"; } -sub say() { - my ( $phrase, $say ) = @_; - $session->execute( "phrase", $phrase . "," . $say ); -} - ################# Program Starts Here ################################# my ( $cardnum, $pin, $destination, $connectsurcharge, $perminsurcharge, $brand ) = @ARGV; @@ -531,7 +564,10 @@ $ASTPP->debug( debug => "Vars: " . $vars ); return 1 if ( !$session->ready() ); -if ( $cardnum && $cardnum ne "" ) { +$cardnum = $session->getVariable("callingcard_number"); + + +if ( $cardnum && $cardnum > 0 ) { $ASTPP->debug( debug => "We recieved a cardnumber from the dialplan", verbosity => $verbosity @@ -623,10 +659,22 @@ &load_config_db_reseller( $astpp_db, $config, $brandinfo->{reseller} ); } $config = &load_config_db_brand( $astpp_db, $config, $cardinfo->{brand} ); -$pricelistinfo = &get_pricelist( $astpp_db, $brandinfo->{pricelist} ) - if $cc == 0; -$pricelistinfo = &get_pricelist( $astpp_db, $cardinfo->{pricelist} ) - if $cc == 1; +#$config->{debug} = 1; +print STDERR "CC: " . $cc ."\n" if $config->{debug} == 1; +if ($cc == 0) { + $pricelistinfo = &get_pricelist( $astpp_db, $brandinfo->{pricelist} ); + if ( $brandinfo->{reseller} ne "" ) { + print STDERR "SETTING ACCOUNTCODE TO: RESELLER " . $brandinfo->{reseller} . "\n" if $config->{debug} == 1; + $cardinfo->{accountcode} = $brandinfo->{reseller}; + } else { + print STDERR "SETTING ACCOUNTCODE TO: SYSTEM DEFAULT " . $config->{callout_accountcode} . "\n" if $config->{debug} == 1; + $cardinfo->{accountcode} = $config->{callout_accountcode}; + } +} elsif ($cc == 1) { + $pricelistinfo = &get_pricelist( $astpp_db, $cardinfo->{pricelist} ); + print STDERR "SETTING ACCOUNTCODE TO: ASTPP ACCOUNT " . $cardinfo->{number} . "\n" if $config->{debug} == 1; + $cardinfo->{accountcode} = $cardinfo->{number}; +} if ( $destination && $destination ne "" ) { $numberinfo = &get_route( $astpp_db, $config, $destination, $brandinfo->{pricelist}, @@ -650,11 +698,15 @@ $session->streamFile( $sound->{destination_incorrect} ); } else { + $ASTPP->debug( debug => "COST: " . $numberinfo->{cost}); $numberinfo->{cost} = $numberinfo->{cost} + $perminsurcharge - if $perminsurcharge ne ""; + if $perminsurcharge > 0; + $ASTPP->debug( debug => "COST: " . $numberinfo->{cost}); + $ASTPP->debug( debug => "CONNECTION: " . $numberinfo->{connectcost}); $numberinfo->{connectcost} = $numberinfo->{connectcost} + $connectsurcharge - if $connectsurcharge ne ""; + if $connectsurcharge > 0; + $ASTPP->debug( debug => "CONNECTION: " . $numberinfo->{connectcost}); } $retries++; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |