[freeside-commits] branch master updated. 0bd6fd8b74c3cb6a7abf01ba5974d2d9399da3ab

Ivan Kohler ivan at freeside.biz
Mon Oct 21 12:21:59 PDT 2019


The branch, master has been updated
       via  0bd6fd8b74c3cb6a7abf01ba5974d2d9399da3ab (commit)
      from  95cffb2e514c6117fc3eb111581d387b5d0b4e77 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0bd6fd8b74c3cb6a7abf01ba5974d2d9399da3ab
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Mon Oct 21 12:20:00 2019 -0700

    bulk package cancellation

diff --git a/httemplate/misc/bulk_cancel_pkg.cgi b/httemplate/misc/bulk_cancel_pkg.cgi
new file mode 100644
index 000000000..5499af19d
--- /dev/null
+++ b/httemplate/misc/bulk_cancel_pkg.cgi
@@ -0,0 +1,83 @@
+<% include('/elements/header-popup.html', "Cancel Packages") %>
+
+% if ( $cgi->param('error') ) {
+  <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
+  <BR><BR>
+% }
+
+<FORM NAME     = "OneTrueForm"
+      METHOD   = POST
+      ACTION   = "<% $p %>misc/process/bulk_cancel_pkg.cgi"
+      onSubmit = "document.OneTrueForm.submit.disabled=true;"
+>
+
+%# some false laziness w/search/cust_pkg.cgi
+
+<INPUT TYPE="hidden" NAME="query" VALUE="<% $cgi->keywords |h %>">
+% for my $param (
+%   qw(
+%     agentnum cust_status cust_main_salesnum salesnum custnum magic status
+%     custom pkgbatch zip reasonnum
+%     477part 477rownum date
+%     report_option
+%   ),
+%   grep { /^location_\w+$/ || /^report_option_any/ } $cgi->param
+% ) {
+  <INPUT TYPE="hidden" NAME="<% $param %>" VALUE="<% $cgi->param($param) |h %>">
+% }
+%
+% for my $param (qw( censustract censustract2 ) ) {
+%   next unless grep { $_ eq $param } $cgi->param;
+  <INPUT TYPE="hidden" NAME="<% $param %>" VALUE="<% $cgi->param($param) |h %>">
+% }
+%
+% for my $param (qw( pkgpart classnum refnum towernum )) {
+%   foreach my $value ($cgi->param($param)) {
+      <INPUT TYPE="hidden" NAME="<% $param %>" VALUE="<% $value |h %>">
+%   }
+% }
+%
+% foreach my $field (qw( setup last_bill bill adjourn susp expire contract_end change_date cancel active )) {
+% 
+  <INPUT TYPE="hidden" NAME="<% $field %>_null" VALUE="<% $cgi->param("${field}_null") |h %>">
+  <INPUT TYPE="hidden" NAME="<% $field %>_begin" VALUE="<% $cgi->param("${field}_begin") |h %>">
+  <INPUT TYPE="hidden" NAME="<% $field %>_beginning" VALUE="<% $cgi->param("${field}_beginning") |h %>">
+  <INPUT TYPE="hidden" NAME="<% $field %>_end" VALUE="<% $cgi->param("${field}_end") |h %>">
+  <INPUT TYPE="hidden" NAME="<% $field %>_ending" VALUE="<% $cgi->param("${field}_ending") |h %>">
+% }
+
+<% ntable('#cccccc') %>
+
+%#  <& /elements/tr-input-date-field.html, {
+%#      'name'    => 'cancel_date',
+%#      'label'   => mt("Cancel package on"),
+%#      'format'  => $date_format,
+%#  } &>
+%#  <TR><TD></TD><TH>(Leave blank to cancel immediately)</TH></TR>
+
+  <& /elements/tr-select-reason.html,
+       field          => 'cancel_reasonnum',
+       reason_class   => 'C',
+  &>
+
+</TABLE>
+
+<BR>
+<INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="Cancel Packages">
+
+</FORM>
+</BODY>
+</HTML>
+
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Bulk change customer packages');
+
+#use Date::Parse qw(str2time);
+#<table style="background-color: #cccccc; border-spacing: 2; width: 100%">
+
+my $conf = new FS::Conf;
+#my $date_format = $conf->config('date_format') || '%m/%d/%Y';
+
+</%init>
diff --git a/httemplate/misc/process/bulk_cancel_pkg.cgi b/httemplate/misc/process/bulk_cancel_pkg.cgi
new file mode 100644
index 000000000..def0ad283
--- /dev/null
+++ b/httemplate/misc/process/bulk_cancel_pkg.cgi
@@ -0,0 +1,104 @@
+% if ($error) {
+<% $cgi->redirect(popurl(2)."bulk_cancel_pkg.cgi?".$cgi->query_string ) %>
+% }
+<% include('/elements/popup-topreload.html', "Packages Cancelled") %>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Bulk change customer packages');
+
+my $error;
+
+if (!$error) {
+
+  my %search_hash = ();
+
+  $search_hash{'query'} = $cgi->param('query');
+
+  #scalars
+  for (qw( agentnum cust_status cust_main_salesnum salesnum custnum magic status
+         custom cust_fields pkgbatch zip reasonnum
+         477part 477rownum date 
+      )) 
+  {
+    $search_hash{$_} = $cgi->param($_) if length($cgi->param($_));
+  }
+
+  #arrays
+  for my $param (qw( pkgpart classnum refnum towernum )) {
+    $search_hash{$param} = [ $cgi->param($param) ]
+      if grep { $_ eq $param } $cgi->param;
+  }
+
+  #scalars that need to be passed if empty
+  for my $param (qw( censustract censustract2 )) {
+    $search_hash{$param} = $cgi->param($param) || ''
+      if grep { $_ eq $param } $cgi->param;
+  }
+
+  #location flags (checkboxes)
+  my @loc = grep /^\w+$/, $cgi->param('loc');
+  $search_hash{"location_$_"} = 1 foreach @loc;
+
+  my $report_option = $cgi->param('report_option');
+  $search_hash{report_option} = $report_option if $report_option;
+
+  for my $param (grep /^report_option_any/, $cgi->param) {
+    $search_hash{$param} = $cgi->param($param);
+  }
+
+  ###
+  # parse dates
+  ###
+
+  #false laziness w/report_cust_pkg.html and bulk_pkg_increment_bill.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 contract_end change_date cancel active )) {
+
+    $search_hash{$field.'_null'} = scalar( $cgi->param($field.'_null') );
+
+    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 ];
+
+  }
+
+  my $sql_query = FS::cust_pkg->search(\%search_hash);
+  $sql_query->{'select'} = 'cust_pkg.pkgnum';
+
+  ## set suspend info
+  $cgi->param('cancel_reasonnum') =~ /^(\d+)$/ or die "Illegal Reason";
+  my $cancel_reasonnum = $1;
+
+  #my $cancel_date = '';
+  #if ( $cgi->param('cancel_date') ) {
+  #  parse_datetime($cgi->param('cancel_date')) =~ /^(\d+)$/ or die "Illegal date";
+  #  $cancel_date = $1;
+  #}
+
+  foreach my $pkgnum (map { $_->pkgnum } qsearch($sql_query)) {
+    my $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
+
+    $error .= ($error ? ' / ' : '').
+              $cust_pkg->cancel('reason'      => $cancel_reasonnum,
+                                #'date'        => $cancel_date,
+                               );
+  }
+
+}
+
+$cgi->param("error", substr($error, 0, 512)); # arbitrary length believed
+                                              # suited for all supported
+                                              # browsers
+</%init>
diff --git a/httemplate/search/cust_pkg.cgi b/httemplate/search/cust_pkg.cgi
index 3eb0332d2..3e0880fa5 100755
--- a/httemplate/search/cust_pkg.cgi
+++ b/httemplate/search/cust_pkg.cgi
@@ -286,6 +286,15 @@ my $html_init = sub {
                'height'      => 210,
              ). '<BR>' if $search_hash{status} eq 'suspended';
 
