<% include('/elements/header-popup.html', 'Bulk DID order - DID provisioning' ) %> <% include('/elements/error.html') %>
% my $anyavail = 0; % foreach my $cust_main ( @cust_main ) { % my($cust_pkg_phone,$cust_pkg_label,$svc_label) = possible_pkgs($cust_main); % my $avail = keys(%$cust_pkg_phone); % $anyavail = 1 if $avail; % } % if ( $anyavail ) { % }
Order # <% $ordernum %>
Customer Package/Service
<% $cust_main->name |h %> % if ( !$avail ) { No suitable packages exist for this customer. % } else { % }
<%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Import'); $cgi->param('ordernum') =~ /^(\d+)$/ or die 'illegal ordernum'; my $ordernum = $1; my $did_order = qsearchs( { 'table' => 'did_order', 'hashref' => { 'ordernum' => $ordernum }, } ); die "No order $ordernum" unless $did_order; my @cust_main = $did_order->cust_main; die "Order is not in received status and/or DIDs not assigned to any customers" unless $did_order->received && scalar(@cust_main); my @dids = qsearch( 'phone_avail', { ordernum => $ordernum } ); die "no DIDs on order" unless scalar(@dids); sub possible_pkgs { my $cust_main = shift; my (%cust_pkg_phone, %cust_pkg_label, %svc_label); my @pkgs = $cust_main->ncancelled_pkgs; return (\%cust_pkg_phone,\%cust_pkg_label,\%svc_label) unless scalar(@pkgs); foreach my $pkg ( @pkgs ) { my @avail_part_svc = $pkg->available_part_svc; my @svcpart; foreach my $avail_part_svc ( @avail_part_svc ) { if ($avail_part_svc->svcdb eq 'svc_phone' && $avail_part_svc->num_avail >= scalar(@dids)) { push @svcpart, $avail_part_svc->svcpart; $svc_label{$avail_part_svc->svcpart} = $avail_part_svc->svc; } } $cust_pkg_phone{$pkg->pkgnum} = \@svcpart if scalar(@svcpart); $cust_pkg_label{$pkg->pkgnum} = $pkg->part_pkg->pkg; } (\%cust_pkg_phone,\%cust_pkg_label,\%svc_label); }