update the tax class editor to enable taxclass adding, RT#2929
[freeside.git] / httemplate / edit / part_bill_event.cgi
index da11fc7..2547067 100755 (executable)
@@ -1,46 +1,14 @@
-<!--mason kludge-->
-%
-%
-%if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
-%  $cgi->param('eventpart', $1);
-%} else {
-%  $cgi->param('eventpart', '');
-%}
-%
-%my ($query) = $cgi->keywords;
-%my $action = '';
-%my $part_bill_event = '';
-%if ( $cgi->param('error') ) {
-%  $part_bill_event = new FS::part_bill_event ( {
-%    map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
-%  } );
-%}
-%if ( $query && $query =~ /^(\d+)$/ ) {
-%  $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
-%} else {
-%  $part_bill_event ||= new FS::part_bill_event {};
-%}
-%$action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
-%my $hashref = $part_bill_event->hashref;
-%
-%
-
-
 <% include('/elements/header.html',
       "$action Invoice Event Definition",
       menubar(
-        'Main Menu' => popurl(2),
         'View all invoice events' => popurl(2). 'browse/part_bill_event.cgi',
       )
     )
 %>
-% if ( $cgi->param('error') ) { 
-
-  <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
-% } 
 
+<% include('/elements/error.html') %>
 
-<FORM ACTION="<% popurl(1) %>process/part_bill_event.cgi" METHOD=POST>
+<FORM ACTION="<% popurl(1) %>process/part_bill_event.cgi" NAME="editEvent" METHOD=POST>
 <INPUT TYPE="hidden" NAME="eventpart" VALUE="<% $part_bill_event->eventpart %>">
 Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 
@@ -136,52 +104,72 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %my $conf = new FS::Conf;
 %my $money_char = $conf->config('money_char') || '$';
 %
+%my $late_taxclass = '';
+%my $late_percent_taxclass = '';
+%if ( $conf->exists('enable_taxclasses') ) {
+%  $late_taxclass =
+%    '<BR>Taxclass '.
+%    include('/elements/select-taxclass.html', '%%%late_taxclass%%%',
+%              'name' => 'late_taxclass' );
+%  $late_percent_taxclass =
+%    '<BR>Taxclass '.
+%    include('/elements/select-taxclass.html', '%%%late_percent_taxclass%%%',
+%              'name' => 'late_percent_taxclass' );
+%}
+%
 %#this is pretty kludgy right here.
 %tie my %events, 'Tie::IxHash',
 %
 %  'fee' => {
 %    'name'   => 'Late fee (flat)',
-%    'code'   => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\' );',
+%    'code'   => '$cust_main->charge( %%%charge%%%, \'%%%reason%%%\', \'$%%%charge%%%\', \'%%%late_taxclass%%%\' );',
 %    'html'   => 
 %      'Amount <INPUT TYPE="text" SIZE="7" NAME="charge" VALUE="%%%charge%%%">'.
-%      '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
+%      '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">'.
+%      $late_taxclass,
 %    'weight' => 10,
 %  },
 %  'fee_percent' => {
 %    'name'   => 'Late fee (percentage)',
-%    'code'   => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%reason%%%\' );',
+%    'code'   => '$cust_main->charge( sprintf(\'%.2f\', $cust_bill->owed * %%%percent%%% / 100 ), \'%%%percent_reason%%%\', \'%%%percent%%% percent\', \'%%%late_percent_taxclass%%%\' );',
 %    'html'   => 
 %      'Percent <INPUT TYPE="text" SIZE="2" NAME="percent" VALUE="%%%percent%%%">%'.
-%      '<BR>Reason <INPUT TYPE="text" NAME="reason" VALUE="%%%reason%%%">',
+%      '<BR>Reason <INPUT TYPE="text" NAME="percent_reason" VALUE="%%%percent_reason%%%">'.
+%      $late_percent_taxclass,
 %    'weight' => 10,
 %  },
 %  'suspend' => {
 %    'name'   => 'Suspend',
-%    'code'   => '$cust_main->suspend();',
+%    'code'   => '$cust_main->suspend(reason => %%%sreason%%%);',
 %    'weight' => 10,
+%    'reason' => 'S',
 %  },
 %  'suspend-if-balance' => {
 %    'name'   => 'Suspend if balance (this invoice and previous) over',
-%    'code'   => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%% );',
+%    'code'   => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%%, reason => %%%sreason%%%, );',
 %    'html'   => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
 %    'weight' => 10,
