add per-customer configurable billing date, RT10813
authorlevinse <levinse>
Sun, 24 Apr 2011 17:05:01 +0000 (17:05 +0000)
committerlevinse <levinse>
Sun, 24 Apr 2011 17:05:01 +0000 (17:05 +0000)
FS/FS/Conf.pm
FS/FS/Schema.pm
FS/FS/cust_main.pm
FS/FS/part_event/Condition/billday.pm [new file with mode: 0644]
httemplate/edit/cust_main/billing.html
httemplate/view/cust_main/billing.html

index 5bad056..61cba34 100644 (file)
@@ -681,6 +681,13 @@ my %payment_gateway_options = (
     'description' => 'Display a barcode on HTML and PDF invoices',
     'type'        => 'checkbox',
   },
+  
+  {
+    'key'         => 'cust_main-select-billday',
+    'section'     => 'billing',
+    'description' => 'When used with a specific billing event, allows the selection of the day of month on which to charge credit card / bank account automatically, on a per-customer basis',
+    'type'        => 'checkbox',
+  },
 
   {
     'key'         => 'encryption',
index 5dd9e13..0b6ea0d 100644 (file)
@@ -871,6 +871,7 @@ sub tables_hashref {
         'archived', 'char', 'NULL', 1, '', '',
         'email_csv_cdr', 'char', 'NULL', 1, '', '',
         'accountcode_cdr', 'char', 'NULL', 1, '', '',
+        'billday',   'int', 'NULL', '', '', '',
       ],
       'primary_key' => 'custnum',
       'unique' => [ [ 'agentnum', 'agent_custid' ] ],
index 22c16fb..8345d92 100644 (file)
@@ -1681,6 +1681,7 @@ sub check {
     || $self->ut_alphan('geocode')
     || $self->ut_floatn('cdr_termination_percentage')
     || $self->ut_floatn('credit_limit')
+    || $self->ut_numbern('billday')
   ;
 
   #barf.  need message catalogs.  i18n.  etc.
diff --git a/FS/FS/part_event/Condition/billday.pm b/FS/FS/part_event/Condition/billday.pm
new file mode 100644 (file)
index 0000000..b150a6c
--- /dev/null
@@ -0,0 +1,30 @@
+package FS::part_event::Condition::billday;
+
+use strict;
+use Tie::IxHash;
+
+use base qw( FS::part_event::Condition );
+
+sub description {
+  "Customer's monthly billing day matches current day or customer has no billing day";
+}
+
+sub condition {
+  my( $self, $object ) = @_;
+
+  my $cust_main = $self->cust_main($object);
+
+  my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
+
+  ($mday == $cust_main->billday) || (!$cust_main->billday);
+}
+
+sub condition_sql {
+  my( $self, $table ) = @_;
+
+  my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
+
+  "cust_main.billday is null or cust_main.billday = $mday";
+}
+
+1;
index e6600e6..2301a0b 100644 (file)
       return true;
     }
 
+    function payauto_changed(payauto_field){
+        var f = (payauto_field.name == 'CARD_payauto') ? 'card_billday' : 'chek_billday';
+        f = document.getElementById(f);
+        if ( f == null) return;
+        if(payauto_field.checked) f.style.display = 'inline';
+        else f.style.display = 'none';
+    }
+
   </SCRIPT>
 
   <% include('/elements/init_overlib.html') %>
 %                             : $payby eq 'CHEK' ? 'CHECKED'
 %                             : $disable_payauto ? '' : 'CHECKED';
 %
+%  sub billday_options {
+%   my $curr_value = shift;
+%   my $ret = '<OPTION></OPTION>';
+%   for my $billday ( 1 .. 28 ) {
+%       my $sel = '';
+%       $sel = "SELECTED='SELECTED'" if $curr_value == $billday;
+%       $ret .= "<OPTION VALUE='$billday' $sel>$billday</OPTION>";
+%   }
+%   $ret;
+%  }
+%  my $billday_card_display = $payby eq 'CARD' ? 'inline' : 'none';
+%  my $billday_chek_display = $payby eq 'CHEK' ? 'inline' : 'none';
+%
 %  my %payby = (
 %
 %    'CARD' =>
 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}Exact name on card </TD>!.
 %          qq!<TD WIDTH="408"><INPUT TYPE="text" NAME="CARD_payname" VALUE="!. ( $payby =~ /^(CARD|DCRD)$/ ? $cust_main->payname : '' ). qq!"></TD></TR>!.
 %
-%        qq!<TR><TD COLSPAN=2 WIDTH="608"><INPUT TYPE="checkbox" NAME="CARD_payauto" $CARD_payauto_checked> Charge future payments to this card automatically</TD></TR>!.
+%        qq!<TR><TD COLSPAN=2 WIDTH="608"><INPUT TYPE="checkbox" onchange="payauto_changed(this);" NAME="CARD_payauto" $CARD_payauto_checked> Charge future payments to this card automatically</TD></TR>!.
+%
+%      ( $conf->exists('cust_main-select-billday') ?
+%        qq!<TR><TD COLSPAN=2 WIDTH="608" id="card_billday" style="display: $billday_card_display">
+%                    Charge on the <SELECT NAME="billday">!
+%                . billday_options($cust_main->billday) . qq!</SELECT> day of each month</TD></TR>!
+%        : ''
+%      ).
 %
 %      '</TABLE>',
 %
 %       ).
 %
 %
-%        qq!<TR><TD COLSPAN=4 WIDTH="608"><INPUT TYPE="checkbox" NAME="CHEK_payauto" $CHEK_payauto_checked> Charge future payments to this electronic check automatically</TD></TR>!.
+%        qq!<TR><TD COLSPAN=4 WIDTH="608"><INPUT TYPE="checkbox" onchange="payauto_changed(this);" NAME="CHEK_payauto" $CHEK_payauto_checked> Charge future payments to this electronic check automatically</TD></TR>!.
+%
+%      ( $conf->exists('cust_main-select-billday') ?
+%        qq!<TR><TD COLSPAN=2 WIDTH="608" id="chek_billday" style="display: $billday_chek_display">
+%                    Charge on the <SELECT NAME="billday">!
+%                . billday_options($cust_main->billday) . qq!</SELECT> day of each month</TD></TR>!
+%        : ''
+%      ).
 %
 %        '<TR><TD>&nbsp;</TD></TR>'.
 %        '<TR><TD>&nbsp;</TD></TR>'.
index 014ddab..efff3ed 100644 (file)
@@ -23,6 +23,15 @@ Billing information
   <TD BGCOLOR="#ffffff"><B><% $balance %></B></TD>
 </TR>
 
+% if ( $conf->exists('cust_main-select-billday') 
+%    && ($cust_main->payby eq 'CARD' || $cust_main->payby eq 'CHEK') ) {
+<TR>
+  <TD ALIGN="right">Billing day of month</TD>
+  <TD BGCOLOR="#ffffff"><% $cust_main->billday %>
+  </TD>
+</TR>
+% }
+
 <TR>
   <TD ALIGN="right">Billing&nbsp;type</TD>
   <TD BGCOLOR="#ffffff">