summaryrefslogtreecommitdiff
path: root/httemplate/misc
diff options
context:
space:
mode:
authorivan <ivan>2009-01-05 00:26:54 +0000
committerivan <ivan>2009-01-05 00:26:54 +0000
commit125fb1a284ae96b46fe433c418aafa87862c4382 (patch)
treecb9485c9cfd7e685bc63ea40fe214f80c18407b1 /httemplate/misc
parentc23d6e1673dbec98fe9d778ee55962d2cbd145d5 (diff)
add rate copying, RT#4431
Diffstat (limited to 'httemplate/misc')
-rw-r--r--httemplate/misc/copy-rate_detail.html61
-rw-r--r--httemplate/misc/process/copy-rate_detail.html61
2 files changed, 122 insertions, 0 deletions
diff --git a/httemplate/misc/copy-rate_detail.html b/httemplate/misc/copy-rate_detail.html
new file mode 100644
index 000000000..3d328ce59
--- /dev/null
+++ b/httemplate/misc/copy-rate_detail.html
@@ -0,0 +1,61 @@
+<% include( '/elements/header.html', 'Copy rates between plans', menubar(
+ 'View all rate plans' => "${p}browse/rate.cgi",
+ ))
+%>
+
+<% include('/elements/error.html') %>
+
+<FORM ACTION="process/copy-rate_detail.html">
+
+<% ntable('#cccccc') %>
+
+ <% include( '/elements/tr-justtitle.html', 'value' => 'Copy rates' ) %>
+
+ <% include( '/elements/tr-select-rate.html',
+ 'label' => 'From rate plan',
+ 'element_name' => 'src_ratenum',
+ )
+ %>
+
+ <% include( '/elements/tr-select-rate.html',
+ 'label' => 'To rate plan',
+ 'element_name' => 'dst_ratenum',
+ )
+ %>
+
+ <TR>
+ <TD COLSPAN=2>Copy country codes</TD>
+ </TR>
+
+ <TR>
+ <TD COLSPAN=2>
+
+ <% include( '/elements/checkboxes.html',
+ 'names_list' => [ FS::rate_prefix->all_countrycodes ],
+ 'element_name_prefix' => 'countrycode',
+ )
+ %>
+ </TD>
+ </TR>
+
+ <TR>
+ <TD COLSPAN=2 ALIGN="center">
+ <INPUT TYPE="submit" VALUE="Copy rates">
+ </TD>
+ </TR>
+
+</TABLE>
+
+</FORM>
+
+<% include('/elements/footer.html') %>
+
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+#should have some javascript that enables submit button only when both src & dst
+#rates are chosen
+
+</%init>
diff --git a/httemplate/misc/process/copy-rate_detail.html b/httemplate/misc/process/copy-rate_detail.html
new file mode 100644
index 000000000..87a674566
--- /dev/null
+++ b/httemplate/misc/process/copy-rate_detail.html
@@ -0,0 +1,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>