[Astpp-commit] SF.net SVN: astpp:[2331] trunk/scripts/astpp-common.pl
Brought to you by:
darrenkw
From: <dar...@us...> - 2011-01-15 21:48:04
|
Revision: 2331 http://astpp.svn.sourceforge.net/astpp/?rev=2331&view=rev Author: darrenkw Date: 2011-01-15 21:47:57 +0000 (Sat, 15 Jan 2011) Log Message: ----------- Add more FreeSWITCH support esp vendor rating support. Modified Paths: -------------- trunk/scripts/astpp-common.pl Modified: trunk/scripts/astpp-common.pl =================================================================== --- trunk/scripts/astpp-common.pl 2011-01-15 21:45:05 UTC (rev 2330) +++ trunk/scripts/astpp-common.pl 2011-01-15 21:47:57 UTC (rev 2331) @@ -98,6 +98,7 @@ . $astpp_db->quote($status) . " WHERE cardnumber = " . $astpp_db->quote( $cardinfo->{cardnumber} ); + print STDERR $sql ."\n"; $astpp_db->do($sql); } @@ -1256,7 +1257,7 @@ my $didinfo = &get_did_reseller($astpp_db,$did,$accountdata->{reseller}); my $did_min_available = $didinfo->{monthlycost} + $didinfo->{setup} + $didinfo->{disconnectionfee}; my $credit = &accountbalance( $astpp_db, $accountdata->{number} ); # Find the available credit to the customer. - print STDERR "Account Balance: $credit" if $config->{debug} == 1; + print STDERR "Account Balance: " . $credit . "\n" if $config->{debug} == 1; $credit = ($credit * -1) + ($accountdata->{credit_limit}); # Add on the accounts credit limit. if ($credit < $did_min_available) { return gettext ("Account: " . $accountdata->{number} . " does not have enough funds available."); @@ -1305,7 +1306,7 @@ } else { my $did_min_available = $didinfo->{monthlycost} + $didinfo->{setup} + $didinfo->{disconnectionfee}; my $credit = &accountbalance( $astpp_db, $accountinfo->{number} ); # Find the available credit to the customer. - print STDERR "Account Balance: $credit" if $config->{debug} == 1; + print STDERR "Account Balance: " . $credit . "\n" if $config->{debug} == 1; $credit = ($credit * -1) + ($accountinfo->{credit_limit}); # Add on the accounts credit limit. if ($credit < $did_min_available) { return gettext ("Account: " . $accountinfo->{number} . " does not have enough funds available."); @@ -1846,9 +1847,9 @@ $record = &search_for_route($astpp_db,$config,$destination,$config->{default_brand}); print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; } - print STDERR "Route: $record->{comment} Cost: $record->{cost} Pricelist: $record->{pricelist} Pattern: $record->{pattern}\n" if $record; + print STDERR "Route: $record->{comment} Cost: $record->{cost} Pricelist: $record->{pricelist} Pattern: $record->{pattern}\n" if $record->{pattern}; } - if ( $record->{inc} eq "" || $record->{inc} == 0 ) { + if ($record->{inc} &&( $record->{inc} eq "" || $record->{inc} == 0 )) { my $branddata = &get_pricelist( $astpp_db, $pricelist); $record->{inc} = $branddata->{inc}; } @@ -3750,12 +3751,12 @@ } print STDERR "Found pattern: $numdata->{pattern}\n" if $config->{debug} == 1; $credit = &accountbalance( $astpp_db, $carddata->{number} ); # Find the available credit to the customer. - print STDERR "Account Balance: " . $credit * 10000 if $config->{debug} == 1; + print STDERR "Account Balance: " . $credit * 10000 . "\n" if $config->{debug} == 1; $credit_limit = $carddata->{credit_limit} * 10000; - print STDERR "Credit Limit: $credit_limit" if $config->{debug} == 1; + print STDERR "Credit Limit: " . $credit_limit . "\n" if $config->{debug} == 1; $credit = ($credit * -1) + ($credit_limit); # Add on the accounts credit limit. #$credit = $credit / $carddata->{maxchannels} if $carddata->{maxchannels} > 0; - print STDERR "Credit: $credit \n" if $config->{debug} == 1; + print STDERR "Credit: " . $credit . "\n" if $config->{debug} == 1; if ($branddata->{markup} > 0) { $numdata->{connectcost} = $numdata->{connectcost} * ( ( $branddata->{markup} / 10000 ) + 1 ); @@ -3767,22 +3768,15 @@ } if ( $numdata->{cost} > 0 ) { $maxlength = ( ( $credit - $numdata->{connectcost} ) / $numdata->{cost} ); - if ($config->{call_max_length} && $maxlength < $config->{call_max_length} / 1000){ + if ($config->{call_max_length} && ($maxlength > $config->{call_max_length} / 1000)){ + print STDERR "LIMITING CALL TO CONFIG MAX LENGTH \n" if $config->{debug} == 1; $maxlength = $config->{call_max_length} / 1000 / 60; } } else { + print STDERR "CALL IS FREE - ASSIGNING MAX LENGHT \n" if $config->{debug} == 1; $maxlength = $config->{max_free_length}; # If the call is set to be free then assign a max length. } - if ( $numdata->{cost} > 0 ) { - $maxlength = ( ( $credit - $numdata->{connectcost} ) / $numdata->{cost} ); - if ($config->{call_max_length} && $maxlength < $config->{call_max_length} / 1000){ - $maxlength = $config->{call_max_length} / 1000 / 60; - } - } - else { - $maxlength = $config->{max_free_length}; # If the call is set to be free then assign a max length. - } return (1, $maxlength); } @@ -3887,7 +3881,7 @@ $sound->{cardnumber_incorrect} = $location . "astpp-badaccount.gsm"; #Incorrect card number. $sound->{pin} = $location . "astpp-pleasepin.gsm"; #Please enter your pin followed by pound. $sound->{pin_incorrect} = $location . "astpp-invalidpin.gsm"; #Incorrect pin. -$sound->{goodbye} = $location . "goodbye.gsm"; #Goodbye. +$sound->{goodbye} = $location . "conf-goodbye.wav"; #Goodbye. $sound->{destination} = $location . "astpp-phonenum.gsm"; #Please enter the number you wish to dial followed by pound. $sound->{destination_incorrect} = $location . "astcc-badphone.gsm"; #Phone number not found! $sound->{card_inuse} = $location . "astpp-in-use.gsm"; #This card is presently being used. @@ -3898,7 +3892,9 @@ $sound->{sub_currency_plural} = $location . "astpp-cents.gsm"; #cents $sound->{per} = $location . "astpp-per.gsm"; #per $sound->{minute} = $location . "astpp-minute.gsm"; #Minute -$sound->{minutes} = $location . "astpp-minutes.gsm"; #Minutes +#Changed By Joseph Watson +#$sound->{minutes} = $location . "astpp-minutes.gsm"; #Minutes +$sound->{minutes} = $location . "minutes.wav"; #Minutes $sound->{second} = $location . "astpp-second.gsm"; #Second $sound->{seconds} = $location . "astpp-seconds.gsm"; #Seconds $sound->{a_connect_charge} = $location . "astpp-connectcharge.gsm"; #A connect charge of @@ -3918,7 +3914,7 @@ $sound->{noanswer} = $location . "astpp-noanswer-tryagain.gsm"; #There was no answer, Press 1 to try again. $sound->{badnumber} = $location . "astpp-badnumber.gsm"; # "Calls from this location are blocked!" $sound->{used_elsewhere} = $location . "astpp-used-elsewhere.gsm"; # "This location has been used already." -$sound->{goodbye} = $location . "goodbye.gsm"; # "Goodbye" +$sound->{goodbye} = $location . "conf-goodbye.wav"; # "Goodbye" $sound->{callback_performed} = $location . "astpp-callback-performed.gsm"; # "This callback has been performed please disconnect now" $sound->{cardnumber} = $location . "astpp-accountnum.gsm"; #Please enter your card number followed by pound. $sound->{cardnumber_incorrect} = $location . "astpp-badaccount.gsm"; #Incorrect card number. @@ -3927,7 +3923,7 @@ $sound->{point} = $location . "astcc-point.gsm"; #point. $sound->{register_ani} = $location . "astpp-register.gsm"; # "Register ANI to this card? Press 1 for yes or any other key for no." $sound->{card_has_expired} = $location . "astpp_expired.gsm"; #"This card has expired" -$sound->{card_is_empty} = $location . "astpp-empty.gsm"; #This card is empty +$sound->{card_is_empty} = $location . "astpp-card-is-empty.gsm"; #This card is empty $sound->{where_to_call} = $location . "astpp-where-to-call.gsm" ; #Press 1 to receive a call at the number you called from or registered @@ -3996,37 +3992,23 @@ ######## Call Rating ################################ sub cleanup_cdrs_fs() { my ($cdr_db, $config) = @_; - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0' WHERE disposition REGEXP 'ORIGINATOR_CANCEL'"); - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0' WHERE disposition REGEXP 'CALL_REJECTED'"); - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0' WHERE disposition REGEXP 'USER_NOT_REGISTERED'"); - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0' WHERE disposition REGEXP 'CHAN_NOT_IMPLEMENTED'"); - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0' WHERE disposition REGEXP 'INVALID_NUMBER_FORMAT'"); - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0' WHERE disposition REGEXP 'UNALLOCATED_NUMBER'"); - if ($config->{trackvendorcharges} == 1) { - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET vendor = '0' WHERE disposition REGEXP 'ORIGINATOR_CANCEL'"); - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET vendor = '0' WHERE disposition REGEXP 'CALL_REJECTED'"); - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET vendor = '0' WHERE disposition REGEXP 'USER_NOT_REGISTERED'"); - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET vendor = '0' WHERE disposition REGEXP 'CHAN_NOT_IMPLEMENTED'"); - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET vendor = '0' WHERE disposition REGEXP 'INVALID_NUMBER_FORMAT'"); - $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0' WHERE disposition REGEXP 'UNALLOCATED_NUMBER'"); - } + $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'ORIGINATOR_CANCEL'"); + $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'CALL_REJECTED'"); + $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'USER_NOT_REGISTERED'"); + $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'CHAN_NOT_IMPLEMENTED'"); + $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'INVALID_NUMBER_FORMAT'"); + $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'NORMAL_TEMPORARY_FAILURE'"); + $cdr_db->do("UPDATE $config->{freeswitch_cdr_table} SET cost = '0',vendor='0' WHERE duration = '0' and billsec='0'"); } sub cleanup_cdrs() { my ($cdr_db, $config) = @_; # First we cleanup all calls that are not answered if ($config->{astcdr} == 1) { - $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET cost = '0' WHERE disposition REGEXP 'NO ANSWER'"); - $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET cost = '0' WHERE disposition REGEXP 'BUSY'"); - $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET cost = '0' WHERE disposition REGEXP 'FAILED'"); - $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET cost = '0' WHERE disposition REGEXP 'CONGESTION'"); - $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET cost = '0' WHERE disposition REGEXP 'CANCEL'"); - if ($config->{trackvendorcharges} == 1) { - $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET vendor = '0' WHERE disposition REGEXP 'NO ANSWER'"); - $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET vendor = '0' WHERE disposition REGEXP 'BUSY'"); - $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET vendor = '0' WHERE disposition REGEXP 'FAILED'"); - $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET vendor = '0' WHERE disposition REGEXP 'CONGESTION'"); - $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET vendor = '0' WHERE disposition REGEXP 'CANCEL'"); - } + $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'NO ANSWER'"); + $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'BUSY'"); + $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'FAILED'"); + $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'CONGESTION'"); + $cdr_db->do("UPDATE $config->{asterisk_cdr_table} SET cost = '0',vendor='0' WHERE disposition REGEXP 'CANCEL'"); if ($config->{thirdlane_mods} == 1) { $cdr_db->do("UPDATE $config->{cdr_table} SET accountcode = userfield WHERE (accountcode IS NULL or accountcode = '')"); } @@ -4058,6 +4040,7 @@ 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, $vars, @output ) = @_; my ( $increment, $numdata, $package, $notes, $status ); + $status = 0; print STDERR "----------------------------------------------------------------\n"; print STDERR "uniqueid: $cdrinfo->{uniqueid}, cardno: $carddata->{number}, phoneno: $cdrinfo->{dst}, Userfield: $cdrinfo->{userfield}\n"; @@ -4070,7 +4053,6 @@ # print STDERR "Destination: $cdrinfo->{dst} \n"; # } $numdata = &get_route( $astpp_db, $config, $cdrinfo->{dst}, $carddata->{pricelist}, $carddata, $cdrinfo->{userfield} ); - print STDERR "PATTERN: $numdata->{pattern}"; if ( !$numdata->{pattern} ) { &save_cdr( $config, $cdr_db, $cdrinfo->{uniqueid}, "error",$cdrinfo->{dst} ) if !$vars && $config->{astcdr} == 1; print STDERR "ERROR - ERROR - ERROR - ERROR - ERROR \n"; @@ -4078,7 +4060,7 @@ print STDERR "----------------------------------------------------------------\n"; } else { - print STDERR "FOUND A MATCHING PATTERN.\n"; + print STDERR "FOUND A MATCHING PATTERN: $numdata->{pattern}"; my $branddata = &get_pricelist( $astpp_db, $carddata->{pricelist} ); print STDERR "pricelistData: $branddata->{name} $branddata->{markup} $branddata->{inc} $branddata->{status}\n"; @@ -4260,6 +4242,7 @@ print STDERR "----------------------\n"; } elsif ( $cdrinfo->{accountcode} ) { + $status = 0; $status = &rating( $astpp_db, $cdr_db,$config, $cdrinfo, $carddata, $vars); $cdrinfo = &get_cdr( $config, $cdr_db, $uniqueid ) if !$vars; if ( $status == 1 ) { @@ -4344,10 +4327,10 @@ my ( $astpp_db, $cdr_db, $config, $phrase, $uniqueid, $vars ) = @_; my ($sql,$tmp); print STDERR "Vendor Rating Uniqueid: " . $uniqueid . "\n"; - if(!$uniqueid) { - $tmp = "SELECT * FROM $config->{freeswitch_cdr_table} WHERE vendor IN ('error','none')"; - } else { + if($uniqueid) { $tmp = "SELECT * FROM $config->{freeswitch_cdr_table} WHERE uniqueid = '$uniqueid'"; + } else { + $tmp = "SELECT * FROM $config->{freeswitch_cdr_table} WHERE vendor IN ('error','none')"; } print STDERR $tmp . "\n" if $config->{debug} == 1; $sql = $cdr_db->prepare($tmp); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |