import torrus 1.0.9
[freeside.git] / httemplate / edit / part_bill_event.cgi
index 77aa828..c0ff386 100755 (executable)
@@ -1,49 +1,12 @@
-<!--mason kludge-->
-%
-%
-%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;
-%
-%
-
-
 <% 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" NAME="editEvent" METHOD=POST>
 <INPUT TYPE="hidden" NAME="eventpart" VALUE="<% $part_bill_event->eventpart %>">
@@ -59,16 +22,11 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
   <TR>
     <TD ALIGN="right">For </TD>
     <TD>
-      <SELECT NAME="payby">
+      <SELECT NAME="payby" <% $hashref->{eventpart} ? '' : 'MULTIPLE SIZE=7'%>>
 % tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname;
 %           foreach my $payby ( keys %payby ) {
-%        
-
-
           <OPTION VALUE="<% $payby %>"<% ($part_bill_event->payby eq $payby) ? ' SELECTED' : '' %>><% $payby{$payby} %></OPTION>
 % } 
-
-
       </SELECT> customers
     </TD>
   </TR>
@@ -120,7 +78,7 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %  join("\n", map {
 %    '<OPTION VALUE="'. $_->pkgpart. '"'.
 %    ( $selected{$_->pkgpart} ? ' SELECTED' : '' ).
-%    '>'. $_->pkg. ' - '. $_->comment
+%    '>'. $_->pkg_comment
 %  } qsearch('part_pkg', { 'disabled' => '' } ) ).
 %  '</SELECT>';
 %}
@@ -138,59 +96,89 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %  '</SELECT>';
 %}
 %
+%sub honor_dundate {
+%  my $label = shift;
+%  my $plandata = shift;
+%  '<TABLE>'.
+%  '<TR><TD ALIGN="right">Allow delay until dun date? </TD>'.
+%  qq(<TD><INPUT TYPE="checkbox" NAME="$label" VALUE="$label => 1," ).
+%    ( $plandata->{$label} eq "$label => 1," ? 'CHECKED' : '' ).
+%  '>'.
+%  '</TD></TR>'.
+%  '</TABLE>'
+%}
+%
 %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',
+%              'curr_value' => '%%%late_taxclass%%%',
+%              'name' => 'late_taxclass' );
+%  $late_percent_taxclass =
+%    '<BR>Taxclass '.
+%    include('/elements/select-taxclass.html',
+%              'curr_value' => '%%%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(reason => %%%sreason%%%);',
+%    'code'   => '$cust_main->suspend(reason => %%%sreason%%%, %%%honor_dundate%%% );',
+%    'html'   => sub { &honor_dundate('honor_dundate', @_) },
 %    '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%%%, reason => %%%sreason%%%, );',
-%    'html'   => " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%">',
+%    'code'   => '$cust_bill->cust_suspend_if_balance_over( %%%balanceover%%%, reason => %%%sreason%%%, %%%balance_honor_dundate%%% );',
+%    'html'   => sub { " $money_char ". '<INPUT TYPE="text" SIZE="7" NAME="balanceover" VALUE="%%%balanceover%%%"> '. &honor_dundate('balance_honor_dundate', @_) },
 %    'weight' => 10,
 %    'reason' => 'S',
 %  },
 %  'suspend-if-pkgpart' => {
 %    'name'   => 'Suspend packages',
-%    'code'   => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%,});',
-%    'html'   => sub { &select_pkgpart('if_pkgpart', @_) },
+%    'code'   => '$cust_main->suspend_if_pkgpart({pkgparts => [%%%if_pkgpart%%%,], reason => %%%sreason%%%, %%%if_pkgpart_honor_dundate%%% });',
+%    'html'   => sub { &select_pkgpart('if_pkgpart', @_). &honor_dundate('if_pkgpart_honor_dundate', @_) },
 %    'weight' => 10,
 %    'reason' => 'S',
 %  },
 %  'suspend-unless-pkgpart' => {
 %    'name'   => 'Suspend packages except',
-%    'code'   => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%,});',
-%    'html'   => sub { &select_pkgpart('unless_pkgpart', @_) },
+%    'code'   => '$cust_main->suspend_unless_pkgpart({unless_pkgpart => [%%%unless_pkgpart%%%], reason => %%%sreason%%%, %%%unless_pkgpart_honor_dundate%%% });',
+%    'html'   => sub { &select_pkgpart('unless_pkgpart', @_). &honor_dundate('unless_pkgpart_honor_dundate' => @_) },
 %    'weight' => 10,
 %    'reason' => 'S',
 %  },
 %  'cancel' => {
 %    'name'   => 'Cancel',
 %    'code'   => '$cust_main->cancel(reason => %%%creason%%%);',
-%    'weight' => 10,
+%    'weight' => 80, #10,
 %    'reason' => 'C',
 %  },
 %
