[freeside-commits] freeside/FS/FS Conf.pm, 1.180.2.29, 1.180.2.30 cust_main.pm, 1.271.2.49, 1.271.2.50

Jeff Finucane,420,, jeff at wavetail.420.am
Tue Jun 24 09:39:13 PDT 2008


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv2836/FS/FS

Modified Files:
      Tag: FREESIDE_1_7_BRANCH
	Conf.pm cust_main.pm 
Log Message:
postal invoice fees

Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.180.2.29
retrieving revision 1.180.2.30
diff -u -d -r1.180.2.29 -r1.180.2.30
--- Conf.pm	16 Jun 2008 06:53:50 -0000	1.180.2.29
+++ Conf.pm	24 Jun 2008 16:39:10 -0000	1.180.2.30
@@ -1966,6 +1966,25 @@
   },
 
   {
+    'key'         => 'postal_invoice-fee_pkgpart',
+    'section'     => 'billing',
+    'description' => 'This allows selection of a package to insert on invoices for customers with postal invoices selected.',
+    'type'        => 'select-sub',
+    'options_sub' => sub { require FS::Record;
+                           require FS::part_pkg;
+			   map { $_->pkgpart => $_->pkg }
+                               FS::Record::qsearch('part_pkg', { disabled=>'' } );
+			 },
+    'option_sub'  => sub { require FS::Record;
+                           require FS::part_pkg;
+			   my $part_pkg = FS::Record::qsearchs(
+			     'part_pkg', { 'pkgpart'=>shift }
+			   );
+                           $part_pkg ? $part_pkg->pkg : '';
+			 },
+  },
+
+  {
     'key'         => 'batch-enable',
     'section'     => 'billing',
     'description' => 'Enable credit card and/or ACH batching - leave disabled for real-time installations.',

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.271.2.49
retrieving revision 1.271.2.50
diff -u -d -r1.271.2.49 -r1.271.2.50
--- cust_main.pm	18 Jun 2008 05:23:56 -0000	1.271.2.49
+++ cust_main.pm	24 Jun 2008 16:39:10 -0000	1.271.2.50
@@ -1923,13 +1923,12 @@
   # & generate invoice database.
   ###
 
-  my( $total_setup, $total_recur ) = ( 0, 0 );
+  my( $total_setup, $total_recur, $postal_charge ) = ( 0, 0, 0 );
   my %tax;
   my @precommit_hooks = ();
 
-  foreach my $cust_pkg (
-    qsearch('cust_pkg', { 'custnum' => $self->custnum } )
-  ) {
+  my @cust_pkgs = qsearch('cust_pkg', { 'custnum' => $self->custnum } );
+  foreach my $cust_pkg (@cust_pkgs) {
 
     #NO!! next if $cust_pkg->cancel;  
     next if $cust_pkg->getfield('cancel');  
@@ -2074,6 +2073,17 @@
 
       if ( $setup != 0 || $recur != 0 ) {
 
+        unless ($postal_charge) {
+          $postal_charge = 1;  # try only once
+          my $postal_pkg = $self->charge_postal_fee();
+          if ( $postal_pkg && !ref( $postal_pkg ) ) {
+            $dbh->rollback if $oldAutoCommit;
+            return "can't charge postal invoice fee for customer ".
+              $self->custnum. ": $postal_pkg";
+          }
+          push @cust_pkgs, $postal_pkg if $postal_pkg;
+        }
+
         warn "    charges (setup=$setup, recur=$recur); adding line items\n"
           if $DEBUG > 1;
         my $cust_bill_pkg = new FS::cust_bill_pkg ({
@@ -4221,6 +4231,33 @@
 
 }
 
+#=item charge_postal_fee
+#
+#Applies a one time charge this customer.  If there is an error,
+#returns the error, returns the cust_pkg charge object or false
+#if there was no charge.
+#
+#=cut
+#
+# This should be a customer event.  For that to work requires that bill
+# also be a customer event.
+
+sub charge_postal_fee {
+  my $self = shift;
+
+  my $pkgpart = $conf->config('postal_invoice-fee_pkgpart');
+  return '' unless ($pkgpart && grep { $_ eq 'POST' } $self->invoicing_list);
+
+  my $cust_pkg = new FS::cust_pkg ( {
+    'custnum'  => $self->custnum,
+    'pkgpart'  => $pkgpart,
+    'quantity' => 1,
+  } );
+
+  my $error = $cust_pkg->insert;
+  $error ? $error : $cust_pkg;
+}
+
 =item cust_bill
 
 Returns all the invoices (see L<FS::cust_bill>) for this customer.



More information about the freeside-commits mailing list