diff options
author | Ivan Kohler <ivan@freeside.biz> | 2015-02-03 07:14:45 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2015-02-03 07:14:45 -0800 |
commit | 167dbdad01e2c1b62fd9be43cc05212e8c874a02 (patch) | |
tree | 0d49c9ba03d64560f21b02a20d32d6005a790ced /httemplate | |
parent | 475ae93877f1d834941f7b9adcc35ee84c5c22fa (diff) |
contacts can be shared among customers / "duplicate contact emails", RT#27943
Diffstat (limited to 'httemplate')
-rwxr-xr-x | httemplate/edit/cust_main.cgi | 4 | ||||
-rw-r--r-- | httemplate/edit/elements/edit.html | 4 | ||||
-rw-r--r-- | httemplate/elements/contact.html | 19 | ||||
-rw-r--r-- | httemplate/elements/tr-select-contact.html | 10 | ||||
-rw-r--r-- | httemplate/misc/email-quotation.html | 8 | ||||
-rw-r--r-- | httemplate/search/contact.html | 60 | ||||
-rw-r--r-- | httemplate/search/prospect_main.html | 4 | ||||
-rw-r--r-- | httemplate/view/cust_main/contacts_new.html | 33 | ||||
-rw-r--r-- | httemplate/view/prospect_main.html | 5 |
9 files changed, 103 insertions, 44 deletions
diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index 353ae1799..da87bfca7 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -325,8 +325,8 @@ if ( $cgi->param('error') ) { $cust_main->company( $prospect_main->company ); #first contact? -> name - my @contacts = $prospect_main->contact; - my $contact = $contacts[0]; + my @prospect_contacts = $prospect_main->prospect_contact; + my $contact = $prospect_contacts[0]->contact; $cust_main->first( $contact->first ); $cust_main->set( 'last', $contact->get('last') ); #contact phone numbers? diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 9e506a731..4d5beee71 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -334,6 +334,10 @@ Example: % #any? % 'colspan' => $f->{'colspan'}, % 'required' => $f->{'required'}, +% +% #contact +% 'custnum' => $f->{'custnum'}, +% 'prospectnum' => $f->{'prospectnum'}, % ); % % $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}), diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html index 979c26b49..ef74481c0 100644 --- a/httemplate/elements/contact.html +++ b/httemplate/elements/contact.html @@ -9,7 +9,7 @@ <SELECT NAME="<%$name%>_classnum" <% $onchange %>> <OPTION VALUE=""> % my $classnum = scalar($cgi->param($name.'_classnum')) -% || $contact->classnum; +% || $X_contact->classnum; % foreach my $contact_class (@contact_class) { <OPTION VALUE="<% $contact_class->classnum %>" <% ($contact_class->classnum == $classnum) ? 'SELECTED' : '' %> @@ -40,6 +40,8 @@ % } % } elsif ( $field eq 'emailaddress' ) { % $value = join(', ', map $_->emailaddress, $contact->contact_email); +% } elsif ( $field eq 'selfservice_access' || $field eq 'comment' ) { +% $value = $X_contact->get($field); % } else { % $value = $contact->get($field); % } @@ -100,10 +102,25 @@ if ( $opt{'onchange'} ) { my @contact_class = qsearch('contact_class', { 'disabled' => '' }); my $contact; +my $X_contact; if ( $curr_value ) { $contact = qsearchs('contact', { 'contactnum' => $curr_value } ); + if ( $opt{'custnum'} ) { + $X_contact = qsearchs('cust_contact', { + 'contactnum' => $curr_value, + 'custnum' => $opt{'custnum'}, + }); + } elsif ( $opt{'prospectnum'} ) { + $X_contact = qsearchs('prospect_contact', { + 'contactnum' => $curr_value, + 'prospectnum' => $opt{'prospectnum'}, + }); + } else { + die 'neither custnum nor prospectnum specified'; + } } else { $contact = new FS::contact {}; + $X_contact = new FS::cust_contact; #arbitrary, it could be prospect_contact } my %size = ( 'title' => 12 ); diff --git a/httemplate/elements/tr-select-contact.html b/httemplate/elements/tr-select-contact.html index e37d26d1b..0bfa8934c 100644 --- a/httemplate/elements/tr-select-contact.html +++ b/httemplate/elements/tr-select-contact.html @@ -138,8 +138,8 @@ if ( $cgi->param('error') ) { if ( length($opt{'curr_value'}) ) { $contactnum = $opt{'curr_value'}; } elsif ($prospect_main) { - my @cust_contact = $prospect_main->contact; - $contactnum = $cust_contact[0]->contactnum if scalar(@cust_contact)==1; + my @prospect_contact = $prospect_main->prospect_contact; + $contactnum = $prospect_contact[0]->contactnum if scalar(@cust_contact)==1; } else { #$cust_main $cgi->param('contactnum') =~ /^(\-?\d*)$/ or die "illegal contactnum"; $contactnum = $1; @@ -176,8 +176,10 @@ my $contact_sort = sub { }; my @contact; -push @contact, $cust_main->cust_contact if $cust_main; -push @contact, $prospect_main->contact if $prospect_main; +push @contact, map $_->contact, $cust_main->cust_contact + if $cust_main; +push @contact, map $_->contact, $prospect_main->prospect_contact + if $prospect_main; push @contact, $contact if !$cust_main && $contact && $contact->contactnum > 0 && ! grep { $_->contactnum == $contact->contactnum } @contact; diff --git a/httemplate/misc/email-quotation.html b/httemplate/misc/email-quotation.html index b93b80bb7..64e3691b5 100644 --- a/httemplate/misc/email-quotation.html +++ b/httemplate/misc/email-quotation.html @@ -16,9 +16,11 @@ % } % } -% my @contact = $quotation->custnum ? $quotation->cust_main->cust_contact -% : $quotation->prospect_main->contact; -% foreach my $contact ( @contact ) { +% my @X_contact = $quotation->custnum +% ? $quotation->cust_main->cust_contact +% : $quotation->prospect_main->prospect_contact; +% foreach my $X_contact ( @X_contact ) { +% my $contact = $X_contact->contact; % foreach my $contact_email ( $contact->contact_email ) { % $emails++; <& .emailrow, $contact_email->emailaddress, $contact->firstlast &> diff --git a/httemplate/search/contact.html b/httemplate/search/contact.html index 650307824..c3667df98 100644 --- a/httemplate/search/contact.html +++ b/httemplate/search/contact.html @@ -1,13 +1,13 @@ <& elements/search.html, title => 'Contacts', name_singular => 'contact', - query => { select => $select, + query => { select => join(', ', @select), table => 'contact', addl_from => $addl_from, hashref => \%hash, extra_sql => $extra_sql, }, - count_query => "SELECT COUNT(*) FROM contact $extra_sql", #XXX + count_query => "SELECT COUNT(*) FROM contact $addl_from $extra_sql", #XXX header => \@header, fields => \@fields, links => \@links, @@ -17,13 +17,29 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('List contacts'); -my $select = 'contact.*'; +my @select = 'contact.contactnum AS contact_contactnum'; #if we select it as bare contactnum, the multi-customer listings go away +push @select, map "contact.$_", qw( first last title ); my %hash = (); my $addl_from = ''; -my @header = ( 'First', 'Last', 'Title', ); -my @fields = ( 'first', 'last', 'title', ); -my @links = ( '', '', '' ); +my $link; #for closure in this sub, we'll define it later +my $contact_classname_sub = sub { + my $contact = shift; + my %hash = ( 'contactnum' => $contact->contact_contactnum ); + my $X_contact; + if ( $link eq 'cust_main' ) { + $X_contact = qsearchs('cust_contact', { %hash, 'custnum' => $contact->custnum } ); + } elsif ( $link eq 'prospect_main' ) { + $X_contact = qsearchs('prospect_contact', { %hash, 'prospectnum' => $contact->prospectnum } ); + } else { + die 'guru meditation #5555'; + } + $X_contact->contact_classname; +}; + +my @header = ( 'First', 'Last', 'Title', 'Type' ); +my @fields = ( 'first', 'last', 'title', $contact_classname_sub ); +my @links = ( '', '', '', '', ); my $company_link = ''; @@ -32,23 +48,30 @@ if ( $cgi->param('selfservice_access') eq 'Y' ) { } my $extra_sql = ''; -if ( $cgi->param('link') ) { +$link = $cgi->param('link'); +if ( $link ) { my $as = ') AS prospect_or_customer'; - if ( $cgi->param('link') eq 'cust_main' ) { + if ( $link eq 'cust_main' ) { push @header, 'Customer'; - $select .= - ", COALESCE( cust_main.company, cust_main.first||' '||cust_main.last $as"; - $addl_from = ' LEFT JOIN cust_main USING ( custnum )'; - $extra_sql = ' custnum IS NOT NULL '; + push @select, + "COALESCE( cust_main.company, cust_main.first||' '||cust_main.last $as", + map "cust_contact.$_", qw( custnum classnum comment selfservice_access ); + $addl_from = + ' LEFT JOIN cust_contact USING ( contactnum ) '. + ' LEFT JOIN cust_main ON ( cust_contact.custnum = cust_main.custnum )'; + $extra_sql = ' cust_contact.custnum IS NOT NULL '; $company_link = [ $p.'view/cust_main.cgi?', 'custnum' ]; - } elsif ( $cgi->param('link') eq 'prospect_main' ) { + } elsif ( $link eq 'prospect_main' ) { push @header, 'Prospect'; - $select .= - ", COALESCE( prospect_main.company, contact.first||' '||contact.last $as"; - $addl_from = ' LEFT JOIN prospect_main USING ( prospectnum )'; - $extra_sql = ' prospectnum IS NOT NULL '; + push @select, + "COALESCE( prospect_main.company, contact.first||' '||contact.last $as", + map "prospect_contact.$_", qw( prospectnum classnum comment ); + $addl_from = + ' LEFT JOIN prospect_contact USING ( contactnum ) '. + ' LEFT JOIN prospect_main ON ( prospect_contact.prospectnum = prospect_main.prospectnum )'; + $extra_sql = ' prospect_contact.prospectnum IS NOT NULL '; $company_link = [ $p.'view/prospect_main.html?', 'prospectnum' ]; } else { die "don't know how to report on contacts linked to specified table"; @@ -63,6 +86,9 @@ if ( $cgi->param('link') ) { push @header, 'Self-service'; push @fields, 'selfservice_access'; +push @header, 'Comment'; +push @fields, 'comment'; + $extra_sql = (keys(%hash) ? ' AND ' : ' WHERE '). $extra_sql if $extra_sql; diff --git a/httemplate/search/prospect_main.html b/httemplate/search/prospect_main.html index 4798f58f2..241918b98 100644 --- a/httemplate/search/prospect_main.html +++ b/httemplate/search/prospect_main.html @@ -12,9 +12,9 @@ sub { my $pm = shift; [ map { - [ { 'data' => $_->line, }, ]; + [ { 'data'=>$_->contact->line, }, ]; } - $pm->contact + $pm->prospect_contact ]; }, ], diff --git a/httemplate/view/cust_main/contacts_new.html b/httemplate/view/cust_main/contacts_new.html index f73483ae1..f0bc0b848 100644 --- a/httemplate/view/cust_main/contacts_new.html +++ b/httemplate/view/cust_main/contacts_new.html @@ -6,26 +6,31 @@ % my $bgcolor1 = '#eeeeee'; % my $bgcolor2 = '#ffffff'; % my $bgcolor = $bgcolor2; +% my $th = '<TH CLASS="grid" ALIGN="left" BGCOLOR="#cccccc">'; <TR> - <TH CLASS="grid" ALIGN="left" BGCOLOR="#cccccc">Type</TH> - <TH CLASS="grid" ALIGN="left" BGCOLOR="#cccccc">Contact</TH> - <TH CLASS="grid" ALIGN="left" BGCOLOR="#cccccc">Email</TH> - <TH CLASS="grid" ALIGN="left" BGCOLOR="#cccccc">Self-service</TH> + <%$th%>Type</TH> + <%$th%>Contact</TH> + <%$th%>Email</TH> + <%$th%>Self-service</TH> % foreach my $phone_type (@phone_type) { - <TH CLASS="grid" ALIGN="left" BGCOLOR="#cccccc"><% $phone_type->typename |h %> phone</TD> + <%$th%><% $phone_type->typename |h %></TH> % } + <%$th%>Comment</TH> </TR> -% foreach my $contact ( @contacts ) { +% foreach my $cust_contact ( @cust_contacts ) { +% my $contact = $cust_contact->contact; +% my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">); + <TR> - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $contact->contact_classname |h %></TD> - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $contact->line |h %></TD> + <%$td%><% $cust_contact->contact_classname |h %></TD> + <%$td%><% $contact->line |h %></TD> % my @contact_email = $contact->contact_email; - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% join(', ', map $_->emailaddress, @contact_email) %></TD> + <%$td%><% join(', ', map $_->emailaddress, @contact_email) %></TD> - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"> -% if ( $contact->selfservice_access ) { + <%$td%> +% if ( $cust_contact->selfservice_access ) { Enabled %# <FONT SIZE="-1"><A HREF="XXX">disable</A> %# <A HREF="XXX">re-email</A></FONT> @@ -41,9 +46,11 @@ % 'contactnum' => $contact->contactnum, % 'phonetypenum' => $phone_type->phonetypenum, % }); - <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $contact_phone ? $contact_phone->phonenum_pretty : '' |h %></TD> + <%$td%><% $contact_phone ? $contact_phone->phonenum_pretty : '' |h %></TD> % } + <%$td%><% $cust_contact->comment |h %></TD> + </TR> % if ( $bgcolor eq $bgcolor1 ) { @@ -63,6 +70,6 @@ my @phone_type = qsearch({table=>'phone_type', order_by=>'weight'}); my( $cust_main ) = @_; #my $conf = new FS::Conf; -my @contacts = $cust_main->cust_contact; +my @cust_contacts = $cust_main->cust_contact; </%init> diff --git a/httemplate/view/prospect_main.html b/httemplate/view/prospect_main.html index 66abffcdd..a1f14a374 100644 --- a/httemplate/view/prospect_main.html +++ b/httemplate/view/prospect_main.html @@ -39,9 +39,10 @@ </TR> % } -% foreach my $contact ( $prospect_main->contact ) { +% foreach my $prospect_contact ( $prospect_main->prospect_contact ) { +% my $contact = $prospect_contact->contact; <TR> - <TD ALIGN="right"><% $contact->contact_classname %> Contact</TD> + <TD ALIGN="right"><% $prospect_contact->contact_classname %> Contact</TD> <TD BGCOLOR="#FFFFFF"><% $contact->line %></TD> </TR> %} |