[freeside-commits] branch FREESIDE_3_BRANCH updated. 43e9232c02591fceea1445e59584ab584ce7b433

Jonathan Prykop jonathan at 420.am
Mon Nov 16 19:15:26 PST 2015


The branch, FREESIDE_3_BRANCH has been updated
       via  43e9232c02591fceea1445e59584ab584ce7b433 (commit)
       via  73ad9e9c38a2b441444dfe77458f515de5b58ac3 (commit)
       via  67b1386cb9519db0088c077f415a813a41a2315b (commit)
       via  3af54162b6f9fae1c836390a3ff072af38d60550 (commit)
      from  80943daf9e33f2045da3dbf6fbf431b4c6b81f13 (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 43e9232c02591fceea1445e59584ab584ce7b433
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Nov 16 21:13:53 2015 -0600

    RT#17480: Freeside Cancel Reason [v3 only, removed v4 tables from merge]

diff --git a/FS/FS/reason.pm b/FS/FS/reason.pm
index 4c2587f..1739f96 100644
--- a/FS/FS/reason.pm
+++ b/FS/FS/reason.pm
@@ -161,13 +161,9 @@ Accepts an arrayref of reason objects, to be merged into this reason.
 Reasons must all have the same reason_type class as this one.
 Matching reasonnums will be replaced in the following tables:
 
-  cust_bill_void
-  cust_bill_pkg_void
   cust_credit
   cust_credit_void
-  cust_pay_void
   cust_pkg_reason
-  cust_refund
 
 =cut
 
@@ -195,13 +191,9 @@ sub merge {
     $error = "Mismatched reason type class"    
       unless $reason->reasontype->class eq $class;
     foreach my $table ( qw(
-      cust_bill_void
-      cust_bill_pkg_void
       cust_credit
       cust_credit_void
-      cust_pay_void
       cust_pkg_reason
-      cust_refund
     )) {
       last if $error;
       my @fields = ('reasonnum');

commit 73ad9e9c38a2b441444dfe77458f515de5b58ac3
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Nov 16 19:32:09 2015 -0600

    RT#17480: Freeside Cancel Reason [small fixes]

diff --git a/httemplate/misc/reason-merge.html b/httemplate/misc/reason-merge.html
index a531e58..14f5ebb 100644
--- a/httemplate/misc/reason-merge.html
+++ b/httemplate/misc/reason-merge.html
@@ -1,9 +1,7 @@
 % if ($success) {
 <% include('/elements/header-popup.html', 'Reason Merge Success') %>
 <SCRIPT>
-<!-- 
 window.top.location.reload()
--->
 </SCRIPT>
 % } else {
 <% include('/elements/header-popup.html', 'Merge Reasons') %>
@@ -72,7 +70,7 @@ if ($cgi->param('process_merge') && !$error) {
     $error = $destreason->merge(\@reasons);
     $success = 1 unless $error;
   } else {
-    $error = "No desitation reason selected.";
+    $error = "No destination reason selected.";
   }
 }
 

commit 67b1386cb9519db0088c077f415a813a41a2315b
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Fri Nov 13 17:46:33 2015 -0600

    RT#17480: Freeside Cancel Reason [missing file]

diff --git a/httemplate/misc/reason-merge.html b/httemplate/misc/reason-merge.html
new file mode 100644
index 0000000..a531e58
--- /dev/null
+++ b/httemplate/misc/reason-merge.html
@@ -0,0 +1,79 @@
+% if ($success) {
+<% include('/elements/header-popup.html', 'Reason Merge Success') %>
+<SCRIPT>
+<!-- 
+window.top.location.reload()
+-->
+</SCRIPT>
+% } else {
+<% include('/elements/header-popup.html', 'Merge Reasons') %>
+%   if ($error) {
+<P STYLE="color: red;"><% emt($error) %></P>
+%   }
+%   if (@reasons > 1) {
+<P>
+The following reasons will be merged into one.
+Please select one reason to merge the others into.
+</P>
+<FORM METHOD="POST" ACTION="<% "${p}misc/reason-merge.html" %>">
+<P>
+%     foreach my $reason (@reasons) {
+<INPUT TYPE="hidden" NAME="reasonnum" VALUE="<% $reason->reasonnum %>">
+<INPUT TYPE="radio" NAME="destreasonnum" VALUE="<% $reason->reasonnum %>">
+<% $reason->reason %><BR>
+%     }
+<P>
+<P>Caution: merging reasons cannot be undone!</P>
+<P><INPUT TYPE="submit" NAME="process_merge" value="Merge"></P>
+</FORM>
+%   } else {
+<BUTTON TYPE="button" onClick="parent.cClick();">Close</BUTTON>
+%   }
+% }
+
+<%init>
+my @reasonnums = $cgi->param('reasonnum');
+my $destreasonnum = $cgi->param('destreasonnum');
+
+my $error;
+my $class;
+my @reasons;
+my $destreason;
+foreach my $reasonnum (@reasonnums) {
+  unless ($reasonnum =~ /^\d+$/) {
+    $error = "Invalid reasonnum $reasonnum.";
+    last;
+  }
+  my $reason = qsearchs('reason',{ 'reasonnum' => $reasonnum });
+  unless ($reason) {
+    $error = "Reason $reasonnum could not be loaded.";
+    last;
+  }
+  my $reasontype = $reason->reasontype;
+  $class ||= $reasontype->class;
+  if ($class ne $reasontype->class) {
+    $error = "Selected reasons must have the same reason type class.";
+    last;
+  }
+  push(@reasons, $reason);
+  $destreason = $reason if $reasonnum eq $destreasonnum;
+}
+
+unless ($error) {
+  $error = "No reasons selected." unless @reasons;
+  $error = "Select two or more reasons to merge." unless @reasons > 1;
+}
+
+ at reasons = () if $error;
+
+my $success = 0;
+if ($cgi->param('process_merge') && !$error) {
+  if ($destreason) {
+    $error = $destreason->merge(\@reasons);
+    $success = 1 unless $error;
+  } else {
+    $error = "No desitation reason selected.";
+  }
+}
+
+</%init>

commit 3af54162b6f9fae1c836390a3ff072af38d60550
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Nov 16 20:20:34 2015 -0600

    RT#17480: Freeside Cancel Reason [v3 merge]

diff --git a/FS/FS/reason.pm b/FS/FS/reason.pm
index 21c82b1..4c2587f 100644
--- a/FS/FS/reason.pm
+++ b/FS/FS/reason.pm
@@ -155,6 +155,80 @@ sub reasontype {
   qsearchs( 'reason_type', { 'typenum' => shift->reason_type } );
 }
 
+=item merge
+
+Accepts an arrayref of reason objects, to be merged into this reason.
+Reasons must all have the same reason_type class as this one.
+Matching reasonnums will be replaced in the following tables:
+
+  cust_bill_void
+  cust_bill_pkg_void
+  cust_credit
+  cust_credit_void
+  cust_pay_void
+  cust_pkg_reason
+  cust_refund
+
+=cut
+
+sub merge {
+  my ($self,$reasons) = @_;
+  return "Bad input for merge" unless ref($reasons) eq 'ARRAY';
+
+  my $class = $self->reasontype->class;
+
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $error;
+  foreach my $reason (@$reasons) {
+    last if $error;
+    next if $reason->reasonnum eq $self->reasonnum;
+    $error = "Mismatched reason type class"    
+      unless $reason->reasontype->class eq $class;
+    foreach my $table ( qw(
+      cust_bill_void
+      cust_bill_pkg_void
+      cust_credit
+      cust_credit_void
+      cust_pay_void
+      cust_pkg_reason
+      cust_refund
+    )) {
+      last if $error;
+      my @fields = ('reasonnum');
+      push(@fields, 'void_reasonnum') if $table eq 'cust_credit_void';
+      foreach my $field (@fields) {
+        last if $error;
+        foreach my $obj ( qsearch($table,{ $field => $reason->reasonnum }) ) {
+          last if $error;
+          $obj->set($field,$self->reasonnum);
+          $error = $obj->replace;
+        }
+      }
+    }
+    $error ||= $reason->delete;
+  }
+
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+  '';
+
+}
+
 =back
 
 =head1 CLASS METHODS
diff --git a/httemplate/browse/reason.html b/httemplate/browse/reason.html
index 8af88a9..bdbcf37 100644
--- a/httemplate/browse/reason.html
+++ b/httemplate/browse/reason.html
@@ -18,6 +18,8 @@
                  'fields'      => \@fields,
                  'links'       => \@links,
                  'align'       => $align,
+                 'html_form'   => qq!<FORM ACTION="${p}misc/reason_merge.html" METHOD="POST">!,
+                 'html_foot'   => $html_foot,
              )
 %>
 <%init>
@@ -31,7 +33,8 @@ my $class = $1;
 my $classname = $FS::reason_type::class_name{$class};
 my $classpurpose = $FS::reason_type::class_purpose{$class};
 
-my $html_init = ucfirst($classname).  " reasons $classpurpose.<BR><BR>".
+my $html_init = include('/elements/init_overlib.html').
+ucfirst($classname).  " reasons $classpurpose.<BR><BR>".
 qq!<A HREF="${p}edit/reason.html?class=$class">!.
 "<I>Add a $classname reason</I></A><BR><BR>";
 
@@ -107,5 +110,22 @@ if ( $class eq 'S' ) {
   $align .= 'cl';
 }
 
+# reason merge handling
+push @header, '';
+push @fields, sub {
+  my $reason = shift;
+  my $reasonnum = $reason->reasonnum;
+  qq!<INPUT TYPE="checkbox" NAME="reasonnum" VALUE="$reasonnum">!;
+};
+push @links, '';
+$align .= 'l';
+my $html_foot = include('/search/elements/checkbox-foot.html',
+  onclick  => include( '/elements/popup_link_onclick.html',
+                js_action   => q!'! . "${p}misc/reason-merge.html?" . q!' + toCGIString()!,
+                actionlabel => 'Merge reasons',
+              ),
+  label    => 'merge selected reasons',
+  minboxes => 2,
+) . '</FORM>';
 
 </%init>
diff --git a/httemplate/search/elements/checkbox-foot.html b/httemplate/search/elements/checkbox-foot.html
index c470094..ae8b794 100644
--- a/httemplate/search/elements/checkbox-foot.html
+++ b/httemplate/search/elements/checkbox-foot.html
@@ -11,6 +11,7 @@
                     },
                   ],
                   filter        => '.name = "pkgpart"', # see below
+                  minboxes      => 2, #will remove checkboxes if there aren't at least this many
                ),
 &>
 
@@ -67,6 +68,14 @@ for (var i = 0; i < inputs.length; i++) {
   }
 }
 %# avoid the need for "$areboxes" late-evaluation hackery
+% if ($opt{'minboxes'}) {
+if ( checkboxes.length < <% $opt{'minboxes'} %> ) {
+  for (i = 0; i < checkboxes.length; i++) {
+    checkboxes[i].parentNode.removeChild(checkboxes[i]);
+  }
+  checkboxes = [];
+}
+% }
 if ( checkboxes.length == 0 ) {
   document.getElementById('checkbox_footer').style.display = 'none';
 }

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

Summary of changes:
 FS/FS/reason.pm                               |   66 +++++++++++++++++++++
 httemplate/browse/reason.html                 |   22 ++++++-
 httemplate/misc/reason-merge.html             |   77 +++++++++++++++++++++++++
 httemplate/search/elements/checkbox-foot.html |    9 +++
 4 files changed, 173 insertions(+), 1 deletion(-)
 create mode 100644 httemplate/misc/reason-merge.html




More information about the freeside-commits mailing list