+%    'reason' => 'S',
 %  },
 %  'suspend-if-pkgpart' => {
 %    'name'   => 'Suspend packages',
-%    'code'   => '$cust_main->suspend_if_pkgpart(%%%if_pkgpart%%%);',
+%    'code'   => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%,});',
 %    'html'   => sub { &select_pkgpart('if_pkgpart', @_) },
 %    'weight' => 10,
+%    'reason' => 'S',
 %  },
 %  'suspend-unless-pkgpart' => {
 %    'name'   => 'Suspend packages except',
-%    'code'   => '$cust_main->suspend_unless_pkgpart(%%%unless_pkgpart%%%);',
+%    'code'   => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%,});',
 %    'html'   => sub { &select_pkgpart('unless_pkgpart', @_) },
 %    'weight' => 10,
+%    'reason' => 'S',
 %  },
 %  'cancel' => {
 %    'name'   => 'Cancel',
-%    'code'   => '$cust_main->cancel();',
+%    'code'   => '$cust_main->cancel(reason => %%%creason%%%);',
 %    'weight' => 10,
+%    'reason' => 'C',
 %  },
 %
 %  'addpost' => {
@@ -196,6 +184,13 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %    'weight' => 30,
 %  },
 %
+%  'credit' => {
+%    'name'   => "Create and apply a credit for the customer's balance (i.e. write off as bad debt)",
+%    'code'   => '$cust_main->credit( $cust_main->balance, \'%%%credit_reason%%%\' );',
+%    'html'   => '<INPUT TYPE="text" NAME="credit_reason" VALUE="%%%credit_reason%%%">',
+%    'weight' => 30,
+%  },
+%
 %  'realtime-card' => {
 %    'name' => 'Run card with a <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> realtime gateway',
 %    'code' => '$cust_bill->realtime_card();',
@@ -233,6 +228,12 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %    'weight' => 50,
 %  },
 %
+%  'send_email' => {
+%    'name' => 'Send invoice (email only)',
+%    'code' => '$cust_bill->email();',
+%    'weight' => 50,
+%  },
+%
 %  'send_alternate' => {
 %    'name' => 'Send invoice (email/print/fax) with alternate template',
 %    'code' => '$cust_bill->send(\'%%%templatename%%%\');',
@@ -385,7 +386,7 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %
 %  'apply' => {
 %    'name' => 'Apply unapplied payments and credits',
-%    'code' => '$cust_main->apply_payments; $cust_main->apply_credits; "";',
+%    'code' => '$cust_main->apply_payments_and_credits; "";',
 %    'weight'  => 70,
 %  },
 %
@@ -397,6 +398,7 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %
 %;
 %
+<SCRIPT TYPE="text/javascript">var myreasons = new Array();</SCRIPT>
 %foreach my $event ( keys %events ) {
 %  my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
 %                   split(/\n/, $part_bill_event->plandata);
@@ -409,9 +411,15 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %    $html =~ s/%%%$field%%%/$plandata{$field}/;
 %  }
 %
+<SCRIPT TYPE="text/javascript">myreasons.push('<% $events{$event}{reason} %>');
+</SCRIPT>
+%  if ($event eq $part_bill_event->plan){
+%    $currentreasonclass=$events{$event}{reason};
+%  }
 %  print ntable( "#cccccc", 2).
 %        qq!<TR><TD><INPUT TYPE="radio" NAME="plan_weight_eventcode" !;
 %  print "CHECKED " if $event eq $part_bill_event->plan;
+%  print qq!onClick="showhide_table()" !;
 %  print qq!VALUE="!.  $event. ":". $events{$event}{weight}. ":".
 %        encode_entities($events{$event}{code}).
 %        qq!">$events{$event}{name}</TD>!;
@@ -420,12 +428,87 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %  print '</TABLE>';
 %}
 %
