[freeside-commits] freeside/FS/FS Conf.pm, 1.210, 1.211 cust_bill.pm, 1.178, 1.179 cust_main.pm, 1.318, 1.319

Ivan,,, ivan at wavetail.420.am
Wed Nov 7 16:59:37 PST 2007


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv16758/FS/FS

Modified Files:
	Conf.pm cust_bill.pm cust_main.pm 
Log Message:
for new installs, centralize some stuff that was spread around different config files.

Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.210
retrieving revision 1.211
diff -u -d -r1.210 -r1.211
--- Conf.pm	9 Oct 2007 04:58:49 -0000	1.210
+++ Conf.pm	8 Nov 2007 00:59:34 -0000	1.211
@@ -732,7 +732,7 @@
 
   {
     'key'         => 'home',
-    'section'     => 'required',
+    'section'     => 'shell',
     'description' => 'For new users, prefixed to username to create a directory name.  Should have a leading but not a trailing slash.',
     'type'        => 'text',
   },
@@ -746,8 +746,8 @@
 
   {
     'key'         => 'invoice_template',
-    'section'     => 'required',
-    'description' => 'Required template file for invoices.  See the <a href="http://www.sisd.com/mediawiki/index.php/Freeside:1.7:Documentation:Administration#Plaintext_invoice_templates">billing documentation</a> for details.',
+    'section'     => 'billing',
+    'description' => 'Text template file for invoices.  Used if no invoice_html template is defined, and also seen by users using non-HTML capable mail clients.  See the <a href="http://www.sisd.com/mediawiki/index.php/Freeside:1.7:Documentation:Administration#Plaintext_invoice_templates">billing documentation</a> for details.',
     'type'        => 'textarea',
   },
 
@@ -949,7 +949,7 @@
 
   {
     'key'         => 'shells',
-    'section'     => 'required',
+    'section'     => 'shell',
     'description' => 'Legal shells (think /etc/shells).  You probably want to `cut -d: -f7 /etc/passwd | sort | uniq\' initially so that importing doesn\'t fail with `Illegal shell\' errors, then remove any special entries afterwords.  A blank line specifies that an empty shell is permitted.',
     'type'        => 'textarea',
   },
