add manual_process-skip_first option, RT#5889
authorivan <ivan>
Mon, 5 Oct 2009 02:36:03 +0000 (02:36 +0000)
committerivan <ivan>
Mon, 5 Oct 2009 02:36:03 +0000 (02:36 +0000)
FS/FS/Conf.pm
FS/FS/cust_main.pm
httemplate/misc/payment.cgi

index b125b62..be4c744 100644 (file)
@@ -1873,6 +1873,12 @@ worry that config_items is freeside-specific and icky.
                      ],
   },
 
                      ],
   },
 
+  {
+    'key'         => 'manual_process-skip_first',
+    'section'     => 'billing',
+    'description' => "When using manual_process-pkgpart, omit the fee if it is the customer's first payment.",
+    'type'        => 'checkbox',
+  },
 
   {
     'key'         => 'allow_negative_charges',
 
   {
     'key'         => 'allow_negative_charges',
index d61ebd2..638036a 100644 (file)
@@ -7377,10 +7377,26 @@ Returns all the payments (see L<FS::cust_pay>) for this customer.
 
 sub cust_pay {
   my $self = shift;
 
 sub cust_pay {
   my $self = shift;
+  return $self->num_cust_pay unless wantarray;
   sort { $a->_date <=> $b->_date }
     qsearch( 'cust_pay', { 'custnum' => $self->custnum } )
 }
 
   sort { $a->_date <=> $b->_date }
     qsearch( 'cust_pay', { 'custnum' => $self->custnum } )
 }
 
+=item num_cust_pay
+
+Returns the number of payments (see L<FS::cust_pay>) for this customer.  Also
+called automatically when the cust_pay method is used in a scalar context.
+
+=cut
+
+sub num_cust_pay {
+  my $self = shift;
+  my $sql = "SELECT COUNT(*) FROM cust_pay WHERE custnum = ?";
+  my $sth = dbh->prepare($sql) or die dbh->errstr;
+  $sth->execute($self->custnum) or die $sth->errstr;
+  $sth->fetchrow_arrayref->[0];
+}
+
 =item cust_pay_pkgnum
 
 Returns all the payments (see L<FS::cust_pay>) for this customer's specific
 =item cust_pay_pkgnum
 
 Returns all the payments (see L<FS::cust_pay>) for this customer's specific
index d35e73f..ada925c 100644 (file)
@@ -302,6 +302,8 @@ my $fee_display = '';
 my $fee_op = '';
 if ( $conf->config('manual_process-pkgpart') ) {
 
 my $fee_op = '';
 if ( $conf->config('manual_process-pkgpart') ) {
 
+  last if $conf->exists('manual_process-skip_first') && ! $cust_main->cust_pay;
+
   $fee_display = $conf->config('manual_process-display') || 'add';
   $fee_op = $fee_display eq 'add' ? '+' : '-';
 
   $fee_display = $conf->config('manual_process-display') || 'add';
   $fee_op = $fee_display eq 'add' ? '+' : '-';