summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-09-27 17:19:36 -0700
committerMark Wells <mark@freeside.biz>2013-09-27 17:19:36 -0700
commiteb3bd392a89b8b666dc512951e78913c05b98810 (patch)
tree22670bdf99b0a473abb708f6f5c55cbfa2f0c249 /httemplate
parente3012c0751dad6710ea35b6d074b551bffdad09b (diff)
invoice configurations, #24723
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/browse/invoice_conf.html70
-rw-r--r--httemplate/edit/elements/edit.html1
-rw-r--r--httemplate/edit/invoice_conf.html296
-rw-r--r--httemplate/edit/process/invoice_conf.html21
-rw-r--r--httemplate/elements/columnstart.html77
-rw-r--r--httemplate/elements/menu.html1
-rw-r--r--httemplate/elements/tr-select-invoice_mode.html10
-rw-r--r--httemplate/misc/delete-invoice_conf.html19
-rwxr-xr-xhttemplate/misc/email-invoice.cgi2
-rwxr-xr-xhttemplate/misc/fax-invoice.cgi2
-rwxr-xr-xhttemplate/misc/print-invoice.cgi2
-rw-r--r--httemplate/misc/send-invoice.cgi5
-rwxr-xr-xhttemplate/view/cust_bill.cgi35
-rwxr-xr-xhttemplate/view/cust_statement.html4
-rw-r--r--httemplate/view/elements/cust_bill-typeset7
15 files changed, 540 insertions, 12 deletions
diff --git a/httemplate/browse/invoice_conf.html b/httemplate/browse/invoice_conf.html
new file mode 100644
index 000000000..c8fd1bffb
--- /dev/null
+++ b/httemplate/browse/invoice_conf.html
@@ -0,0 +1,70 @@
+<& elements/browse.html,
+ 'title' => 'Invoice modes',
+ 'name_singular' => 'configuration',
+ 'menubar' => \@menubar,
+ 'query' => {
+ 'select' => $select,
+ 'table' => 'invoice_conf',
+ 'addl_from' => ' JOIN invoice_mode USING (modenum)',
+ 'extra_sql' => ' WHERE '.$curuser->agentnums_sql(
+ 'table' => 'invoice_mode',
+ 'null_right' => ['Edit global templates'],
+ ),
+ 'order_by' => q( ORDER BY modename asc, COALESCE(locale,'') asc),
+ },
+ 'count_query' => 'SELECT COUNT(*) FROM invoice_conf JOIN invoice_mode USING (modenum)',
+ 'header' => [ 'Name', 'Agent', 'Locale', 'Overrides', ],
+ 'fields' => [ $modename,
+ $agent,
+ $locale_label,
+ $overrides,
+ ],
+ 'align' => 'llcl',
+ 'links' => [ '', '', $link ],
+ 'disable_maxselect' => 1,
+&>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+ unless $curuser->access_right([ 'View templates', 'View global templates',
+ 'Edit templates', 'Edit global templates', ]);
+
+my @overrides = grep {$_ ne 'modenum' and $_ ne 'confnum'} FS::invoice_conf->fields;
+my $select = join(',', 'modename', 'agentnum', 'confnum', 'invoice_conf.*');
+
+my @menubar = ();
+if ( $curuser->access_right(['Edit templates', 'Edit global templates']) ) {
+ push @menubar, 'Add a new invoice mode' => $p.'edit/invoice_conf.html';
+}
+
+my $locale_style = 'font-size:0.8em; padding:3px; background-color:';
+
+my $last_modenum = 0;
+my $modename = sub {
+ return '' if $_[0]->modenum == $last_modenum;
+ $_[0]->modename;
+};
+
+my $agent = sub {
+ return '' if $_[0]->modenum == $last_modenum;
+ $last_modenum = $_[0]->modenum;
+ $_[0]->agentnum ? FS::agent->by_key($_[0]->agentnum)->agent : '(global)';
+};
+
+my $locale_label = sub {
+ my $l = $_[0]->locale;
+ $l ? +{ FS::Locales->locale_info($l) }->{'label'} : '(default)';
+};
+
+my $overrides = sub {
+ my $invoice_conf = shift;
+ [ map { [ { data => $_ } ] }
+ grep { length $invoice_conf->get($_) }
+ @overrides
+ ],
+};
+
+my $link = [ $p.'edit/invoice_conf.html?', 'confnum' ];
+</%init>
diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html
index 3270f0443..051788cf7 100644
--- a/httemplate/edit/elements/edit.html
+++ b/httemplate/edit/elements/edit.html
@@ -331,6 +331,7 @@ Example:
% qw( width height config ), #htmlarea
% qw( alt_format ), #select-cust_location
% qw( classnum ), # select-inventory_item
+% qw( aligned ), # columnstart
% ;
%
% #select-table
diff --git a/httemplate/edit/invoice_conf.html b/httemplate/edit/invoice_conf.html
new file mode 100644
index 000000000..b7b3a4ebc
--- /dev/null
+++ b/httemplate/edit/invoice_conf.html
@@ -0,0 +1,296 @@
+<& elements/edit.html,
+ 'body_etc' => $body_etc,
+ 'name_singular' => 'invoice configuration',
+ 'table' => 'invoice_conf',
+ 'viewall_dir' => 'browse',
+ 'fields' => \@fields,
+ 'labels' => \%labels,
+ 'new_callback' => \&new_callback,
+ 'edit_callback' => \&edit_callback,
+ 'error_callback' => \&error_callback,
+ 'html_init' => \&html_init,
+ 'html_table_bottom' => \&html_table_bottom,
+ 'html_bottom' => '</DIV>', # close tablebreak-tabs
+&>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+# ???
+die "access denied"
+ unless $curuser->access_right([ 'Edit templates', 'Edit global templates' ]);
+
+my $body_etc = '';
+$body_etc = q!onload="document.getElementById('locale').onchange()"!
+ if $cgi->param('locale') eq 'new';
+
+my $modenum = $cgi->param('modenum');
+my $mode = $modenum ? qsearchs('invoice_mode', { modenum => $modenum }) : '';
+
+my %textarea = (type => 'textarea', rows => 10, cols => 40);
+my @fields = (
+ { field => 'modenum', type => 'hidden' },
+ { field => 'agentnum',
+ type => 'select-agent',
+ },
+ { field => 'modename', size=>60, },
+ { type => 'tablebreak-tabs',
+ include_opt_callback => \&menubar_opt_callback,
+ },
+ { field => 'locale', type => 'hidden' },
+ { field => 'notice_name', size=>60, },
+ { field => 'subject', size=>60, },
+ { field => 'lpr', size=>60, },
+
+ { type => 'columnstart', aligned => 1 },
+ { type => 'title', value => '<BR>' },
+ map ( { +{ type => 'justtitle', value => $_ } }
+ 'Notes',
+ 'Footer',
+ 'Summary header',
+ 'Return address',
+ 'Coupon',
+ 'Small footer',
+ 'Top margin',
+ 'Header separation',
+ 'Address separation',
+ 'Text height',
+ 'Coupon height',
+ 'Footer separation',
+ ),
+
+ { type => 'columnnext' },
+ { type => 'title', value => 'LaTeX' },
+ { field => 'latexnotes', %textarea },
+ { field => 'latexfooter', %textarea },
+ { field => 'latexsummary', %textarea },
+ { field => 'latexreturnaddress', %textarea },
+ { field => 'latexcoupon', %textarea },
+ { field => 'latexsmallfooter', %textarea },
+ { field => 'latextopmargin', size => 16 },
+ { field => 'latexheadsep', size => 16 },
+ { field => 'latexaddresssep', size => 16 },
+ { field => 'latextextheight', size => 16 },
+ { field => 'latexextracouponspace', size => 16 },
+ { field => 'latexcouponfootsep', size => 16 },
+ # are these still used?
+ #{ field => 'latexcouponamountenclosedsep', size => 16 },
+ #{ field => 'latexverticalreturnaddress', type => 'checkbox' },
+ #{ field => 'latexcouponaddcompanytoaddress',type => 'checkbox' },
+ # logo -- implement if someone really needs it...
+
+ { type => 'columnnext' },
+ { type => 'title', value => 'HTML' },
+ { field => 'htmlnotes', %textarea }, #htmlarea?
+ { field => 'htmlfooter', %textarea },
+ { field => 'htmlsummary', %textarea },
+ { field => 'htmlreturnaddress', %textarea },
+ # logo
+
+ { type => 'columnend' },
+);
+
+my %labels = (
+ 'confnum' => 'Configuration',
+ 'locale' => 'Locale',
+ 'agentnum' => 'Agent',
+ 'modename' => 'Mode name',
+ 'notice_name' => 'Notice name',
+ 'subject' => 'Email Subject: header',
+ 'lpr' => 'Alternate lpr command',
+
+ map { $_ => '' } (qw(
+ latexnotes
+ latexfooter
+ latexsummary
+ latexreturnaddress
+ latexcoupon
+ latexsmallfooter
+ latextopmargin
+ latexheadsep
+ latexaddresssep
+ latextextheight
+ latexextracouponspace
+ latexcouponfootsep
+ htmlnotes
+ htmlfooter
+ htmlsummary
+ htmlreturnaddress
+ logo_png
+ logo_eps
+ ) ),
+
+);
+
+sub get_invoice_mode { # because we can't quite use agent_virt here
+ my $modenum = shift;
+ qsearchs({
+ 'table' => 'invoice_mode',
+ 'hashref' => { 'modenum' => $modenum },
+ 'extra_sql' => ' AND '.
+ $FS::CurrentUser::CurrentUser->agentnums_sql(
+ 'null_right' => 'Edit global templates',
+ 'viewall_right' => 'Edit global templates' ),
+ });
+};
+
+sub error_callback {
+ my ($cgi, $object) = @_;
+ foreach (qw(modename agentnum)) {
+ $object->set($_, $cgi->param($_));
+ }
+ if ($object->confnum) {
+ return edit_callback(@_);
+ } else {
+ return new_callback(@_);
+ }
+}
+
+sub new_callback {
+ my ($cgi, $object, $fields_arrayref, $opt_hashref) = @_;
+ my $modenum;
+ if ( $cgi->param('locale') =~ /^(\w+)$/ ) {
+ $object->set('locale' => $1);
+ }
+
+ if ( $cgi->param('modenum') =~ /^(\d+)$/ ) {
+ $modenum = $1; # we're adding a locale to an existing mode
+ $object->set('modenum' => $modenum);
+ my $invoice_mode = get_invoice_mode($modenum)
+ or die "invoice mode $modenum not found";
+
+ $object->set('modename', $invoice_mode->modename);
+ $object->set('agentnum', $invoice_mode->agentnum);
+
+ # also, need to select a locale
+ # make a list of available locales
+ my %existing_locales = map { $_->locale }
+ qsearch('invoice_conf', { modenum => $modenum });
+
+ my @locales = grep { !exists($existing_locales{$_}) }
+ FS::Conf->new->config('available-locales');
+ my %labels;
+ foreach (@locales) {
+ my %info = FS::Locales->locale_info($_);
+ $labels{$_} = $info{'label'};
+ }
+ unshift @locales, 'new';
+ $labels{'new'} = 'Select language';
+
+ # insert a field def
+ my $i = 0;
+ $i++ until ( $fields_arrayref->[$i]->{'field'} eq 'locale' );
+ my $locale_field = $fields_arrayref->[$i];
+
+ my $onchange_locale = "document.getElementById('submit').disabled =
+ (this.options[this.selectedIndex].value == 'new');";
+
+ %$locale_field = (
+ field => 'locale',
+ type => 'select',
+ options => \@locales,
+ labels => \%labels,
+ curr_value => 'new',
+ onchange => $onchange_locale,
+ );
+
+ } # otherwise it's a completely new mode, so the locale is default
+
+}
+
+sub edit_callback {
+ # massive false laziness with msg_template UI
+ my ($cgi, $object, $fields_arrayref, $opt_hashref) = @_;
+
+ # a little different here in that we treat the content object
+ # as "primary" (this is edit/invoice_conf.html, etc.)
+ # so all we need from the invoice_mode is its name
+ # (and agent identity)
+ my $modenum = $object->modenum;
+ my $invoice_mode = get_invoice_mode($modenum)
+ or die "invoice mode $modenum not found";
+ $object->set('modename', $invoice_mode->modename);
+ $object->set('agentnum', $invoice_mode->agentnum);
+
+}
+
+sub menubar_opt_callback {
+ my $object = shift;
+ my $modenum = $object->modenum or return;
+ my (@tabs, @options, %labels);
+ my $display_new = 0;
+ my $selected = '';
+ foreach my $l ('', FS::Conf->new->config('available-locales')) {
+ my $invoice_conf =
+ qsearchs('invoice_conf', { modenum => $modenum, locale => $l });
+ if ( $invoice_conf ) {
+ my %info = FS::Locales->locale_info($l) if $l;
+ my $label = $info{'label'} || mt('Default');
+ push @tabs, $label, $invoice_conf->confnum;
+ $selected = $label if $object->locale eq $l;
+ }
+ else {
+ $display_new = 1; # there is at least one unused locale left
+ }
+ }
+ push @tabs, mt('New'), "modenum=$modenum;locale=new" if $display_new;
+ $selected = mt('New') if $object->locale eq 'new';
+ $selected ||= mt('Default');
+ (
+ 'url_base' => $cgi->url() . '?',
+ 'selected' => $selected,
+ 'tabs' => \@tabs
+ );
+}
+
+sub html_init {
+q!
+<STYLE>
+.fstabcontainer th { vertical-align: middle; text-align: center }
+</STYLE>
+!
+}
+
+sub html_table_bottom {
+ my $object = shift;
+ my $locale = '';
+ my $modenum = '';
+
+ if ($object->locale =~ /^(\w+)$/) {
+ $locale = $1;
+ }
+ if ($object->modenum =~ /^(\d+)$/) {
+ $modenum = $1;
+ }
+ my $html;
+ my $show_delete = 1;
+ # don't allow the default locale to be removed unless it's the last one
+ # in the mode
+ $show_delete = 0 if (
+ $locale eq 'new' or
+ $modenum eq '' or
+ ($locale eq '' and
+ FS::invoice_conf->count("modenum = $modenum and locale is not null") > 0
+ )
+ );
+
+ if ( $show_delete ) {
+ # set up a delete link
+ my $confnum = $object->confnum;
+ my $url = $p."misc/delete-invoice_conf.html?$confnum";
+ my $link = qq!<A HREF="javascript:areyousure('$url','Really delete this configuration?')">! .
+ 'Delete this configuration' .
+ '</A>';
+ $html = qq!<TR><TD></TD>
+ <TD STYLE="font-style: italic; font-size: small">$link</TD></TR>
+ <SCRIPT TYPE="text/javascript">
+ function areyousure(url, message) {
+ if (confirm(message)) window.location.href = url;
+ }
+ </SCRIPT>
+ !;
+ }
+ $html;
+}
+
+</%init>
diff --git a/httemplate/edit/process/invoice_conf.html b/httemplate/edit/process/invoice_conf.html
new file mode 100644
index 000000000..1d45e126f
--- /dev/null
+++ b/httemplate/edit/process/invoice_conf.html
@@ -0,0 +1,21 @@
+<& elements/process.html,
+ 'table' => 'invoice_conf',
+ 'viewall_dir' => 'browse',
+ 'fields' => [ FS::invoice_conf->fields, 'modename', 'agentnum' ],
+ 'precheck_callback' => \&precheck_callback,
+&>
+<%init>
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right(['Edit templates','Edit global templates']);
+
+sub precheck_callback {
+ my $cgi = shift;
+ $cgi->param('locale') =~ /^(\w*)$/;
+ my $locale = $1;
+ return mt('Language required') if $locale eq 'new'; # the user didn't choose
+ die "unknown locale $locale" if ( $locale and
+ !FS::Locales->locale_info($locale) );
+}
+# invoice_conf itself knows to create/update invoice_mode if necessary,
+# so nothing special here
+</%init>
diff --git a/httemplate/elements/columnstart.html b/httemplate/elements/columnstart.html
index be37d817d..1ffbcb9e8 100644
--- a/httemplate/elements/columnstart.html
+++ b/httemplate/elements/columnstart.html
@@ -1,6 +1,81 @@
+<%doc>
+<table>
+ <& /elements/columnstart.html &>
+ <tr> ... </tr>
+ <tr> ... </tr>
+ <& /elements/columnnext.html &>
+ ...
+ <& /elements/columnend.html &>
+</table>
+
+Pass 'aligned' => 1 to have corresponding rows in the columns line up.
+</%doc>
+% my $id = sprintf('table%08d', rand(100000000));
<TR>
<TD CLASS="background" COLSPAN=99>
- <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
+ <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 id="<%$id%>">
<TR>
<TD VALIGN="top">
<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
+% if ( $aligned ) {
+%# Instead of changing all the tr-* elements to sometimes output table
+%# cells without wrapping them in a row, we're just going to completely
+%# rebuild the table on the client side.
+<script type="text/javascript">
+<&| onload.js &>
+ var table = document.getElementById('<%$id%>'); // has one row, always
+ var rows = []; // row contents, each containing
+ var n_rows = []; // rows in each subtable
+ var n_cols = []; // cols in each subtable
+ var total_rows = 0; // max(n_rows)
+ for(var i=0; i < table.rows[0].cells.length; i++) {
+ // these are cells created by columnstart/columnnext
+ // each contains a table, and nothing else
+ var subtable = table.rows[0].cells[i].children[0];
+ n_rows[i] = subtable.rows.length;
+ if ( total_rows < n_rows[i] ) {
+ total_rows = n_rows[i];
+ }
+ n_cols[i] = 0;
+ var subrows = []; // the rows of this table
+ for(var j=0; j < n_rows[i]; j++) {
+ // these are the actual tr-* rows within the table, and
+ // can contain multiple cells
+ subrows[j] = [];
+ var tr = subtable.rows[j];
+ if ( n_cols[i] < tr.cells.length ) {
+ n_cols[i] = tr.cells.length;
+ }
+ for(var k=0; k < tr.cells.length; k++) {
+ subrows[j][k] = tr.cells[k];
+ }
+ } // for(j)
+ rows[i] = subrows;
+ } // for(i)
+ var new_table = document.createElement('TABLE');
+ for (var j = 0; j < total_rows; j++) {
+ var tr = document.createElement('TR');
+ for (var i = 0; i < rows.length; i++) { // subtables
+ var k = 0; // subrow position
+ if ( j < n_rows[i] ) { // then subtable i has this row
+ for (k = 0; k < rows[i][j].length; k++) { // cells
+ tr.appendChild(rows[i][j][k]);
+ }
+ } // else k is just 0
+ if ( k < n_cols[i] ) { // then we need a spacer
+ var spacer = document.createElement('TD');
+ spacer.setAttribute('colspan', n_cols[i] - k);
+ tr.appendChild(spacer);
+ }
+ } // for(i); subtables
+ // tr is complete
+ new_table.appendChild(tr);
+ } // for(j); rows
+ table.parentNode.insertBefore( new_table, table );
+ table.parentNode.removeChild(table);
+</&>
+</script>
+% } # if $aligned
+<%args>
+$aligned => 0
+</%args>
diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html
index 8cbbd1742..edb5e8159 100644
--- a/httemplate/elements/menu.html
+++ b/httemplate/elements/menu.html
@@ -600,6 +600,7 @@ $config_billing{'Billing events'} = [ $fsurl.'browse/part_event.html', 'Billing
|| $curuser->access_right('Edit global billing events');
if ( $curuser->access_right('Configuration') ) {
#$config_billing{'Invoice events'} = [ $fsurl.'browse/part_bill_event.cgi', 'Deprecated, old-style actions for overdue invoices' ];
+ $config_billing{'Invoice configurations'} = [ $fsurl.'browse/invoice_conf.html', 'Adjust invoice settings for special-purpose notices' ];
$config_billing{'Invoice templates'} = [ $fsurl.'browse/invoice_template.html', 'Edit templates for HTML, plaintext and typeset invoices' ];
$config_billing{'separator'} = ''; #its a separator!
$config_billing{'Prepaid cards'} = [ $fsurl.'search/prepay_credit.html', 'View outstanding cards, generate new cards' ];
diff --git a/httemplate/elements/tr-select-invoice_mode.html b/httemplate/elements/tr-select-invoice_mode.html
new file mode 100644
index 000000000..3dccdccc2
--- /dev/null
+++ b/httemplate/elements/tr-select-invoice_mode.html
@@ -0,0 +1,10 @@
+<& tr-select-table.html,
+ 'label' => 'Invoice mode',
+ 'table' => 'invoice_mode',
+ 'field' => 'modenum',
+ 'name_col' => 'modename',
+ 'agent_virt' => 1,
+ 'agent_null' => 1,
+ 'empty_label' => '(none)',
+ @_
+&>
diff --git a/httemplate/misc/delete-invoice_conf.html b/httemplate/misc/delete-invoice_conf.html
new file mode 100644
index 000000000..6cc6ddc95
--- /dev/null
+++ b/httemplate/misc/delete-invoice_conf.html
@@ -0,0 +1,19 @@
+<%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
+die "access denied"
+ unless $curuser->access_right(['Edit templates', 'Edit global templates']);
+
+my ($query) = $cgi->keywords;
+$query =~ /^(\d+)$/ or die "bad confnum";
+my $invoice_conf = FS::invoice_conf->by_key($1)
+ or die "couldn't find invoice_conf #$1";
+if ( !$curuser->access_right('Edit global templates') ) {
+ my $agentnum = FS::invoice_mode->by_key($invoice_conf->modenum)->agentnum;
+ die "access denied"
+ unless $curuser->agentnums_href->{$agentnum};
+}
+
+my $error = $invoice_conf->delete; # may also delete the invoice_mode
+my $url = $p.'browse/invoice_conf.html';
+</%init>
+<% $cgi->redirect($url) %>
diff --git a/httemplate/misc/email-invoice.cgi b/httemplate/misc/email-invoice.cgi
index 269722f67..b24e0420f 100755
--- a/httemplate/misc/email-invoice.cgi
+++ b/httemplate/misc/email-invoice.cgi
@@ -12,7 +12,7 @@ my $invnum = $3;
my $cust_bill = qsearchs('cust_bill',{'invnum'=>$invnum});
die "Can't find invoice!\n" unless $cust_bill;
-$cust_bill->email($template);
+$cust_bill->email({ 'template' => $template });
my $custnum = $cust_bill->getfield('custnum');
diff --git a/httemplate/misc/fax-invoice.cgi b/httemplate/misc/fax-invoice.cgi
index 2591fceb8..f72fc7eaf 100755
--- a/httemplate/misc/fax-invoice.cgi
+++ b/httemplate/misc/fax-invoice.cgi
@@ -12,7 +12,7 @@ my $invnum = $3;
my $cust_bill = qsearchs('cust_bill',{'invnum'=>$invnum});
die "Can't find invoice!\n" unless $cust_bill;
-$cust_bill->fax_invoice($template);
+$cust_bill->fax_invoice({ 'template' => $template });
my $custnum = $cust_bill->getfield('custnum');
diff --git a/httemplate/misc/print-invoice.cgi b/httemplate/misc/print-invoice.cgi
index aeef68795..5ce6e76df 100755
--- a/httemplate/misc/print-invoice.cgi
+++ b/httemplate/misc/print-invoice.cgi
@@ -12,7 +12,7 @@ my $invnum = $3;
my $cust_bill = qsearchs('cust_bill',{'invnum'=>$invnum});
die "Can't find invoice!\n" unless $cust_bill;
-$cust_bill->print($template);
+$cust_bill->print({ 'template' => $template});
my $custnum = $cust_bill->getfield('custnum');
diff --git a/httemplate/misc/send-invoice.cgi b/httemplate/misc/send-invoice.cgi
index 32dfe276d..08dd0e01c 100644
--- a/httemplate/misc/send-invoice.cgi
+++ b/httemplate/misc/send-invoice.cgi
@@ -13,6 +13,10 @@ my $invnum = $cgi->param('invnum');
my $template = $cgi->param('template');
my $notice_name = $cgi->param('notice_name') if $cgi->param('notice_name');
my $method = $cgi->param('method');
+my $mode;
+if ( $cgi->param('mode') =~ /^(\d+)$/ ) {
+ $mode = $1;
+}
$method .= '_invoice' if $method eq 'fax'; #!
@@ -21,6 +25,7 @@ die "unknown method $method" unless $method{$method};
my $cust_bill = qsearchs('cust_bill',{'invnum'=>$invnum});
die "Can't find invoice!\n" unless $cust_bill;
+$cust_bill->set('mode' => $mode) if $mode;
$cust_bill->$method({ 'template' => $template,
'notice_name' => $notice_name,
});
diff --git a/httemplate/view/cust_bill.cgi b/httemplate/view/cust_bill.cgi
index 95ce60b1d..4822ab718 100755
--- a/httemplate/view/cust_bill.cgi
+++ b/httemplate/view/cust_bill.cgi
@@ -104,12 +104,35 @@
% my $br = 0;
% if ( $cust_bill->num_cust_event ) { $br++;
<A HREF="<%$p%>search/cust_event.html?invnum=<% $cust_bill->invnum %>">( <% mt('View invoice events') |h %> )</A>
-% }
+% }
% if ( $cust_bill->num_cust_bill_event ) { $br++;
<A HREF="<%$p%>search/cust_bill_event.cgi?invnum=<% $cust_bill->invnum %>">( <% mt('View deprecated, old-style invoice events') |h %> )</A>
% }
+% my @modes = grep {! $_->disabled}
+% $cust_bill->cust_main->agent->invoice_modes;
+% if ( @modes ) {
+( <% mt('View as:') %>
+<FORM STYLE="display:inline" ACTION="<% $cgi->url %>" METHOD="GET">
+<INPUT NAME="invnum" VALUE="<% $invnum %>" TYPE="hidden">
+<& /elements/select-table.html,
+ table => 'invoice_mode',
+ field => 'mode',
+ curr_value => scalar($cgi->param('mode')),
+ records => \@modes,
+ name_col => 'modename',
+ onchange => 'change_invoice_mode',
+ empty_label => '(default)',
+&> )
+<SCRIPT TYPE="text/javascript">
+function change_invoice_mode(obj) {
+ obj.form.submit();
+}
+</SCRIPT>
+% $br++;
+% }
+
<% $br ? '<BR><BR>' : '' %>
% if ( $conf->exists('invoice_html') ) {
@@ -126,7 +149,9 @@ my $curuser = $FS::CurrentUser::CurrentUser;
die "access denied"
unless $curuser->access_right('View invoices');
-my( $invnum, $template, $notice_name );
+my $conf = FS::Conf->new;
+
+my( $invnum, $mode, $template, $notice_name );
my($query) = $cgi->keywords;
if ( $query =~ /^((.+)-)?(\d+)$/ ) {
$template = $2;
@@ -136,10 +161,9 @@ if ( $query =~ /^((.+)-)?(\d+)$/ ) {
$invnum = $cgi->param('invnum');
$template = $cgi->param('template');
$notice_name = $cgi->param('notice_name');
+ $mode = $cgi->param('mode');
}
-my $conf = new FS::Conf;
-
my %opt = (
'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
'template' => $template,
@@ -163,10 +187,13 @@ my $cust_bill = qsearchs({
});
die "Invoice #$invnum not found!" unless $cust_bill;
+$cust_bill->set('mode' => $mode);
+
my $custnum = $cust_bill->custnum;
my $display_custnum = $cust_bill->cust_main->display_custnum;
my $link = "invnum=$invnum";
+$link .= ';mode=' . $mode if $mode;
$link .= ';template='. uri_escape($template) if $template;
$link .= ';notice_name='. $notice_name if $notice_name;
diff --git a/httemplate/view/cust_statement.html b/httemplate/view/cust_statement.html
index 3e1345ed5..5d37b3167 100755
--- a/httemplate/view/cust_statement.html
+++ b/httemplate/view/cust_statement.html
@@ -35,10 +35,10 @@
% if ( $conf->exists('invoice_html') ) {
- <% join('', $cust_statement->print_html('', $templatename) ) %>
+ <% join('', $cust_statement->print_html('template' => $templatename) ) %>
% } else {
- <PRE><% join('', $cust_statement->print_text('', $templatename) ) %></PRE>
+ <PRE><% join('', $cust_statement->print_text('template' => $templatename) ) %></PRE>
% }
<% include('/elements/footer.html') %>
diff --git a/httemplate/view/elements/cust_bill-typeset b/httemplate/view/elements/cust_bill-typeset
index 00f503fbb..778e538d1 100644
--- a/httemplate/view/elements/cust_bill-typeset
+++ b/httemplate/view/elements/cust_bill-typeset
@@ -6,7 +6,7 @@ die "access denied"
my $type = shift;
-my( $invnum, $template, $notice_name );
+my( $invnum, $mode, $template, $notice_name );
my($query) = $cgi->keywords;
if ( $query =~ /^((.+)-)?(\d+)(.pdf)?$/ ) { #probably not necessary anymore?
$template = $2;
@@ -16,7 +16,8 @@ if ( $query =~ /^((.+)-)?(\d+)(.pdf)?$/ ) { #probably not necessary anymore?
$invnum = $cgi->param('invnum');
$invnum =~ s/\.pdf//i; #probably not necessary anymore
$template = $cgi->param('template');
- $notice_name = ( $cgi->param('notice_name') || 'Invoice' );
+ $notice_name = $cgi->param('notice_name');
+ $mode = $cgi->param('mode');
}
my $conf = new FS::Conf;
@@ -36,6 +37,8 @@ my $cust_bill = qsearchs({
});
die "Invoice #$invnum not found!" unless $cust_bill;
+$cust_bill->set(mode => $mode);
+
my $method = "print_$type";
my $content = $cust_bill->$method(\%opt);