@@ -1700,6 +1700,13 @@
   },
 
   {
+    'key'         => 'company_address',
+    'section'     => 'required',
+    'description' => 'Your company address',
+    'type'        => 'textarea',
+  },
+
+  {
     'key'         => 'address2-search',
     'section'     => 'UI',
     'description' => 'Enable a "Unit" search box which searches the second address field',

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -d -r1.178 -r1.179
--- cust_bill.pm	29 Oct 2007 10:30:52 -0000	1.178
+++ cust_bill.pm	8 Nov 2007 00:59:34 -0000	1.179
@@ -1681,8 +1681,10 @@
 
   #setup template variables
   package FS::cust_bill::_template; #!
-  use vars qw( $custnum $invnum $date $agent @address $overdue
-               $page $total_pages @buf );
+  use vars qw( $company_name $company_address
+               $custnum $invnum $date $agent @address $overdue
+               $page $total_pages @buf
+             );
 
   $custnum = $self->custnum;
   $invnum = $self->invnum;
@@ -1730,6 +1732,10 @@
 	#    && $self->printed > 0
 	#  );
 
+  $FS::cust_bill::_template::company_name = $conf->config('company_name');
+  $FS::cust_bill::_template::company_address =
+    join("\n", $conf->config('company_address') ). "\n";
+
   #and subroutine for the template
   sub FS::cust_bill::_template::invoice_lines {
     my $lines = shift || scalar(@buf);
@@ -1814,34 +1820,49 @@
 
   my $returnaddress;
   if ( length($conf->config_orbase('invoice_latexreturnaddress', $template)) ) {
+
     $returnaddress = join("\n",
       $conf->config_orbase('invoice_latexreturnaddress', $template)
     );
+
+  } elsif ( grep /\S/, $conf->config('company_address') ) {
+
+    $returnaddress =
+      join( '\\*'."\n", map s/( {2,})/'~' x length($1)/eg,
+                            $conf->config('company_address')
+          );
+
   } else {
+
+    my $warning = "Couldn't find a return address; ".
+                  "do you need to set the company_address configuration value?";
+    warn "$warning\n";
     $returnaddress = '~';
+    #$returnaddress = $warning;
+
   }
 
   my %invoice_data = (
-    'custnum'      => $self->custnum,
-    'invnum'       => $self->invnum,
-    'date'         => time2str('%b %o, %Y', $self->_date),
-    'today'        => time2str('%b %o, %Y', $today),
-    'agent'        => _latex_escape($cust_main->agent->agent),
-    'payname'      => _latex_escape($cust_main->payname),
-    'company'      => _latex_escape($cust_main->company),
-    'address1'     => _latex_escape($cust_main->address1),
-    'address2'     => _latex_escape($cust_main->address2),
-    'city'         => _latex_escape($cust_main->city),
-    'state'        => _latex_escape($cust_main->state),
-    'zip'          => _latex_escape($cust_main->zip),
-    'footer'       => join("\n", $conf->config_orbase('invoice_latexfooter', $template) ),
-    'smallfooter'  => join("\n", $conf->config_orbase('invoice_latexsmallfooter', $template) ),
-    'returnaddress' => $returnaddress,
-    'quantity'     => 1,
-    'terms'        => $self->terms,
-    #'notes'        => join("\n", $conf->config('invoice_latexnotes') ),
+    'company_name'    => $conf->config('company_name'),
+    'company_address' => join("\n", $conf->config('company_address') ). "\n",
+    'custnum'         => $self->custnum,
+    'invnum'          => $self->invnum,
+    'date'            => time2str('%b %o, %Y', $self->_date),
+    'today'           => time2str('%b %o, %Y', $today),
+    'agent'           => _latex_escape($cust_main->agent->agent),
+    'payname'         => _latex_escape($cust_main->payname),
+    'company'         => _latex_escape($cust_main->company),
+    'address1'        => _latex_escape($cust_main->address1),
+    'address2'        => _latex_escape($cust_main->address2),
+    'city'            => _latex_escape($cust_main->city),
+    'state'           => _latex_escape($cust_main->state),
+    'zip'             => _latex_escape($cust_main->zip),
+    'returnaddress'   => $returnaddress,
+    'quantity'        => 1,
+    'terms'           => $self->terms,
+    #'notes'           => join("\n", $conf->config('invoice_latexnotes') ),
     # better hang on to conf_dir for a while
-    'conf_dir'     => "$FS::UID::conf_dir/conf.$FS::UID::datasrc",
+    'conf_dir'        => "$FS::UID::conf_dir/conf.$FS::UID::datasrc",
   );
 
   my $countrydefault = $conf->config('countrydefault') || 'US';
@@ -1851,18 +1872,24 @@
     $invoice_data{'country'} = _latex_escape(code2country($cust_main->country));
   }
 
-  $invoice_data{'notes'} =
-    join("\n",
-#  #do variable substitutions in notes
-#      map { my $b=$_; $b =~ s/\$(\w+)/$invoice_data{$1}/eg; $b }
-        $conf->config_orbase('invoice_latexnotes', $template)
-    );
-  warn "invoice notes: ". $invoice_data{'notes'}. "\n"
-    if $DEBUG;
+  #do variable substitution in notes, footer, smallfooter
+  foreach my $include (qw( notes footer smallfooter )) {
 
-  $invoice_data{'footer'} =~ s/\n+$//;
-  $invoice_data{'smallfooter'} =~ s/\n+$//;
-  $invoice_data{'notes'} =~ s/\n+$//;
+    my $inc_tt = new Text::Template (
+      TYPE       => 'ARRAY',
+      SOURCE     => [ map "$_\n",
+                      $conf->config_orbase("invoice_latex$include", $template )
+                    ],
+      DELIMITERS => [ '[@--', '--@]' ],
+    ) or die "can't create new Text::Template object: $Text::Template::ERROR";
+
+    $inc_tt->compile()
+      or die "can't compile template: $Text::Template::ERROR";
+
+    $invoice_data{$include} = $inc_tt->fill_in( HASH => \%invoice_data );
+
+    $invoice_data{$include} =~ s/\n+$//;
+  }
 
   $invoice_data{'po_line'} =
     (  $cust_main->payby eq 'BILL' && $cust_main->payinfo )
@@ -2217,31 +2244,37 @@
     or die 'While compiling ' . $templatefile . ': ' . $Text::Template::ERROR;
 
   my %invoice_data = (
-    'custnum'      => $self->custnum,
-    'invnum'       => $self->invnum,
-    'date'         => time2str('%b&nbsp;%o,&nbsp;%Y', $self->_date),
-    'today'        => time2str('%b %o, %Y', $today),
-    'agent'        => encode_entities($cust_main->agent->agent),
-    'payname'      => encode_entities($cust_main->payname),
-    'company'      => encode_entities($cust_main->company),
-    'address1'     => encode_entities($cust_main->address1),
-    'address2'     => encode_entities($cust_main->address2),
-    'city'         => encode_entities($cust_main->city),
-    'state'        => encode_entities($cust_main->state),
-    'zip'          => encode_entities($cust_main->zip),
-    'terms'        => $self->terms,
-    'cid'          => $cid,
-    'template'     => $template,
-#    'conf_dir'     => "$FS::UID::conf_dir/conf.$FS::UID::datasrc",
+    'company_name'    => $conf->config('company_name'),
+    'company_address' => join("\n", $conf->config('company_address') ). "\n",
+    'custnum'         => $self->custnum,
+    'invnum'          => $self->invnum,
+    'date'            => time2str('%b&nbsp;%o,&nbsp;%Y', $self->_date),
+    'today'           => time2str('%b %o, %Y', $today),
+    'agent'           => encode_entities($cust_main->agent->agent),
+    'payname'         => encode_entities($cust_main->payname),
+    'company'         => encode_entities($cust_main->company),
+    'address1'        => encode_entities($cust_main->address1),
+    'address2'        => encode_entities($cust_main->address2),
+    'city'            => encode_entities($cust_main->city),
+    'state'           => encode_entities($cust_main->state),
+    'zip'             => encode_entities($cust_main->zip),
+    'terms'           => $self->terms,
+    'cid'             => $cid,
+    'template'        => $template,
+#    'conf_dir'        => "$FS::UID::conf_dir/conf.$FS::UID::datasrc",
   );
 
   if (
          defined( $conf->config_orbase('invoice_htmlreturnaddress', $template) )
       && length(  $conf->config_orbase('invoice_htmlreturnaddress', $template) )
   ) {
+
     $invoice_data{'returnaddress'} =
       join("\n", $conf->config('invoice_htmlreturnaddress', $template) );
-  } else {
+
+  } elsif ( grep /\S/,
+            $conf->config_orbase( 'invoice_latexreturnaddress', $template ) ) {
+
     $invoice_data{'returnaddress'} =
       join("\n", map { 
                        s/~/&nbsp;/g;
@@ -2253,6 +2286,19 @@
                                            $template
                                          )
           );
+
+  } elsif ( grep /\S/, $conf->config('company_address') ) {
+
+    $invoice_data{'returnaddress'} =
+      join("\n", $conf->config('company_address') );
+
+  } else {
+
+    my $warning = "Couldn't find a return address; ".
+                  "do you need to set the company_address configuration value?";
+    warn "$warning\n";
+    #$invoice_data{'returnaddress'} = $warning;
+
   }
 
   my $countrydefault = $conf->config('countrydefault') || 'US';

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.318
retrieving revision 1.319
diff -u -d -r1.318 -r1.319
--- cust_main.pm	29 Oct 2007 10:31:31 -0000	1.318
+++ cust_main.pm	8 Nov 2007 00:59:34 -0000	1.319
@@ -5752,6 +5752,10 @@
   $notify_template->compile()
     or die "can't compile template: Text::Template::ERROR";
 
+  $FS::notify_template::_template::company_name = $conf->config('company_name');
+  $FS::notify_template::_template::company_address =
+    join("\n", $conf->config('company_address') ). "\n";
+
   my $paydate = $customer->paydate;
   $FS::notify_template::_template::first = $customer->first;
   $FS::notify_template::_template::last = $customer->last;
@@ -5805,7 +5809,7 @@
             # would be nice to use FS::payby::shortname
 I<$payinfo> - the masked account information used to collect for this customer
 I<$expdate> - the expiration of the customer payment method in seconds from epoch
-I<$returnaddress> - the return address defaults to invoice_latexreturnaddress
+I<$returnaddress> - the return address defaults to invoice_latexreturnaddress or company_address
 
 =cut
 
@@ -5855,12 +5859,22 @@
     my $retadd = join("\n", $conf->config_orbase( 'invoice_latexreturnaddress',
                                                   $self->agent_template)
                      );
-
-    $letter_data{returnaddress} = length($retadd) ? $retadd : '~';
+    if ( length($retadd) ) {
+      $letter_data{returnaddress} = $retadd;
+    } elsif ( grep /\S/, $conf->config('company_address') ) {
+      $letter_data{returnaddress} =
+        join( '\\*'."\n", map s/( {2,})/'~' x length($1)/eg,
+                          $conf->config('company_address')
+        );
+    } else {
+      $letter_data{returnaddress} = '~';
+    }
   }
 
   $letter_data{conf_dir} = "$FS::UID::conf_dir/conf.$FS::UID::datasrc";
 
+  $letter_data{company_name} = $conf->config('company_name');
+
   my $dir = $FS::UID::conf_dir."cache.". $FS::UID::datasrc;
   my $fh = new File::Temp( TEMPLATE => 'letter.'. $self->custnum. '.XXXXXXXX',
                            DIR      => $dir,



More information about the freeside-commits mailing list