-%#print '</TABLE>';
+%  if ($currentreasonclass eq 'C'){
+%    if ($cgi->param('creason') =~ /^(-?\d+)$/){
+%      $creason =  $1;
+%    }else{
+%      $creason = $part_bill_event->reason;
+%    }
+%    if ($cgi->param('newcreasonT') =~ /^(\d+)$/){
+%      $newcreasonT =  $1;
+%    }
+%    if ($cgi->param('newcreason') =~ /^([\w\s]+)$/){
+%      $newcreason =  $1;
+%    }
+%  }elsif ($currentreasonclass eq 'S'){
+%    if ($cgi->param('sreason') =~ /^(-?\d+)$/){
+%      $sreason =  $1;
+%    }else{
+%      $sreason = $part_bill_event->reason;
+%    }
+%    if ($cgi->param('newsreasonT') =~ /^(\d+)$/){
+%      $newsreasonT =  $1;
+%    }
+%    if ($cgi->param('newsreason') =~ /^([\w\s]+)$/){
+%      $newsreason =  $1;
+%    }
+%  }
 %
-%print <<END;
-%</TD></TR>
-%</TABLE>
-%END
+
+</TD></TR>
+</TABLE>
+
+<SCRIPT TYPE="text/javascript">
+  function showhide_table()
+  {
+    for(i=0;i<document.editEvent.plan_weight_eventcode.length;i++){
+      if (document.editEvent.plan_weight_eventcode[i].checked == true){
+        currentevent=i;
+      }
+    }
+    if(myreasons[currentevent] == 'C'){
+      document.getElementById('Ctable').style.display = 'inline';
+      document.getElementById('Stable').style.display = 'none';
+    }else if(myreasons[currentevent] == 'S'){
+      document.getElementById('Ctable').style.display = 'none';
+      document.getElementById('Stable').style.display = 'inline';
+    }else{
+      document.getElementById('Ctable').style.display = 'none';
+      document.getElementById('Stable').style.display = 'none';
+    }
+  }
+</SCRIPT>
+
+<TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
+<TR><TD>
+<TABLE BORDER=0 id="Ctable" style="display:<% $currentreasonclass eq 'C' ? 'inline' : 'none' %>">
+<% include('/elements/tr-select-reason.html',
+             'field'          => 'creason',
+             'reason_class'   => 'C',
+             'curr_value'     => $creason,
+             'init_type'      => $newcreasonT,
+             'init_newreason' => $newcreason
+          )
+%>
+</TABLE>
+</TR></TD>
+</TABLE>
+
+<TABLE BGCOLOR="#cccccc" BORDER=0 WIDTH="100%">
+<TR><TD>
+<TABLE BORDER=0 id="Stable" style="display:<% $currentreasonclass eq 'S' ? 'inline' : 'none' %>">
+<% include('/elements/tr-select-reason.html',
+             'field'          => 'sreason',
+             'reason_class'   => 'S',
+             'curr_value'     => $sreason,
+             'init_type'      => $newsreasonT,
+             'init_newreason' => $newsreason
+          )
+%>
+</TABLE>
+</TR></TD>
+</TABLE>
+    
 %
 %print qq!<INPUT TYPE="submit" VALUE="!,
 %      $hashref->{eventpart} ? "Apply changes" : "Add invoice event",
@@ -434,7 +517,38 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 
 
     </FORM>
-  </BODY>
-</HTML>
 
+<% include('/elements/footer.html') %>
+
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+if ( $cgi->param('eventpart') && $cgi->param('eventpart') =~ /^(\d+)$/ ) {
+  $cgi->param('eventpart', $1);
+} else {
+  $cgi->param('eventpart', '');
+}
+
+my ($creason, $newcreasonT, $newcreason);
+my ($sreason, $newsreasonT, $newsreason);
+
+my ($query) = $cgi->keywords;
+my $action = '';
+my $part_bill_event = '';
+my $currentreasonclass = '';
+if ( $cgi->param('error') ) {
+  $part_bill_event = new FS::part_bill_event ( {
+    map { $_, scalar($cgi->param($_)) } fields('part_bill_event')
+  } );
+}
+if ( $query && $query =~ /^(\d+)$/ ) {
+  $part_bill_event ||= qsearchs('part_bill_event',{'eventpart'=>$1});
+} else {
+  $part_bill_event ||= new FS::part_bill_event {};
+}
+$action ||= $part_bill_event->eventpart ? 'Edit' : 'Add';
+my $hashref = $part_bill_event->hashref;
 
+</%init>