okay, now you can specify an alternate invoice template, and it'll
authorivan <ivan>
Mon, 18 Mar 2002 20:51:09 +0000 (20:51 +0000)
committerivan <ivan>
Mon, 18 Mar 2002 20:51:09 +0000 (20:51 +0000)
be auto-createad and added to the list of configuration options.
closes: Bug#314

FS/FS/Conf.pm
FS/FS/part_bill_event.pm
httemplate/edit/part_bill_event.cgi

index a3269b1..e1384bd 100644 (file)
@@ -2,6 +2,7 @@ package FS::Conf;
 
 use vars qw($default_dir @config_items $DEBUG );
 use IO::File;
+use File::Basename;
 use FS::ConfItem;
 
 $DEBUG = 0;
@@ -25,6 +26,10 @@ FS::Conf - Freeside configuration values
   @list  = $conf->config('key');
   $bool  = $conf->exists('key');
 
+  $conf->touch('key');
+  $conf->set('key' => 'value');
+  $conf->delete('key');
+
   @config_items = $conf->config_items;
 
 =head1 DESCRIPTION
@@ -67,7 +72,7 @@ sub dir {
   $1;
 }
 
-=item config 
+=item config KEY
 
 Returns the configuration value or values (depending on context) for key.
 
@@ -90,7 +95,7 @@ sub config {
   }
 }
 
-=item exists
+=item exists KEY
 
 Returns true if the specified key exists, even if the corresponding value
 is undefined.
@@ -103,7 +108,9 @@ sub exists {
   -e "$dir/$file";
 }
 
-=item touch
+=item touch KEY
+
+Creates the specified configuration key if it does not exist.
 
 =cut
 
@@ -116,7 +123,9 @@ sub touch {
   }
 }
 
-=item set
+=item set KEY VALUE
+
+Sets the specified configuration key to the given value.
 
 =cut
 
@@ -139,7 +148,9 @@ sub set {
 #             return ! eval { join('',@_), kill 0; 1; };
 #         }
 
-=item delete
+=item delete KEY
+
+Deletes the specified configuration key.
 
 =cut
 
@@ -160,16 +171,23 @@ L<FS::ConfItem>.
 =cut
 
 sub config_items {
-#  my $self = shift; 
-  @config_items;
+  my $self = shift; 
+  #quelle kludge
+  @config_items,
+  map { new FS::ConfItem {
+                           'key'         => basename($_),
+                           'section'     => 'billing',
+                           'description' => 'Alternate template file for invoices.  See the <a href="../docs/billing.html">billing documentation</a> for details.',
+                           'type'        => 'textarea',
+                         }
+      } glob($self->dir. '/invoice_template_*')
+  ;
 }
 
 =back
 
 =head1 BUGS
 
-Write access (touch, set, delete) should be documented.
-
 If this was more than just crud that will never be useful outside Freeside I'd
 worry that config_items is freeside-specific and icky.
 
index 70c8a56..40f7fc7 100644 (file)
@@ -126,6 +126,8 @@ sub check {
 
       or $c =~ /^\s*\$cust_bill\->(comp|realtime_card|realtime_card_cybercash|batch_card|send)\(\);\s*$/
 
+      or $c =~ /^\s*\$cust_bill\->send\(\'\w+\'\);\s*$/
+
       or $c =~ /^\s*\$cust_main\->apply_payments; \$cust_main->apply_credits; "";\s*$/
 
       or $c =~ /^\s*\$cust_main\->charge\( \s*\d*\.?\d*\s*,\s*\'[\w \!\@\#\$\%\&\(\)\-\+\;\:\"\,\.\?\/]*\'\s*\);\s*$/
@@ -137,7 +139,7 @@ sub check {
 
   }
 
-  $self->ut_numbern('eventpart')
+  my $error = $self->ut_numbern('eventpart')
     || $self->ut_enum('payby', [qw( CARD BILL COMP )] )
     || $self->ut_text('event')
     || $self->ut_anything('eventcode')
@@ -147,6 +149,21 @@ sub check {
     || $self->ut_textn('plan')
     || $self->ut_anything('plandata')
   ;
+  return $error if $error;
+
+  #quelle kludge
+  if ( $self->plandata =~ /^templatename\s+(.*)$/ ) {
+    my $name= $1;
+    unless ( $conf->config("invoice_template_$name") ) {
+      $conf->set(
+        "invoice_template_$name" =>
+          join("\n", $conf->config('invoice_template') )
+      );
+    }
+  }
+
+  '';
+
 }
 
 =back
index 018fc94..324daeb 100755 (executable)
@@ -126,6 +126,14 @@ tie my %events, 'Tie::IxHash',
     'weight' => 50,
   },
 
+  'send_alternate' => {
+    'name' => 'Send invoice (email/print) with alternate template',
+    'code' => '$cust_bill->send(\'%%%templatename%%%\');',
+    'html' =>
+        '<INPUT TYPE="text" NAME="templatename" VALUE="%%%templatename%%%">',
+    'weight' => 50,
+  },
+
   'bill' => {
     'name' => 'Generate invoices (normally only used with a <i>Late Fee</i> event)',
     'code' => '$cust_main->bill();',