X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=httemplate%2Fedit%2Fcust_pkg.cgi;h=4e4f4d2b2184bb57fea8321234ddffd7974a7f54;hb=219c811aa5ee634bb17e1fa19a2d75351949b8d4;hp=7ffbb1fc0e2da2fe81b40ed6523af6ce04ae8685;hpb=d20e332890418a6713c0617cd7af5507664168e2;p=freeside.git diff --git a/httemplate/edit/cust_pkg.cgi b/httemplate/edit/cust_pkg.cgi index 7ffbb1fc0..4e4f4d2b2 100755 --- a/httemplate/edit/cust_pkg.cgi +++ b/httemplate/edit/cust_pkg.cgi @@ -1,115 +1,207 @@ -<% include('/elements/header.html', "Add/Edit Packages", '') %> +<%doc> + Bulk package Edit Page + +%doc> +<& /elements/header-cust_main.html, + view => 'packages', + cust_main => $cust_main, + include_selectize => 1, +&> <% include('/elements/error.html') %> -
<% include('/elements/footer.html') %> @@ -118,53 +210,41 @@ Order new packages die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Bulk change customer packages'); -my %pkg = (); -my %comment = (); -my %all_pkg = (); -my %all_comment = (); -#foreach (qsearch('part_pkg', { 'disabled' => '' })) { -# $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg'); -# $comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment'); -#} -foreach (qsearch('part_pkg', {} )) { - $all_pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg'); - $all_comment{ $_ -> getfield('pkgpart') } = $_->custom_comment; - next if $_->disabled; - $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg'); - $comment{ $_ -> getfield('pkgpart') } = $_->custom_comment; -} +my $custnum = $cgi->param('keywords') || $cgi->param('custnum'); +$custnum =~ /^\d+$/ + or die "Invalid custnum($custnum)"; -my($custnum, %remove_pkg); -if ( $cgi->param('error') ) { - $custnum = $cgi->param('custnum'); - %remove_pkg = map { $_ => 1 } $cgi->param('remove_pkg'); -} else { - my($query) = $cgi->keywords; - $query =~ /^(\d+)$/; - $custnum = $1; - %remove_pkg = (); -} +my $cust_main = qsearchs( cust_main => { custnum => $custnum }) + or die "Invalid custnum ($custnum)"; -my $p1 = popurl(1); +my %part_pkg; +my @part_pkg_enabled; -my @cust_pkg = qsearch('cust_pkg', { 'custnum' => $custnum, 'cancel' => '' } ); -my @main_pkgs; -my %supp_pkgs_of; # main pkgnum => arrayref of cust_pkgs - - -foreach my $cust_pkg - ( sort { $all_pkg{ $a->pkgpart } cmp $all_pkg{ $b->getfield('pkgpart') } } - @cust_pkg +for my $part_pkg ( qsearch( part_pkg => {} )) { + $part_pkg{ $part_pkg->pkgpart } = $part_pkg; + push @part_pkg_enabled, $part_pkg + unless $part_pkg->disabled; +} +@part_pkg_enabled = + sort { $a->classname cmp $b->classname || $a->pkg cmp $b->pkg } + @part_pkg_enabled; + +my @cust_pkg; +my %cust_pkg_supp_of; +for my $cust_pkg ( + qsearch( + cust_pkg => { + custnum => $custnum, + cancel => '', + } ) - # XXX does not properly handle recursive supplemental links -{ +) { if ( my $main_pkgnum = $cust_pkg->main_pkgnum ) { - $supp_pkgs_of{$main_pkgnum} ||= []; - push @{ $supp_pkgs_of{$main_pkgnum} }, $cust_pkg; + $cust_pkg_supp_of{ $main_pkgnum } //= []; + push @{ $cust_pkg_supp_of{ $main_pkgnum } }, $cust_pkg; } else { - push @main_pkgs, $cust_pkg; - $supp_pkgs_of{$cust_pkg->pkgnum} ||= []; + $cust_pkg_supp_of{ $cust_pkg->pkgnum } //= []; + push @cust_pkg, $cust_pkg; } } - %init>