From 105c166a23234dd923757a477b4efcda65fb2881 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 18 Mar 2002 20:51:09 +0000 Subject: okay, now you can specify an alternate invoice template, and it'll be auto-createad and added to the list of configuration options. closes: Bug#314 --- FS/FS/Conf.pm | 36 +++++++++++++++++++++++++++--------- FS/FS/part_bill_event.pm | 19 ++++++++++++++++++- httemplate/edit/part_bill_event.cgi | 8 ++++++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index a3269b1c4..e1384bd4c 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -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. =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 billing documentation 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. diff --git a/FS/FS/part_bill_event.pm b/FS/FS/part_bill_event.pm index 70c8a56ec..40f7fc79d 100644 --- a/FS/FS/part_bill_event.pm +++ b/FS/FS/part_bill_event.pm @@ -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 diff --git a/httemplate/edit/part_bill_event.cgi b/httemplate/edit/part_bill_event.cgi index 018fc94a4..324daeb90 100755 --- a/httemplate/edit/part_bill_event.cgi +++ b/httemplate/edit/part_bill_event.cgi @@ -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' => + '', + 'weight' => 50, + }, + 'bill' => { 'name' => 'Generate invoices (normally only used with a Late Fee event)', 'code' => '$cust_main->bill();', -- cgit v1.2.1