summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2015-11-18 13:07:47 -0800
committerMark Wells <mark@freeside.biz>2015-11-18 13:07:47 -0800
commitb2fd002f3285b70311642f8ff0025598d42bd16e (patch)
tree8005ab27d04c8aaaa7e9bfd10a9ba0f48cafd967 /httemplate
parent1daa37e733b9e972e5328503374130a423d02836 (diff)
track customer invoice destination emails using contact_email, #25536
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/REST/1.0/cust_main18
-rwxr-xr-xhttemplate/edit/cust_main.cgi3
-rw-r--r--httemplate/edit/cust_main/basics.html4
-rw-r--r--httemplate/edit/cust_main/billing.html81
-rw-r--r--httemplate/edit/cust_main/name.html13
-rw-r--r--httemplate/edit/process/cust_main-contacts.html20
-rwxr-xr-xhttemplate/edit/process/cust_main.cgi51
-rw-r--r--httemplate/elements/contact.html14
-rw-r--r--httemplate/elements/tr-checkbox.html23
-rw-r--r--httemplate/elements/tr-td-label.html3
-rw-r--r--httemplate/misc/xmlhttp-cust_main-email_search.html8
-rw-r--r--httemplate/view/cust_main/contacts_new.html10
12 files changed, 168 insertions, 80 deletions
diff --git a/httemplate/REST/1.0/cust_main b/httemplate/REST/1.0/cust_main
index 4656bcb25..5401195fc 100644
--- a/httemplate/REST/1.0/cust_main
+++ b/httemplate/REST/1.0/cust_main
@@ -47,17 +47,23 @@ if ( $r->method eq 'GET' ) {
if ( $cgi->param('cust_main_invoice_dest') ) {
my $dest = dbh->quote(scalar($cgi->param('cust_main_invoice_dest')));
$extra_sql = "
- WHERE EXISTS ( SELECT 1 FROM cust_main_invoice
- WHERE cust_main.custnum = cust_main_invoice.custnum
- AND dest = $dest
+ WHERE EXISTS ( SELECT 1 FROM cust_contact
+ JOIN contact USING (contactnum)
+ JOIN contact_email USING (contactnum)
+ WHERE cust_main.custnum = cust_contact.custnum
+ AND contact.invoice_dest = 'Y'
+ AND contact_email.emailaddress = $dest
)
";
} elsif ( $cgi->param('cust_main_invoice_dest_substring') ) {
my $dest = dbh->quote('%'. scalar($cgi->param('cust_main_invoice_dest_substring')). '%');
$extra_sql = "
- WHERE EXISTS ( SELECT 1 FROM cust_main_invoice
- WHERE cust_main.custnum = cust_main_invoice.custnum
- AND dest ILIKE $dest
+ WHERE EXISTS ( SELECT 1 FROM cust_contact
+ JOIN contact USING (contactnum)
+ JOIN contact_email USING (contactnum)
+ WHERE cust_main.custnum = cust_contact.custnum
+ AND contact.invoice_dest = 'Y'
+ AND contact_email.emailaddress ILIKE $dest
)
";
}
diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi
index effe84b96..bdf3431d7 100755
--- a/httemplate/edit/cust_main.cgi
+++ b/httemplate/edit/cust_main.cgi
@@ -294,8 +294,7 @@ if ( $cgi->param('error') ) {
$cust_main->agentnum( $conf->config('default_agentnum') )
if $conf->exists('default_agentnum');
$cust_main->referral_custnum( $cgi->param('referral_custnum') );
- @invoicing_list = ();
- push @invoicing_list, 'POST'
+ $cust_main->set('postal_invoice', 'Y')
unless $conf->exists('disablepostalinvoicedefault');
$ss = '';
$stateid = '';
diff --git a/httemplate/edit/cust_main/basics.html b/httemplate/edit/cust_main/basics.html
index 32a03bbe6..c3768ac42 100644
--- a/httemplate/edit/cust_main/basics.html
+++ b/httemplate/edit/cust_main/basics.html
@@ -31,6 +31,8 @@
$('#spouse_label').slideUp();
$('#spouse_last_input').slideUp();
$('#spouse_first_input').slideUp();
+ $('#invoice_email_label').slideUp();
+ $('#invoice_email_input').slideUp();
} else {
if ( document.getElementById('company').value.length == 0 ) {
$('#company_label').slideUp();
@@ -40,6 +42,8 @@
$('#spouse_label').slideDown();
$('#spouse_last_input').slideDown();
$('#spouse_first_input').slideDown();
+ $('#invoice_email_label').slideDown();
+ $('#invoice_email_input').slideDown();
}
}
diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html
index 6f716c1be..7bca17b50 100644
--- a/httemplate/edit/cust_main/billing.html
+++ b/httemplate/edit/cust_main/billing.html
@@ -25,9 +25,13 @@
% if ( $curuser->access_right('Complimentary customer') ) {
- <TR>
- <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="complimentary" VALUE="Y" <% $cust_main->complimentary eq "Y" ? 'CHECKED' : '' %>>Complimentary customer
- </TR>
+ <& /elements/tr-checkbox.html,
+ field => 'complimentary',
+ label => emt('Complimentary customer'),
+ value => 'Y',
+ curr_value => $cust_main->complimentary,
+ box_first => 1,
+ &>
% } else {
@@ -51,9 +55,13 @@
% } else {
- <TR>
- <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="tax" VALUE="Y" <% $cust_main->tax eq "Y" ? 'CHECKED' : '' %>> Tax Exempt<% @exempt_groups ? ' (all taxes)' : '' %></TD>
- </TR>
+ <& /elements/tr-checkbox.html,
+ field => 'tax',
+ label => emt('Tax Exempt' . (scalar(@exempt_groups) ? '(all taxes)' : '') ),
+ value => 'Y',
+ curr_value => $cust_main->tax,
+ box_first => 1,
+ &>
% }
@@ -66,7 +74,7 @@
<TD STYLE="white-space:nowrap">&nbsp;&nbsp;<INPUT TYPE="checkbox" NAME="tax_<% $exempt_group %>" ID="tax_<% $exempt_group %>" VALUE="Y" <% $checked ? 'CHECKED' : '' %> onChange="tax_changed(this)"> Tax Exempt (<% $exempt_group %> taxes)</TD>
<TD> - Exemption number <INPUT TYPE="text" NAME="tax_<% $exempt_group %>_num" ID="tax_<% $exempt_group %>_num" VALUE="<% $cgi->param("tax_$exempt_group".'_num') || ( $cust_main_exemption ? $cust_main_exemption->exempt_number : '' ) |h %>" <% $checked ? '' : 'DISABLED' %>></TD>
</TR>
-% }
+% } #"
% }
% ###
@@ -75,18 +83,13 @@
% unless ( $conf->exists('emailinvoiceonly') ) {
- <TR>
- <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="invoicing_list_POST" VALUE="POST" <%
-
- ( grep { $_ eq 'POST' } @invoicing_list )
-
- ? 'CHECKED'
- : ''
-
- %>> <% mt('Postal mail invoices') |h %>
-
- </TD>
- </TR>
+ <& /elements/tr-checkbox.html,
+ field => 'postal_invoice',
+ label => emt('Postal mail invoices'),
+ value => 'Y',
+ curr_value => $cust_main->postal_invoice,
+ box_first => 1,
+ &>
% }
@@ -94,33 +97,21 @@
% # email invoices
% ###
- <TR>
- <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="invoice_email" VALUE="Y" <%
-
- ( $cust_main->invoice_noemail eq 'Y' )
- ? ''
- : 'CHECKED'
-
- %>> <% mt('Email invoices') |h %>
-
- </TD>
- </TR>
+ <& /elements/tr-checkbox.html,
+ field => 'invoice_noemail',
+ label => emt('Do not send email invoices'),
+ value => 'Y',
+ curr_value => $cust_main->invoice_noemail,
+ box_first => 1,
+ &>
-% unless ( $conf->exists('cust-email-high-visibility')) {
- <TR>
- <TH ALIGN="right" WIDTH="200">
- <% $conf->exists('cust_main-require_invoicing_list_email', $agentnum)
- ? $r : '' %>Email address(es)
- </TD>
- <TD WIDTH="408"><INPUT TYPE="text" NAME="invoicing_list" VALUE="<% join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ) %>">
- <INPUT TYPE="checkbox" NAME="message_noemail" VALUE="Y" <%
- ( $cust_main->message_noemail eq 'Y' )
- ? 'CHECKED'
- : ''
- %>> <FONT SIZE="-1"><% emt('Do not send notices') %></FONT>
- </TD>
- </TR>
-% }
+ <& /elements/tr-checkbox.html,
+ field => 'message_noemail',
+ label => emt('Do not send other email notices'),
+ value => 'Y',
+ curr_value => $cust_main->message_noemail,
+ box_first => 1,
+ &>
% ###
% # prorate_day
diff --git a/httemplate/edit/cust_main/name.html b/httemplate/edit/cust_main/name.html
index 13bd09764..12d9d7405 100644
--- a/httemplate/edit/cust_main/name.html
+++ b/httemplate/edit/cust_main/name.html
@@ -29,19 +29,18 @@
</TR>
% }
-% if ( $conf->exists('cust-email-high-visibility') ) {
<TR>
- <TH ALIGN="right" CLASS="
+ <TH ALIGN="right">
+ <SPAN ID="invoice_email_label" CLASS="
<% $conf->exists('cust_main-require_invoicing_list_email', $agentnum)
? 'required label'
- : 'label' %>">Email address(es)
- </TD>
- <TD BGCOLOR="#FFFF00">
- <INPUT TYPE="text" NAME="invoicing_list"
+ : 'label' %>">Email address(es)</SPAN>
+ </TH>
+ <TD>
+ <INPUT TYPE="text" NAME="invoice_email" ID="invoice_email_input"
VALUE="<% $cust_main->invoicing_list_emailonly_scalar %>">
</TD>
</TR>
-% }
<%init>
my $cust_main = shift;
my $agentnum = $cust_main->agentnum if $cust_main->custnum;
diff --git a/httemplate/edit/process/cust_main-contacts.html b/httemplate/edit/process/cust_main-contacts.html
index 10ec3638f..2a7185b5c 100644
--- a/httemplate/edit/process/cust_main-contacts.html
+++ b/httemplate/edit/process/cust_main-contacts.html
@@ -3,6 +3,7 @@
'error_redirect' => popurl(3). 'edit/cust_main-contacts.html?',
'agent_virt' => 1,
'skip_process' => 1, #we don't want to make any changes to cust_main
+ 'precheck_callback' => $precheck_callback,
'process_o2m' => {
'table' => 'contact',
'fields' => FS::contact->cgi_contact_fields,
@@ -10,3 +11,22 @@
'redirect' => popurl(3). 'view/cust_main.cgi?',
)
%>
+<%init>
+my $precheck_callback = sub {
+ my $cgi = shift;
+ my $conf = FS::Conf->new;
+ if ( $conf->exists('cust_main-require_invoicing_list_email') ) {
+ my $has_email = 0;
+ foreach my $prefix (grep /^contactnum\d+$/, $cgi->param) {
+ if ( length($cgi->param($prefix . '_emailaddress'))
+ and $cgi->param($prefix . '_invoice_dest') ) {
+ $has_email = 1;
+ last;
+ }
+ }
+ return "At least one contact must receive email invoices"
+ unless $has_email;
+ }
+ '';
+};
+</%init>
diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi
index 52a2608fd..a9f7cf4ac 100755
--- a/httemplate/edit/process/cust_main.cgi
+++ b/httemplate/edit/process/cust_main.cgi
@@ -29,10 +29,12 @@ $cgi->param('tax','') unless defined $cgi->param('tax');
$cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] );
-my @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
-push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
-push @invoicing_list, 'FAX' if $cgi->param('invoicing_list_FAX');
-$cgi->param('invoicing_list', join(',', @invoicing_list) );
+#my @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
+#push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
+#push @invoicing_list, 'FAX' if $cgi->param('invoicing_list_FAX');
+#$cgi->param('invoicing_list', join(',', @invoicing_list) );
+
+my $agentnum = $cgi->param('agentnum');
# is this actually used? if so, we need to clone locations...
# but I can't find anything that sets this parameter to a non-empty value
@@ -78,7 +80,7 @@ my $new = new FS::cust_main ( {
map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
} );
-$new->invoice_noemail( ($cgi->param('invoice_email') eq 'Y') ? '' : 'Y' );
+warn Dumper( $new ) if $DEBUG > 1;
if ( $duplicate_of ) {
# then negate all changes to the customer; the only change we should
@@ -157,6 +159,36 @@ if ( $curuser->access_right('Edit customer tax exemptions') ) {
$options{'contact_params'} = scalar($cgi->Vars);
$options{'cust_payby_params'} = scalar($cgi->Vars);
+my $email;
+
+if ( $cgi->param('residential_commercial') eq 'Residential' ) {
+
+ $email = $cgi->param('invoice_email') || '';
+ if ( length($email) == 0 and $conf->exists('cust_main-require_invoicing_list_email', $agentnum) ) {
+ $error = 'Email address required';
+ }
+
+ # XXX really should include the phone numbers in here also
+
+} else {
+
+ # contact UI is enabled; everything will be passed through via
+ # contact_params
+ if ($conf->exists('cust_main-require_invoicing_list_email', $agentnum)) {
+ my $has_email = 0;
+ foreach my $prefix (grep /^contactnum\d+$/, $cgi->param) {
+ if ( length($cgi->param($prefix . '_emailaddress'))
+ and $cgi->param($prefix . '_invoice_dest') ) {
+ $has_email = 1;
+ last;
+ }
+ }
+ $error = "At least one contact must receive email invoices"
+ unless $has_email;
+ }
+
+}
+
#perhaps this stuff should go to cust_main.pm
if ( $new->custnum eq '' or $duplicate_of ) {
@@ -263,7 +295,8 @@ if ( $new->custnum eq '' or $duplicate_of ) {
}
else {
# create the customer
- $error ||= $new->insert( \%hash, \@invoicing_list,
+ $error ||= $new->insert( \%hash,
+ [ $email ],
%options,
prospectnum => scalar($cgi->param('prospectnum')),
);
@@ -296,16 +329,14 @@ if ( $new->custnum eq '' or $duplicate_of ) {
$new->signupdate($old->signupdate);
}
- warn "$me calling $new -> replace( $old, \ @invoicing_list )" if $DEBUG;
+ warn "$me calling $new -> replace( $old )" if $DEBUG;
local($FS::cust_main::DEBUG) = $DEBUG if $DEBUG;
local($FS::Record::DEBUG) = $DEBUG if $DEBUG;
local($Data::Dumper::Sortkeys) = 1;
warn Dumper({ new => $new, old => $old }) if $DEBUG;
- $error ||= $new->replace( $old, \@invoicing_list,
- %options,
- );
+ $error ||= $new->replace( $old, [ $email ], %options );
warn "$me returned from replace" if $DEBUG;
diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html
index 87e15debe..ab14dfbe8 100644
--- a/httemplate/elements/contact.html
+++ b/httemplate/elements/contact.html
@@ -59,13 +59,22 @@
% }
% }
</SELECT>
-
+% } elsif ( $field eq 'invoice_dest' ) {
+% my $curr_value = $cgi->param($name . '_' . $field);
+% $curr_value = $value if !defined($curr_value);
+ <& select.html,
+ field => $name . '_' . $field,
+ curr_value => $curr_value,
+ options => [ '', 'Y' ],
+ option_labels => { '' => 'no', 'Y' => 'yes' },
+ style => 'width: 100%',
+ &>
% } else {
<INPUT TYPE = "text"
NAME = "<%$name%>_<%$field%>"
ID = "<%$id%>_<%$field%>"
SIZE = "<% $size{$field} || 14 %>"
- VALUE = "<% scalar($cgi->param($name."_$field"))
+ VALUE = "<% scalar($cgi->param($name . '_' . $field))
|| $value |h %>"
<% $onchange %>
>
@@ -130,6 +139,7 @@ tie my %label, 'Tie::IxHash',
'last' => 'Last name',
'title' => 'Title/Position',
'emailaddress' => 'Email',
+ 'invoice_dest' => 'Send invoices',
'selfservice_access' => 'Self-service'
;
diff --git a/httemplate/elements/tr-checkbox.html b/httemplate/elements/tr-checkbox.html
index 5761263cf..ed166502b 100644
--- a/httemplate/elements/tr-checkbox.html
+++ b/httemplate/elements/tr-checkbox.html
@@ -9,13 +9,26 @@ Example:
&>
</%doc>
-<% include('tr-td-label.html', @_ ) %>
+% if ( $opt{'box_first'} ) {
+ <TR>
+ <TH COLSPAN="<% $opt{'colspan'} || 2 %>"
+ VALIGN = "<% $opt{'valign'} || 'top' %>"
+ STYLE = "<% $style %>"
+ ID = "<% $opt{label_id} || $opt{id}. '_label0' %>"
+ >
+ <& checkbox.html, @_ &>
+ <% $required %><% $opt{label} %>
+ </TH>
+ </TR>
+% } else {
+<& tr-td-label.html, @_ &>
<TD <% $style %>>
<% include('checkbox.html', @_) %>
</TD>
</TR>
+% }
<%init>
@@ -25,6 +38,12 @@ my $onchange = $opt{'onchange'}
? 'onChange="'. $opt{'onchange'}. '(this)"'
: '';
-my $style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
+my $style = 'text-align: left; padding-top: 3px';
+$style .= '; '. $opt{'cell_style'} if $opt{'cell_style'};
+
+my $required = $opt{'required'} ? '<font color="#ff0000">*</font>&nbsp;' : '';
+if ($required) {
+ $style .= ';font-weight: bold';
+}
</%init>
diff --git a/httemplate/elements/tr-td-label.html b/httemplate/elements/tr-td-label.html
index f7067221b..3111f435c 100644
--- a/httemplate/elements/tr-td-label.html
+++ b/httemplate/elements/tr-td-label.html
@@ -2,6 +2,9 @@
Actually <TR> <TH> $label </TH>
+Note that this puts the 'label' argument into the document verbatim, with no
+escaping or localization.
+
</%doc>
<TR>
diff --git a/httemplate/misc/xmlhttp-cust_main-email_search.html b/httemplate/misc/xmlhttp-cust_main-email_search.html
index 0d830826c..eb9ecc8f6 100644
--- a/httemplate/misc/xmlhttp-cust_main-email_search.html
+++ b/httemplate/misc/xmlhttp-cust_main-email_search.html
@@ -6,14 +6,14 @@ die 'access denied'
my $sub = $cgi->param('sub');
my $email = $cgi->param('arg');
my @where = (
- "cust_main_invoice.dest != 'POST'",
- "cust_main_invoice.dest LIKE ".dbh->quote('%'.$email.'%'),
+ 'contact_email.emailaddress LIKE '.dbh->quote('%'.$email.'%'),
$FS::CurrentUser::CurrentUser->agentnums_sql(table => 'cust_main'),
);
my @cust_main = qsearch({
'table' => 'cust_main',
- 'select' => 'cust_main.*, cust_main_invoice.dest',
- 'addl_from' => 'JOIN cust_main_invoice USING (custnum)',
+ 'select' => 'cust_main.*',
+ 'addl_from' => ' JOIN cust_contact USING (custnum) '.
+ ' JOIN contact_email USING (contactnum)',
'extra_sql' => 'WHERE '.join(' AND ', @where),
});
diff --git a/httemplate/view/cust_main/contacts_new.html b/httemplate/view/cust_main/contacts_new.html
index 590409df9..d55ee3dc3 100644
--- a/httemplate/view/cust_main/contacts_new.html
+++ b/httemplate/view/cust_main/contacts_new.html
@@ -1,4 +1,4 @@
-%if ( @cust_contacts ) {
+% if ( $display and @cust_contacts ) {
<BR>
<FONT CLASS="fsinnerbox-title">Contacts</FONT>
@@ -9,6 +9,7 @@
<%$th%>Type</TH>
<%$th%>Contact</TH>
<%$th%>Email</TH>
+ <%$th%>Send invoices</TH>
<%$th%>Self-service</TH>
% foreach my $phone_type (@phone_type) {
<%$th%><% $phone_type->typename |h %></TH>
@@ -30,7 +31,7 @@
% my @contact_email = $contact->contact_email;
<%$td%><% join(', ', map $_->emailaddress, @contact_email) %></TD>
-
+ <%$td%><% $contact->invoice_dest eq 'Y' ? 'Yes' : 'No' %></TD>
<%$td%>
% if ( $cust_contact->selfservice_access ) {
Enabled
@@ -75,4 +76,9 @@ my( $cust_main ) = @_;
my @cust_contacts = $cust_main->cust_contact;
+# residential customers have a default "invisible" contact, but if they
+# somehow get more than one contact, show them
+my $display = (length($cust_main->residential_commercial) > 0)
+ or ( scalar(@cust_contacts) > 1 );
+
</%init>