optimize package view with tons of packages, RT#28526
[freeside.git] / httemplate / view / cust_main / packages / location.html
1 % if ( $cust_pkg->change_from_pkg
2 %      and $cust_pkg->change_from_pkg->locationnum == $cust_pkg->locationnum)
3 % {
4 % # don't show the location
5 % } else {
6 %   if ( !$opt{'cust_pkg-group_by_location'} ) {
7 %     if ( $default ) {
8         <DIV STYLE="font-style: italic; font-size: small">
9 %     }
10
11       <% $loc->location_label( 'join_string'     => '<BR>',
12                                'double_space'    => ' &nbsp; ',
13                                'escape_function' => \&encode_entities,
14                                'countrydefault'  => $countrydefault,
15                                'cust_main'       => $opt{'cust_main'},
16                              )
17       %>
18
19 %     if ( $loc->latitude && $loc->longitude ) {
20           <BR>
21           <FONT SIZE=-1>
22           <% $loc->latitude %>, <% $loc->longitude %>
23           <& /elements/coord-links.html, {
24                'latitude'        => $loc->latitude,
25                'longitude'       => $loc->longitude,
26                'name'            => $opt{'cust_main'}->name_short.
27                                       ': '. $opt{'part_pkg'}->pkg,
28                'company_address' => $opt{'company_address'},
29              }
30           &>
31           </FONT>
32 %     }
33 %     if ( $loc->censustract ) {
34          <BR>
35          <FONT SIZE=-1>
36          <% $loc->censustract %> (<% $loc->censusyear %> census)
37          </FONT>
38 %     } elsif ( $opt{'cust_main-require_censustract'} ) {
39           <BR>
40           <FONT SIZE=-1 COLOR="#ee3300">
41           <% emt('Census tract unknown') %>
42           </FONT>
43 %     }
44
45 %     if ( $default ) {
46       </DIV>
47 %     }
48 %   } # all of this is hidden if packages are grouped by location, because
49 %     # it's in the top banner
50
51 %   if ( ! $cust_pkg->get('cancel')
52 %      && $FS::CurrentUser::CurrentUser->access_right('Change customer package')
53 %     )
54 %   {
55   <BR>
56   <FONT SIZE=-1>
57 %     unless ( $opt{no_links} or $opt{'change_from'} ) {
58       (&nbsp;<%pkg_change_location_link($cust_pkg)%>&nbsp;)
59 %     }
60 %     if ( $cust_pkg->locationnum && ! $opt{no_links} ) {
61         (&nbsp;<%pkg_edit_location_link($cust_pkg->locationnum)%>&nbsp;)
62 %     }
63   </FONT>
64 %   } 
65 % } # if the package is a scheduled future package change without location
66 %   # change, then don't show any of this at all.  It's all implied by the
67 %   # preceding package.
68 <%init>
69
70 my %opt = @_;
71
72 my $cust_pkg       = $opt{'cust_pkg'};
73 my $countrydefault = $opt{'countrydefault'} || 'US';
74 my $statedefault   = $opt{'statedefault'}
75                      || ($countrydefault eq 'US' ? 'CA' : '');
76
77 my $loc = $cust_pkg->cust_location_or_main('_cache'=>$opt{cust_location_cache});
78 # dubious--they should all have a location now
79 my $default = $cust_pkg->locationnum == $opt{'cust_main'}->ship_locationnum;
80
81 sub pkg_change_location_link {
82   my $cust_pkg = shift;
83   my $pkgpart = $cust_pkg->pkgpart;
84   include( '/elements/popup_link-cust_pkg.html',
85     'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
86                      "address1=;address2=;city=;county=;state=$statedefault;".
87                      "zip=;country=$countrydefault",
88     'label'       => emt('Change location'),
89     'actionlabel' => emt('Change'),
90     'cust_pkg'    => $cust_pkg,
91     'width'       => 960,
92     'height'      => 490,
93   );
94 }
95
96 sub pkg_edit_location_link {
97   my $locationnum = shift;
98   include( '/elements/popup_link.html',
99     'action'      => $p. "edit/cust_location.cgi?locationnum=$locationnum",
100     'label'       => emt('Edit location'),
101     'actionlabel' => emt('Edit'),
102     'width'       => 700,
103     'height'      => 355,
104    );
105 }
106
107 </%init>