From 2419a740ea77d7c1fd2151dbf8822fc40fd94053 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 24 Feb 2010 23:32:47 +0000 Subject: [PATCH] RT#7132: bulk increment package bill dates --- httemplate/misc/bulk_pkg_increment_bill.cgi | 50 ++++++++++++++ .../misc/process/bulk_pkg_increment_bill.cgi | 76 ++++++++++++++++++++++ httemplate/search/cust_pkg.cgi | 35 ++++++---- 3 files changed, 149 insertions(+), 12 deletions(-) create mode 100755 httemplate/misc/bulk_pkg_increment_bill.cgi create mode 100755 httemplate/misc/process/bulk_pkg_increment_bill.cgi diff --git a/httemplate/misc/bulk_pkg_increment_bill.cgi b/httemplate/misc/bulk_pkg_increment_bill.cgi new file mode 100755 index 000000000..79bc0cd3e --- /dev/null +++ b/httemplate/misc/bulk_pkg_increment_bill.cgi @@ -0,0 +1,50 @@ +<% include('/elements/header-popup.html', "Increment Bill Date") %> + +% if ( $cgi->param('error') ) { + Error: <% $cgi->param('error') %> +

+% } + +
+ +%# some false laziness w/search/cust_pkg.cgi + + +% for my $param (qw(agentnum custnum magic status classnum custom censustract)) { + +% } +% +% foreach my $pkgpart ($cgi->param('pkgpart')) { + +% } +% +% foreach my $field (qw( setup last_bill bill adjourn susp expire cancel )) { +% + "> + "> + "> + "> +% } + +<% ntable('#cccccc') %> + + + Days to increment: + + + + + +
+ + +
+ + + +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Bulk change customer packages'); + + diff --git a/httemplate/misc/process/bulk_pkg_increment_bill.cgi b/httemplate/misc/process/bulk_pkg_increment_bill.cgi new file mode 100755 index 000000000..0d8417b26 --- /dev/null +++ b/httemplate/misc/process/bulk_pkg_increment_bill.cgi @@ -0,0 +1,76 @@ +%if ($error) { +% $cgi->param('error', $error); +<% $cgi->redirect(popurl(2). 'bulk_pkg_increment_bill.cgi?'. $cgi->query_string ) %> +%} else { +<% header('Packages Adjusted') %> + + +% } +<%init> + +local $FS::UID::AutoCommit = 0; +my $dbh = dbh; +my $error; + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Bulk change customer packages') + and $FS::CurrentUser::CurrentUser->access_right('Edit customer package dates'); + +my $days = $cgi->param('days') or die "missing parameter: days"; +$days > 0 or $error = "Number of days must be > 0"; + +my %search_hash = (); + +$search_hash{'query'} = $cgi->param('query'); + +for my $param (qw(agentnum magic status classnum pkgpart)) { + $search_hash{$param} = $cgi->param($param) + if $cgi->param($param); +} + +### +# parse dates +### + +#false laziness w/report_cust_pkg.html +# and, now, w/bulk_change_pkg.cgi +my %disable = ( + 'all' => {}, + 'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, }, + 'active' => { 'susp'=>1, 'cancel'=>1 }, + 'suspended' => { 'cancel' => 1 }, + 'cancelled' => {}, + '' => {}, +); + +foreach my $field (qw( setup last_bill bill adjourn susp expire cancel )) { + + my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field); + + next if $beginning == 0 && $ending == 4294967295 + or $disable{$cgi->param('status')}->{$field}; + + $search_hash{$field} = [ $beginning, $ending ]; + +} + +if(!$error) { + foreach my $cust_pkg (qsearch(FS::cust_pkg->search(\%search_hash))) { + next if ! $cust_pkg->bill; + my $new_cust_pkg = FS::cust_pkg->new({ $cust_pkg->hash }); + $new_cust_pkg->bill($new_cust_pkg->bill + $days*86400); + $error = $new_cust_pkg->replace($cust_pkg); + + if($error) { + $cgi->param("error",substr($error, 0, 512)); + $dbh->rollback; + return; + } + } + + $dbh->commit; +} + + diff --git a/httemplate/search/cust_pkg.cgi b/httemplate/search/cust_pkg.cgi index ee4c82d8e..2a4366ae4 100755 --- a/httemplate/search/cust_pkg.cgi +++ b/httemplate/search/cust_pkg.cgi @@ -257,18 +257,29 @@ my $html_init = include('/elements/init_overlib.html'); my $extra_choices = sub { my $query = shift; - - return '' unless - $FS::CurrentUser::CurrentUser->access_right('Bulk change customer packages'); - - '

'. - include( '/elements/popup_link.html', - 'label' => 'Change these packages', - 'action' => "${p}misc/bulk_change_pkg.cgi?$query", - 'actionlabel' => 'Change Packages', - 'width' => 763, - 'height' => 336, - ); + my $text = ''; + + if( $FS::CurrentUser::CurrentUser->access_right('Bulk change customer packages') ) { + $text .= '

'. + include( '/elements/popup_link.html', + 'label' => 'Change these packages', + 'action' => "${p}misc/bulk_change_pkg.cgi?$query", + 'actionlabel' => 'Change Packages', + 'width' => 569, + 'height' => 210, + ); + if( $FS::CurrentUser::CurrentUser->access_right('Edit customer package dates') ) { + $text .= '
'. + include( '/elements/popup_link.html', + 'label' => 'Increment next bill date', + 'action' => "${p}misc/bulk_pkg_increment_bill.cgi?$query", + 'actionlabel' => 'Increment Bill Date', + 'width' => 569, + 'height' => 210, + ); + } + } + return $text; }; -- 2.11.0