@@ -203,6 +191,13 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %  'comp' => {
 %    'name' => 'Pay invoice with a complimentary "payment"',
 %    'code' => '$cust_bill->comp();',
+%    'weight' => 90, #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,
 %  },
 %
@@ -243,6 +238,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%%%\');',
@@ -261,7 +262,11 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %
 %  'send_agent' => {
 %    'name' => 'Send invoice (email/print/fax) ',
-%    'code' => '$cust_bill->send(\'%%%agent_templatename%%%\', [ %%%agentnum%%% ], \'%%%agent_invoice_from%%%\');',
+%    'code' => '$cust_bill->send( \'%%%agent_templatename%%%\',
+%                                 [ %%%agentnum%%% ],
+%                                 \'%%%agent_invoice_from%%%\',
+%                                 %%%agent_balanceover%%%
+%                               );',
 %    'html' => sub {
 %        '<TABLE BORDER=0>
 %          <TR>
@@ -280,6 +285,13 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %              <INPUT TYPE="text" NAME="agent_invoice_from" VALUE="%%%agent_invoice_from%%%">
 %            </TD>
 %          </TR>
+%          <TR>
+%            <TD ALIGN="right">if balance (this invoice and previous) over
+%            </TD>
+%            <TD>
+%              '. $money_char. '<INPUT TYPE="text" SIZE="7" NAME="agent_balanceover" VALUE="%%%agent_balanceover%%%">
+%            </TD>
+%          </TR>
 %        </TABLE>';
 %    },
 %    'weight' => 50,
@@ -395,16 +407,10 @@ 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,
 %  },
 %
-%  'collect' => {
-%    'name' => 'Collect on invoices (normally only used with a <i>Late Fee</i> and <i>Generate Invoice</i> events)',
-%    'code' => '$cust_main->collect();',
-%    'weight'  => 80,
-%  },
-%
 %;
 %
 <SCRIPT TYPE="text/javascript">var myreasons = new Array();</SCRIPT>
@@ -435,6 +441,7 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 %  print '<TD>'. $html. '</TD>' if $html;
 %  print qq!</TR>!;
 %  print '</TABLE>';
+%  print qq!<HR WIDTH="90%">!;
 %}
 %
 %  if ($currentreasonclass eq 'C'){
@@ -491,7 +498,14 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 <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', 'creason', 'C', $creason, $newcreasonT, $newcreason) %>
+<% include('/elements/tr-select-reason.html',
+             'field'          => 'creason',
+             'reason_class'   => 'C',
+             'curr_value'     => $creason,
+             'init_type'      => $newcreasonT,
+             'init_newreason' => $newcreason
+          )
+%>
 </TABLE>
 </TR></TD>
 </TABLE>
@@ -499,7 +513,14 @@ Invoice Event #<% $hashref->{eventpart} ? $hashref->{eventpart} : "(NEW)" %>
 <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', 'sreason', 'S', $sreason, $newsreasonT, $newsreason) %>
+<% include('/elements/tr-select-reason.html',
+             'field'          => 'sreason',
+             'reason_class'   => 'S',
+             'curr_value'     => $sreason,
+             'init_type'      => $newsreasonT,
+             'init_newreason' => $newsreason
+          )
+%>
 </TABLE>
 </TR></TD>
 </TABLE>
@@ -512,7 +533,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>