% foreach my $locationnum (@sorted) { % my $packages = $packages_in{$locationnum}; % my $loc = $locations{$locationnum}; % next if $loc->disabled and scalar(@$packages) == 0; <& /elements/table-grid.html &> % if (! $locationnum) { <% mt('Default service location:') |h %> % } % elsif ( $loc->disabled ) { % } <% $loc->location_label %> % if ( $locationnum and !$loc->disabled ) { <% edit_location_link($locationnum) %> % } % if ( $locationnum and !$loc->disabled and !$active{$locationnum} ) {  <% disable_location_link($locationnum) %> % } % if (@$packages) { <& packages/section.html, 'packages' => $packages &> % }
% } #foreach $locationnum <%init> my %opt = @_; my $cust_main = $opt{'cust_main'}; my $all_packages = $opt{'packages'}; my %locations = map { $_->locationnum => $_ } qsearch({ 'table' => 'cust_location', 'hashref' => { 'custnum' => $cust_main->custnum }, 'order_by' => 'ORDER BY country, state, city, address1, locationnum', }); my @sections = keys %locations; $locations{''} = $cust_main; my %packages_in = map { $_ => [] } ('', @sections); my %active = (); # groups with non-canceled packages foreach my $cust_pkg ( @$all_packages ) { my $key = $cust_pkg->locationnum; push @{ $packages_in{$key} }, $cust_pkg; $active{$key} = 1 if !$cust_pkg->getfield('cancel'); } my @sorted = ( '', grep ( { $active{$_} } @sections), grep ( { !$active{$_} } @sections), ); sub edit_location_link { my $locationnum = shift; include( '/elements/popup_link.html', 'action' => $p. "edit/cust_location.cgi?locationnum=$locationnum", 'label' => '('.emt('Edit location').')', 'actionlabel' => emt('Edit'), ); } sub disable_location_link { my $locationnum = shift; include( '/elements/popup_link.html', 'action' => $p. "misc/disable-cust_location.cgi?locationnum=$locationnum", 'label' => '('.emt('Disable location').')', 'actionlabel' => emt('Disable'), ); }