for new installs, centralize some stuff that was spread around different config files.
authorivan <ivan>
Thu, 8 Nov 2007 00:59:35 +0000 (00:59 +0000)
committerivan <ivan>
Thu, 8 Nov 2007 00:59:35 +0000 (00:59 +0000)
15 files changed:
FS/FS/Conf.pm
FS/FS/cust_bill.pm
FS/FS/cust_main.pm
FS/bin/freeside-expiration-alerter
conf/alerter_template
conf/company_address [new file with mode: 0644]
conf/company_name [new file with mode: 0644]
conf/impending_recur_template
conf/invoice_latexfooter
conf/invoice_latexnotes
conf/invoice_latexreturnaddress [deleted file]
conf/invoice_latexsmallfooter
conf/invoice_template
conf/invoice_template_statement
conf/welcome_letter

index adc5b0e..ed05811 100644 (file)
@@ -732,7 +732,7 @@ worry that config_items is freeside-specific and icky.
 
   {
     '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 @@ worry that config_items is freeside-specific and icky.
 
   {
     '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 @@ worry that config_items is freeside-specific and icky.
 
   {
     '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 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    '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 07aa367..ccbcdf2 100644 (file)
@@ -1681,8 +1681,10 @@ sub print_text {
 
   #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 @@ sub print_text {
        #    && $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 @@ sub print_latex {
 
   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 @@ sub print_latex {
     $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 )) {
+
+    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";
 
-  $invoice_data{'footer'} =~ s/\n+$//;
-  $invoice_data{'smallfooter'} =~ s/\n+$//;
-  $invoice_data{'notes'} =~ s/\n+$//;
+    $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 @@ sub print_html {
     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 @@ sub print_html {
                                            $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 06f2c46..214e943 100644 (file)
@@ -5752,6 +5752,10 @@ sub notify {
   $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 @@ I<$payby> - a description of the method of payment for the customer
             # 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 @@ sub generate_letter {
     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,
index e49bd62..ffd75f9 100755 (executable)
@@ -138,6 +138,10 @@ foreach my $customer (@customers)
         }
         $FS::alerter::_template::expdate = $expire_time;
 
+        $FS::alerter::_template::company_name = $conf->config('company_name');
+        $FS::alerter::_template::company_address =
+          join("\n", $conf->config('company_address') ). "\n";
+
         my $message = new Mail::Internet (
           'Header' => $header,
           'Body' => [ $alerter->fill_in( PACKAGE => 'FS::alerter::_template' ) ],
index 5177e4e..6fb66b7 100644 (file)
@@ -1,20 +1,18 @@
 
 
-Ivan Kohler
-12345 Test Lane
-Truckee, CA  96161
+{ $company_name; }
+{ $company_address; }
 
 
 { $first; } { $last; }:
 
   We thank you for your continuing patronage.  This notice is to remind you
-that your { $payby } used to pay SISD.COM for Internet
-service will expire on { use Date::Format; time2str("%x", $expdate); }.  Please provide us with new billing
-information so that we may continue your service uninterrupted.
+that your { $payby } used to pay { $company_name; } for Internet
+service will expire on { use Date::Format; time2str("%B %o, %Y", $expdate); }.  Please provide us with new
+billing information so that we may continue your service uninterrupted.
 
 Very Truly Yours,
 
-  SISD Service Team
-
+  { $company_name; } Service Team
 
 
diff --git a/conf/company_address b/conf/company_address
new file mode 100644 (file)
index 0000000..3824862
--- /dev/null
@@ -0,0 +1,2 @@
+1234 Example Lane
+Exampleton, CA  54321
diff --git a/conf/company_name b/conf/company_name
new file mode 100644 (file)
index 0000000..2cd5323
--- /dev/null
@@ -0,0 +1 @@
+ExampleCo
index 9075ac8..deb396a 100644 (file)
@@ -1,20 +1,20 @@
 
 
-Ivan Kohler
-12345 Test Lane
-Truckee, CA  96161
+{ $company_name; }
+{ $company_address; }
 
 
 { $first; } { $last; }:
 
   We thank you for your continuing patronage.  This notice is to remind you
-that your { $packages->[0] } Internet service will expire on { use Date::Format; time2str("%x", $recurdates->[0]); }.
+that your { $packages->[0] } Internet service
+will expire on { use Date::Format; time2str("%B %o, %Y", $recurdates->[0]); }.
 At that time we will begin charging you on a recurring basis so that we may
 continue your service uninterrupted.
 
 Very Truly Yours,
 
-  SISD Service Team
+  { $company_name; } Service Team
 
 
 
index 527c356..2e32123 100644 (file)
@@ -1 +1 @@
-Ivan Kohler~~~Freeside - open-source billing
+[@-- $company_name --@]
index 46af6d6..5303d3c 100644 (file)
@@ -3,6 +3,6 @@
 %%
 \section*{\textsc{Notes}}
 \begin{enumerate}
-\item Please make your check payable to \textbf{Ivan Kohler}.
+\item Please make your check payable to \textbf{[@-- $company_name --@]}.
 \item If you have any questions please email or telephone.
 \end{enumerate}
diff --git a/conf/invoice_latexreturnaddress b/conf/invoice_latexreturnaddress
deleted file mode 100644 (file)
index 95067e2..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-Ivan Kohler\\*
-12345 Test Lane\\*
-Truckee, CA~~96161
index 527c356..2e32123 100644 (file)
@@ -1 +1 @@
-Ivan Kohler~~~Freeside - open-source billing
+[@-- $company_name --@]
index 4b2c64b..b33c4dd 100644 (file)
@@ -1,11 +1,10 @@
 
                                  Invoice
-                                 { substr("Page $page of $total_pages          ", 0, 19); } { use Date::Format; time2str("%x", $date); }  FS-{ $invnum; }
+                                 { substr("Page $page of $total_pages          ", 0, 19); } { use Date::Format; time2str("%x", $date); }  Invoice #{ $invnum; }
 
 
-Ivan Kohler
-12345 Test Lane
-Truckee, CA  96161
+{ $company_name; }
+{ $company_address; }
 
 
 { $address[0]; }
@@ -24,4 +23,4 @@ Truckee, CA  96161
   );
 }
 
- -=> Freeside - open-source billing for ISPs - http://www.sisd.com/freeside <=-
+ -=> { $company_name; } <=-
index 674416a..db02915 100644 (file)
@@ -1,11 +1,10 @@
 
                                  Statement
-                                 { substr("Page $page of $total_pages          ", 0, 19); } { use Date::Format; time2str("%x", $date); }  FS-{ $invnum; }
+                                 { substr("Page $page of $total_pages          ", 0, 19); } { use Date::Format; time2str("%x", $date); }  Invoice #{ $invnum; }
 
 
-Ivan Kohler
-12345 Test Lane
-Truckee, CA  96161
+{ $company_name; }
+{ $company_address; }
 
 
 { $address[0]; }
@@ -24,4 +23,4 @@ Truckee, CA  96161
   );
 }
 
- -=> Freeside - open-source billing for ISPs - http://www.sisd.com/freeside <=-
+ -=> { $company_name; } <=-
index 3fcf04e..be7b484 100644 (file)
 %  Your content goes here
 Dear [@-- $first --@] [@-- $last --@]:\\
 \\
-  Thank you for choosing Freeside.  We aim to meet all the billing needs of
-  [@-- $company --@].  Please do not hesitate to contact us for any additional
-  service or features you require.\\
+  Thank you for choosing [@-- $company_name --@].  We aim to meet all of your
+  needs.  Please do not hesitate to contact us for any additional
+  services or assistance.\\
 
 \end{document}