From eb3bd392a89b8b666dc512951e78913c05b98810 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 27 Sep 2013 17:19:36 -0700 Subject: [PATCH] invoice configurations, #24723 --- FS/FS/Mason.pm | 2 + FS/FS/Schema.pm | 45 ++++ FS/FS/Template_Mixin.pm | 117 +++++--- FS/FS/agent.pm | 17 ++ FS/FS/cust_bill.pm | 274 ++++++------------- FS/FS/cust_main.pm | 4 +- FS/FS/invoice_conf.pm | 274 +++++++++++++++++++ FS/FS/invoice_mode.pm | 157 +++++++++++ FS/FS/part_event/Action/cust_bill_email.pm | 10 +- FS/FS/part_event/Action/cust_bill_print.pm | 9 + FS/FS/part_event/Action/cust_bill_print_pdf.pm | 9 + FS/FS/part_event/Action/cust_bill_send.pm | 9 + FS/FS/part_event/Action/cust_bill_send_agent.pm | 17 +- .../part_event/Action/cust_bill_send_alternate.pm | 5 +- .../part_event/Action/cust_bill_send_if_newest.pm | 18 +- FS/FS/part_event/Action/cust_bill_send_reminder.pm | 12 +- FS/FS/part_event/Action/cust_statement_send.pm | 3 +- FS/MANIFEST | 4 + FS/t/invoice_conf.t | 5 + FS/t/invoice_mode.t | 5 + bin/generate-table-module | 4 +- httemplate/browse/invoice_conf.html | 70 +++++ httemplate/edit/elements/edit.html | 1 + httemplate/edit/invoice_conf.html | 296 +++++++++++++++++++++ httemplate/edit/process/invoice_conf.html | 21 ++ httemplate/elements/columnstart.html | 77 +++++- httemplate/elements/menu.html | 1 + httemplate/elements/tr-select-invoice_mode.html | 10 + httemplate/misc/delete-invoice_conf.html | 19 ++ httemplate/misc/email-invoice.cgi | 2 +- httemplate/misc/fax-invoice.cgi | 2 +- httemplate/misc/print-invoice.cgi | 2 +- httemplate/misc/send-invoice.cgi | 5 + httemplate/view/cust_bill.cgi | 35 ++- httemplate/view/cust_statement.html | 4 +- httemplate/view/elements/cust_bill-typeset | 7 +- 36 files changed, 1284 insertions(+), 268 deletions(-) create mode 100644 FS/FS/invoice_conf.pm create mode 100644 FS/FS/invoice_mode.pm create mode 100644 FS/t/invoice_conf.t create mode 100644 FS/t/invoice_mode.t create mode 100644 httemplate/browse/invoice_conf.html create mode 100644 httemplate/edit/invoice_conf.html create mode 100644 httemplate/edit/process/invoice_conf.html create mode 100644 httemplate/elements/tr-select-invoice_mode.html create mode 100644 httemplate/misc/delete-invoice_conf.html diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index 780e3ffaf..f1fc5cba4 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -353,6 +353,8 @@ if ( -e $addl_handler_use_file ) { use FS::sales_pkg_class; use FS::svc_alarm; use FS::cable_model; + use FS::invoice_mode; + use FS::invoice_conf; # Sammath Naur if ( $FS::Mason::addl_handler_use ) { diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index ed3790452..16546b32d 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -4377,6 +4377,51 @@ sub tables_hashref { 'index' => [ [ 'derivenum', ], ], }, + 'invoice_mode' => { + 'columns' => [ + 'modenum', 'serial', '', '', '', '', + 'agentnum', 'int', 'NULL', '', '', '', + 'modename', 'varchar', '', 32, '', '', + ], + 'primary_key' => 'modenum', + 'unique' => [ ], + 'index' => [ ], + }, + + 'invoice_conf' => { + 'columns' => [ + 'confnum', 'serial', '', '', '', '', + 'modenum', 'int', '', '', '', '', + 'locale', 'varchar', 'NULL', 16, '', '', + 'notice_name', 'varchar', 'NULL', 64, '', '', + 'subject', 'varchar', 'NULL', 64, '', '', + 'htmlnotes', 'text', 'NULL', '', '', '', + 'htmlfooter', 'text', 'NULL', '', '', '', + 'htmlsummary', 'text', 'NULL', '', '', '', + 'htmlreturnaddress', 'text', 'NULL', '', '', '', + 'latexnotes', 'text', 'NULL', '', '', '', + 'latexfooter', 'text', 'NULL', '', '', '', + 'latexsummary', 'text', 'NULL', '', '', '', + 'latexcoupon', 'text', 'NULL', '', '', '', + 'latexsmallfooter', 'text', 'NULL', '', '', '', + 'latexreturnaddress', 'text', 'NULL', '', '', '', + 'latextopmargin', 'varchar', 'NULL', 16, '', '', + 'latexheadsep', 'varchar', 'NULL', 16, '', '', + 'latexaddresssep', 'varchar', 'NULL', 16, '', '', + 'latextextheight', 'varchar', 'NULL', 16, '', '', + 'latexextracouponspace','varchar', 'NULL', 16, '', '', + 'latexcouponfootsep', 'varchar', 'NULL', 16, '', '', + 'latexcouponamountenclosedsep', 'varchar', 'NULL', 16, '', '', + 'latexcoupontoaddresssep', 'varchar', 'NULL', 16, '', '', + 'latexverticalreturnaddress', 'char', 'NULL', 1, '', '', + 'latexcouponaddcompanytoaddress', 'char', 'NULL', 1, '', '', + 'logo_png', 'blob', 'NULL', '', '', '', + 'logo_eps', 'blob', 'NULL', '', '', '', + 'lpr', 'varchar', 'NULL', $char_d, '', '', + ], + 'primary_key' => 'confnum', + 'unique' => [ [ 'modenum', 'locale' ] ], + }, # name type nullability length default local diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 356de5bed..840df7558 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -18,6 +18,7 @@ use FS::Record qw( qsearch qsearchs ); 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; @@ -30,12 +31,51 @@ FS::UID->install_callback( sub { $date_format_long = $conf->config('date_format_long') || '%b %o, %Y'; } ); -=item print_text HASHREF | [ TIME [ , TEMPLATE [ , OPTION => VALUE ... ] ] ] +=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 hashref (recommended) or as a list of time, template -and then any key/value pairs for any other options. +Options can be passed as a hash. I