1 %# Copyright (c) 2004 Ivan Kohler <ivan-rt@420.am>
3 %# This work is made available to you under the terms of Version 2 of
4 %# the GNU General Public License. A copy of that license should have
5 %# been provided with this software, but in any event can be snarfed
8 %# This work is distributed in the hope that it will be useful, but
9 %# WITHOUT ANY WARRANTY; without even the implied warranty of
10 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 %# General Public License for more details.
13 Provides resolver objects (RT::URI::freeside) for customer/service links
14 to a specified ticket.
17 %hash = $m->comp('Customers', Ticket => $ticket);
19 %hash contains four elements:
20 - "custnums", an arrayref of customer numbers that are linked to the ticket,
22 - "cust_main", a hashref of custnum => customer object, for each custnum.
23 - "cust_linked", a hashref of custnum => boolean flag. If the flag is true,
24 then the customer is _explicitly_ linked (i.e. there is a
25 'freeside://freeside/cust_main/' record in the Links table). Otherwise,
26 the customer link is implied by a service link but doesn't exist in its
28 - "cust_svc", a hashref of custnum => an arrayref of service objects that
29 are linked to the ticket and belong to that customer.
36 my $customers = $Ticket->Customers;
37 # ensure each customer is displayed only once
38 while (my $link = $customers->Next) {
39 my $uri = $link->Target;
40 if ( $uri =~ /cust_main\/(\d+)/ ) {
41 $cust_main{$1} = $link->TargetURI->Resolver;
43 } elsif ( $uri =~ /cust_svc\/(\d+)/ ) {
44 my $svc = $link->TargetURI->Resolver;
45 my $cust = $svc->CustomerResolver;
47 my $custnum = $cust->{fspkey};
48 $cust_main{$custnum} ||= $cust if $cust;
49 $cust_svc{$custnum} ||= [];
50 push @{$cust_svc{$custnum}}, $svc if $svc;
54 @custnums = sort { $a <=> $b } keys %cust_main;
56 'custnums' => \@custnums,
57 'cust_main' => \%cust_main,
58 'cust_svc' => \%cust_svc,
59 'cust_linked' => \%cust_linked,