package FS::Template_Mixin; use strict; use vars qw( $DEBUG $me $money_char $date_format ); # but NOT $conf use vars qw( $invoice_lines @buf ); #yuck use List::Util qw(sum); #can't import first, it conflicts with cust_main.first use Date::Format; use Date::Language; use Time::Local qw( timelocal ); use Text::Template 1.20; use File::Temp 0.14; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use IO::Scalar; use HTML::Entities; use Cwd; use FS::UID; use FS::Misc qw( send_email ); use FS::Record qw( qsearch qsearchs dbh ); use FS::Conf; use FS::Misc qw( generate_ps generate_pdf ); use FS::pkg_category; use FS::pkg_class; use FS::invoice_mode; use FS::L10N; $DEBUG = 0; $me = '[FS::Template_Mixin]'; FS::UID->install_callback( sub { my $conf = new FS::Conf; #global $money_char = $conf->config('money_char') || '$'; $date_format = $conf->config('date_format') || '%x'; #/YY } ); =item conf [ MODE ] Returns a configuration handle (L) set to the customer's locale. If the "mode" pseudo-field is set on the object, the configuration handle will be an L for that invoice mode (and the customer's locale). =cut sub conf { my $self = shift; my $mode = $self->get('mode'); if ($self->{_conf} and !defined($mode)) { return $self->{_conf}; } my $cust_main = $self->cust_main; my $locale = $cust_main ? $cust_main->locale : ''; my $conf; if ( $mode ) { if ( ref $mode and $mode->isa('FS::invoice_mode') ) { $mode = $mode->modenum; } elsif ( $mode =~ /\D/ ) { die "invalid invoice mode $mode"; } $conf = qsearchs('invoice_conf', { modenum => $mode, locale => $locale }); if (!$conf) { $conf = qsearchs('invoice_conf', { modenum => $mode, locale => '' }); # it doesn't have a locale, but system conf still might $conf->set('locale' => $locale) if $conf; } } # if $mode is unspecified, or if there is no invoice_conf matching this mode # and locale, then use the system config only (but with the locale) $conf ||= FS::Conf->new({ 'locale' => $locale }); # cache it return $self->{_conf} = $conf; } =item print_text OPTIONS Returns an text invoice, as a list of lines. Options can be passed as a hash. I