2 %# <% $cgi->redirect(popurl(2).'copy-rate_detail.html?'. $cgi->query_string ) %>
4 <% include('/elements/header.html', 'Rates copied',
5 menubar( 'View all rate plans' => popurl(3).'browse/rate.cgi' ),
11 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
13 $cgi->param('src_ratenum') =~ /^(\d+)$/ or die 'Illegal src_ratenum';
16 $cgi->param('dst_ratenum') =~ /^(\d+)$/ or die 'Illegal src_ratenum';
19 my @countrycodes = map { /^countrycode(\d+)$/ or die; $1 }
20 grep { /^countrycode(\d+)$/ && $cgi->param($_) }
23 foreach my $countrycode ( @countrycodes ) {
25 my @src_rate_detail = qsearch({
26 'table' => 'rate_detail',
27 'addl_from' => 'JOIN rate_region'.
28 ' ON ( rate_detail.dest_regionnum = rate_region.regionnum )',
29 'hashref' => { 'ratenum' => $src_ratenum },
31 "AND 0 < ( SELECT COUNT(*) FROM rate_prefix
32 WHERE rate_prefix.regionnum = rate_region.regionnum
33 AND countrycode = '$countrycode'
38 foreach my $src_rate_detail ( @src_rate_detail ) {
41 'ratenum' => $dst_ratenum,
42 map { $_ => $src_rate_detail->get($_) }
43 qw( orig_regionnum dest_regionnum )
46 my $dst_rate_detail = qsearchs( 'rate_detail', \%hash)
47 || new FS::rate_detail \%hash;
49 $dst_rate_detail->$_( $src_rate_detail->get($_) )
50 foreach qw( min_included conn_charge conn_sec min_charge sec_granularity
51 conn_cost min_cost classnum );
53 my $method = $dst_rate_detail->ratedetailnum ? 'replace' : 'insert';
55 my $error = $dst_rate_detail->$method();
57 die $error if $error; # "shouldn't" happen