-<FORM ACTION="<% $p1 %>process/cust_pkg.cgi" METHOD=POST>
-<INPUT TYPE="hidden" NAME="action" VALUE="bulk">
-<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
-
-%#current packages
-%if (@cust_pkg) {
-
- Current packages - select to remove (services are moved to a new package below)
- <TABLE>
- <TR STYLE="background-color: #cccccc;">
- <TH COLSPAN="2">Pkg #</TH>
- <TH>Package description</TH>
- </TR>
- <BR><BR>
-%
-% foreach ( @main_pkgs ) {
-% my($pkgnum,$pkgpart)=( $_->getfield('pkgnum'), $_->getfield('pkgpart') );
-% my $checked = $remove_pkg{$pkgnum} ? ' CHECKED' : '';
-%
-%
-
-
- <TR>
- <TD><INPUT TYPE="checkbox" NAME="remove_pkg" VALUE="<% $pkgnum %>"<% $checked %>></TD>
- <TD ALIGN="right"><% $pkgnum %>:</TD>
- <TD><% $all_pkg{$pkgpart} |h %> - <% $all_comment{$pkgpart} |h %></TD>
- </TR>
-% foreach my $supp_pkg ( @{ $supp_pkgs_of{$pkgnum} } ) {
- <TR>
- <TD></TD>
- <TD></TD>
- <TD>+ <% $all_pkg{$supp_pkg->pkgpart} |h %> - <% $all_comment{$supp_pkg->pkgpart} |h %></TD>
- </TR>
+<script>
+
+ let locationnum = "<% $cust_main->ship_locationnum %>";
+
+ function location_changed(e) {
+ locationnum = $(e).val();
+ $('tr[data-locationnum]').find('input').prop('checked', false);
+ $('tr[data-locationnum]').each( function() {
+ let tr_el = $(this);
+ tr_el.css(
+ 'display',
+ locationnum == tr_el.data('locationnum') ? 'table-row' : 'none'
+ );
+ });
+ }
+
+ function pkg_class_filter_onchange( selected ) {
+ if ( selected.length == 0 ) {
+ $('tr[data-classnum]').css('display', 'table-row');
+ } else {
+ $('tr[data-classnum]').each( function() {
+ let tr_el = $(this);
+ let classnum = tr_el.data('classnum');
+ let is_displayed = $.grep( selected, function( item ) {
+ return item == classnum;
+ });
+ let display = is_displayed.length ? 'table-row' : 'none';
+ tr_el.css( 'display', is_displayed.length ? 'table-row' : 'none' );
+ });
+ }
+ }
+
+ function confirm_form() {
+ let cust_pkg_removed = [];
+ let pkg_part_added = [];
+
+ $('input[data-locationnum]:checked').each( function() {
+ let this_el = $(this);
+ cust_pkg_removed.push(
+ '#' + this_el.data('pkgnum') + ' ' + this_el.data('pkg')
+ );
+ });
+
+ $('input[data-pkgpart]').each( function() {
+ qty_el = $(this);
+ qty = qty_el.val();
+
+ if ( qty < 1 ) { return; }
+
+ pkg_part_added.push( qty + ' x ' + qty_el.data('pkg') );
+ });
+
+ if ( cust_pkg_removed.length == 0 ) {
+ cust_pkg_removed.push('No Existing Packages Selected');
+ }
+ if ( pkg_part_added.length == 0 ) {
+ pkg_part_added.push('No New Packages Selected');
+ }
+
+ console.log( cust_pkg_removed );
+ console.log( pkg_part_added );
+
+ confirm_html =
+ '<div style="margin: 1em;">'
+ + '<b><u>Removed Packages:</u></b><br>'
+ + cust_pkg_removed.join('<br>')
+ + '<br><br>'
+ + '<b><u>Replacement Packages:</u></b><br>'
+ + pkg_part_added.join('<br>')
+ + '<br><br>'
+ + '<input type="button" role="button" onclick="submit_form();" value="Confirm Order">'
+ + '</div>';
+
+ overlib(
+ confirm_html,
+ CAPTION, 'Confirm bulk change',
+ STICKY,
+ AUTOSTATUSCAP,
+ MIDX, 0,
+ MIDY, 0,
+ WIDTH, 300,
+ HEIGHT, 200,
+ TEXTSIZE, 3,
+ BGCOLOR, '#ff0000',
+ CGCOLOR, '#ff0000'
+ );
+ }
+
+ function submit_form() {
+ $('#formBulkEdit').submit();
+ }
+</script>
+
+<form action="<% $fsurl %>edit/process/cust_pkg.cgi" method="POST" id="formBulkEdit">
+<input type="hidden" name="custnum" value="<% $custnum %>">
+<input type="hidden" name="action" value="bulk">
+
+<p style="margin-bottom: 2em;">
+ <label for="locationnum">Service Location</label>
+ <% include( '/elements/select-cust_location.html',
+ cust_main => $cust_main,
+ addnew => 0,
+ onchange => 'javascript:location_changed(this);',
+ ) %><br>
+ <span style="font-size: .8em; padding-left: 1em;">
+ Bulk-edit works with one customer location at a time
+ </span>
+</p>
+
+<table style="margin-bottom: 2em;">
+ <thead>
+ <tr style="background-color: #ccc;">
+ <th colspan="2" style="text-align: left;">
+ Pkg #
+ </th>
+ <th style="text-align: left;">
+ Current Packages<br>
+ <div style="font-size: .8em; padding-left: 1em; font-weight: normal;">
+ Selected packages are removed.<br>
+ Attached services are moved to the new package selected below
+ </span>
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+% for my $cust_pkg ( @cust_pkg ) {
+% my $id = sprintf 'remove_cust_pkg[%s]', $cust_pkg->pkgnum;
+% my $is_displayed = $cust_main->ship_locationnum == $cust_pkg->locationnum ? 1 : 0;
+ <tr data-locationnum="<% $cust_pkg->locationnum %>" data-pkg="<% $cust_pkg->pkg |h %>" style="display: <% $is_displayed ? 'table-row' : 'none' %>;">
+ <td>
+ <input type="checkbox"
+ name="<% $id %>"
+ id="<% $id %>"
+ data-pkgnum="<% $cust_pkg->pkgnum %>"
+ data-locationnum="<% $cust_pkg->locationnum %>"
+ data-pkg="<% $part_pkg{ $cust_pkg->pkgpart }->pkg |h %>">
+ </td>
+ <td>#<% $cust_pkg->pkgnum %></td>
+ <td>
+ <label for="<% $id %>">
+ <% $part_pkg{ $cust_pkg->pkgpart }->pkg %><br>
+% for my $cust_pkg_supp ( @{ $cust_pkg_supp_of{ $cust_pkg->pkgnum }} ) {
+ <span style="font-size: .8em; padding-left: 1em;">
+ <b>Supplementary:</b> <% $part_pkg{ $cust_pkg_supp->pkgpart }->pkg %>
+ </span>
+ </label>
+% }
+ </td>
+ </tr>