blob: 87a67456686eac08f32d58f5d7eb77d3f3fae961 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
%# if ( $error ) {
%# <% $cgi->redirect(popurl(2).'copy-rate_detail.html?'. $cgi->query_string ) %>
%# } else {
<% include('/elements/header.html', 'Rates copied',
menubar( 'View all rate plans' => popurl(3).'browse/rate.cgi' ),
) %>
%# }
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
$cgi->param('src_ratenum') =~ /^(\d+)$/ or die 'Illegal src_ratenum';
my $src_ratenum = $1;
$cgi->param('dst_ratenum') =~ /^(\d+)$/ or die 'Illegal src_ratenum';
my $dst_ratenum = $1;
my @countrycodes = map { /^countrycode(\d+)$/ or die; $1 }
grep { /^countrycode(\d+)$/ && $cgi->param($_) }
$cgi->param;
foreach my $countrycode ( @countrycodes ) {
my @src_rate_detail = qsearch({
'table' => 'rate_detail',
'addl_from' => 'JOIN rate_region'.
' ON ( rate_detail.dest_regionnum = rate_region.regionnum )',
'hashref' => { 'ratenum' => $src_ratenum },
'extra_sql' =>
"AND 0 < ( SELECT COUNT(*) FROM rate_prefix
WHERE rate_prefix.regionnum = rate_region.regionnum
AND countrycode = '$countrycode'
)
",
});
foreach my $src_rate_detail ( @src_rate_detail ) {
my %hash = (
'ratenum' => $dst_ratenum,
map { $_ => $src_rate_detail->get($_) }
qw( orig_regionnum dest_regionnum )
);
my $dst_rate_detail = qsearchs( 'rate_detail', \%hash)
|| new FS::rate_detail \%hash;
$dst_rate_detail->$_( $src_rate_detail->get($_) )
foreach qw( min_included min_charge sec_granularity classnum );
my $method = $dst_rate_detail->ratedetailnum ? 'replace' : 'insert';
my $error = $dst_rate_detail->$method();
die $error if $error; # "shouldn't" happen
}
}
</%init>
|