+    $text .= include( '/elements/popup_link.html',
+               'label'       => emt('Cancel these packages'),
+               'action'      => "${p}misc/bulk_cancel_pkg.cgi?$query",
+               'actionlabel' => emt('Cancel Packages'),
+               'width'       => 569,
+               'height'      => 210,
+               'color'       => '#ff0000',
+             ). '<BR>' unless $search_hash{status} eq 'cancelled';
+
     if ( $curuser->access_right('Edit customer package dates') ) {
       $text .= include( '/elements/popup_link.html',
                  'label'       => emt('Increment next bill date'),

-----------------------------------------------------------------------

Summary of changes:
 .../{bulk_suspend_pkg.cgi => bulk_cancel_pkg.cgi}  | 45 ++++++++--------------
 ...{bulk_unsuspend_pkg.cgi => bulk_cancel_pkg.cgi} | 23 ++++++++---
 httemplate/search/cust_pkg.cgi                     |  9 +++++
 3 files changed, 44 insertions(+), 33 deletions(-)
 copy httemplate/misc/{bulk_suspend_pkg.cgi => bulk_cancel_pkg.cgi} (68%)
 copy httemplate/misc/process/{bulk_unsuspend_pkg.cgi => bulk_cancel_pkg.cgi} (79%)




More information about the freeside-commits mailing list