diff options
author | Mark Wells <mark@freeside.biz> | 2013-01-12 12:03:16 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2013-01-12 12:07:06 -0800 |
commit | b70b0d8c6f571a68ffb60c5ca728a230926abee4 (patch) | |
tree | 27e6d37c746c8eb5a4a9e257297d98d569bd5a1b /httemplate/edit | |
parent | dd825e780ad1e7d520f5c2d7f99c0f67fe892781 (diff) |
supplemental packages, #20689
Diffstat (limited to 'httemplate/edit')
-rwxr-xr-x | httemplate/edit/REAL_cust_pkg.cgi | 87 | ||||
-rwxr-xr-x | httemplate/edit/cust_pkg.cgi | 36 | ||||
-rwxr-xr-x | httemplate/edit/part_pkg.cgi | 14 | ||||
-rwxr-xr-x | httemplate/edit/process/REAL_cust_pkg.cgi | 57 | ||||
-rwxr-xr-x | httemplate/edit/process/part_pkg.cgi | 9 |
5 files changed, 131 insertions, 72 deletions
diff --git a/httemplate/edit/REAL_cust_pkg.cgi b/httemplate/edit/REAL_cust_pkg.cgi index 166a3b7ea..4bcf55c44 100755 --- a/httemplate/edit/REAL_cust_pkg.cgi +++ b/httemplate/edit/REAL_cust_pkg.cgi @@ -9,6 +9,29 @@ <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-en.js"></SCRIPT> <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-setup.js"></SCRIPT> +<SCRIPT TYPE="text/javascript"> +var submit_fields = []; +function confirm_changes() { + var i; + var querystring = 'pkgnum=<%$pkgnum%>'; + var f = document.forms.formname; + for(i = 0; i < submit_fields.length; i++) { + querystring += ';' + + submit_fields[i] + + '=' + + encodeURIComponent(f.elements[submit_fields[i] + '_text'].value); + } + overlib( + OLiframeContent( + '<%$p%>/misc/confirm-cust_pkg-edit_dates.html?' + querystring, + 576, 576, 'confirm_popup' + ), + CAPTION, 'Package date changes', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', + MIDX, 0, MIDY, 0, DRAGGABLE, BGCOLOR, '#333399', CGCOLOR, '#333399', + TEXTSIZE, 3 + ); +} +</SCRIPT> <FORM NAME="formname" ACTION="process/REAL_cust_pkg.cgi" METHOD="POST"> <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>"> @@ -31,6 +54,15 @@ <TD BGCOLOR="#ffffff"><% $part_pkg->pkg %></TD> </TR> +% if ( $cust_pkg->main_pkgnum ) { +% my $main_pkg = $cust_pkg->main_pkg; + <TR> + <TD ALIGN="right">Supplemental to</TD> + <TD BGCOLOR="#ffffff">Package #<% $cust_pkg->main_pkgnum%>: \ + <% $main_pkg->part_pkg->pkg %></TD> + </TR> + +% } <TR> <TD ALIGN="right">Custom</TD> <TD BGCOLOR="#ffffff"><% $part_pkg->custom %></TD> @@ -50,14 +82,14 @@ % if ( $cust_pkg->setup && ! $cust_pkg->start_date ) { <& .row_display, cust_pkg=>$cust_pkg, column=>'start_date', label=>'Start' &> % } else { - <& .row_edit, cust_pkg=>$cust_pkg, column=>'start_date', label=>'Start' &> + <& .row_edit, cust_pkg=>$cust_pkg, column=>'start_date', label=>'Start', if_primary=>1 &> % } - <& .row_edit, cust_pkg=>$cust_pkg, column=>'setup', label=>'Setup' &> + <& .row_edit, cust_pkg=>$cust_pkg, column=>'setup', label=>'Setup', if_primary=>1 &> <& .row_edit, cust_pkg=>$cust_pkg, column=>'last_bill', label=>$last_bill_or_renewed &> <& .row_edit, cust_pkg=>$cust_pkg, column=>'bill', label=>$next_bill_or_prepaid_until &> %#if ( $cust_pkg->contract_end or $part_pkg->option('contract_end_months',1) ) { - <& .row_edit, cust_pkg=>$cust_pkg, column=>'contract_end',label=>'Contract end' &> + <& .row_edit, cust_pkg=>$cust_pkg, column=>'contract_end',label=>'Contract end', if_primary=>1 &> %#} <& .row_display, cust_pkg=>$cust_pkg, column=>'adjourn', label=>'Adjournment', note=>'(will <b>suspend</b> this package when the date is reached)' &> <& .row_display, cust_pkg=>$cust_pkg, column=>'susp', label=>'Suspension' &> @@ -73,10 +105,17 @@ $column $label $note => '' + $if_primary => 0 </%args> % my $value = $cust_pkg->get($column); % $value = $value ? time2str($format, $value) : ""; - +% +% # if_primary for the dates that can't be edited on supplemental packages +% if ($if_primary and $cust_pkg->main_pkgnum) { + <INPUT TYPE="hidden" ID="<%$column%>_text" VALUE="<% $cust_pkg->get($column) %>"> + <SCRIPT>submit_fields.push('<%$column%>');</SCRIPT> + <& .row_display, %ARGS &> +% } else { <TR> <TD ALIGN="right"><% $label %> date</TD> <TD> @@ -104,8 +143,11 @@ button: "<% $column %>_button", align: "BR" }); - </SCRIPT> + submit_fields.push('<%$column%>'); + + </SCRIPT> +% } </%def> <%def .row_display> @@ -114,6 +156,7 @@ $column $label $note => '' + $is_primary => 0 #ignored </%args> % if ( $cust_pkg->get($column) ) { <TR> @@ -130,7 +173,7 @@ </TABLE> <BR> -<INPUT TYPE="submit" VALUE="<% mt('Apply changes') |h %>"> +<INPUT TYPE="button" VALUE="<% mt('Apply changes') |h %>" onclick="confirm_changes()"> </FORM> <% include('/elements/footer.html') %> @@ -160,38 +203,6 @@ if ( $cgi->param('error') ) { my @errors = (); my %errors = map { $_=>1 } split(',', $cgi->param('error')); $cgi->param('error', ''); - - if ( $errors{'_bill_areyousure'} ) { - if ( $cgi->param('bill') =~ /^([\s\d\/\:\-\(\w\)]*)$/ ) { - my $bill = $1; - push @errors, - "You are attempting to set the next bill date to $bill, which is - in the past. This will charge the customer for the interval - from $bill until now. Are you sure you want to do this? ". - '<INPUT TYPE="checkbox" NAME="bill_areyousure" VALUE="1">'; - } - } - - if ( $errors{'_setup_areyousure'} ) { - push @errors, - "You are attempting to remove the setup date. This will re-charge the - customer for the setup fee. Are you sure you want to do this? ". - '<INPUT TYPE="checkbox" NAME="setup_areyousure" VALUE="1">'; - } - - if ( $errors{'_setupadd_areyousure'} ) { - push @errors, - "You are attempting to add a setup date. This will prevent charging the - customer for the setup fee. Are you sure you want to do this? ". - '<INPUT TYPE="checkbox" NAME="setupadd_areyousure" VALUE="1">'; - } - - if ( $errors{'_start'} ) { - push @errors, - "You are attempting to add a start date to a package that has already - started billing."; - } - $error = join('<BR><BR>', @errors ); } diff --git a/httemplate/edit/cust_pkg.cgi b/httemplate/edit/cust_pkg.cgi index dd1ed335f..88e925460 100755 --- a/httemplate/edit/cust_pkg.cgi +++ b/httemplate/edit/cust_pkg.cgi @@ -7,7 +7,6 @@ <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>"> %#current packages -%my @cust_pkg = qsearch('cust_pkg', { 'custnum' => $custnum, 'cancel' => '' } ); %if (@cust_pkg) { Current packages - select to remove (services are moved to a new package below) @@ -18,13 +17,7 @@ </TR> <BR><BR> % -% -% foreach ( sort { $all_pkg{ $a->getfield('pkgpart') } -% cmp $all_pkg{ $b->getfield('pkgpart') } -% } -% @cust_pkg -% ) -% { +% foreach ( @main_pkgs ) { % my($pkgnum,$pkgpart)=( $_->getfield('pkgnum'), $_->getfield('pkgpart') ); % my $checked = $remove_pkg{$pkgnum} ? ' CHECKED' : ''; % @@ -36,6 +29,13 @@ <TD ALIGN="right"><% $pkgnum %>:</TD> <TD><% $all_pkg{$pkgpart} %> - <% $all_comment{$pkgpart} %></TD> </TR> +% foreach my $supp_pkg ( @{ $supp_pkgs_of{$pkgnum} } ) { + <TR> + <TD></TD> + <TD></TD> + <TD>+ <% $all_pkg{$supp_pkg->pkgpart} %> - <% $all_comment{$supp_pkg->pkgpart} %></TD> + </TR> +% } % } @@ -147,4 +147,24 @@ if ( $cgi->param('error') ) { my $p1 = popurl(1); +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 + ) + # 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; + } else { + push @main_pkgs, $cust_pkg; + $supp_pkgs_of{$cust_pkg->pkgnum} ||= []; + } +} + </%init> diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index c3f4f88b6..7baf84d11 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -53,6 +53,7 @@ 'discountnum' => 'Offer discounts for longer terms', 'bill_dst_pkgpart' => 'Include line item(s) from package', 'svc_dst_pkgpart' => 'Include services of package', + 'supp_dst_pkgpart' => 'Include complete package', 'report_option' => 'Report classes', 'fcc_ds0s' => 'Voice-grade equivalents', 'fcc_voip_class' => 'Category', @@ -239,6 +240,19 @@ }, { 'type' => 'tablebreak-tr-title', + 'value' => 'Supplemental packages', + 'colspan' => '4', + }, + { 'field' => 'supp_dst_pkgpart', + 'type' => 'select-part_pkg', + 'm2_label' => 'Include complete package', + 'm2m_method' => 'supp_part_pkg_link', + 'm2m_dstcol' => 'dst_pkgpart', + 'm2_error_callback' => + &{$m2_error_callback_maker}('supp'), + }, + + { 'type' => 'tablebreak-tr-title', 'value' => 'Pricing add-ons', 'colspan' => 4, }, diff --git a/httemplate/edit/process/REAL_cust_pkg.cgi b/httemplate/edit/process/REAL_cust_pkg.cgi index 3e0ef59c1..fd2893487 100755 --- a/httemplate/edit/process/REAL_cust_pkg.cgi +++ b/httemplate/edit/process/REAL_cust_pkg.cgi @@ -19,36 +19,41 @@ die "access denied" my $pkgnum = $cgi->param('pkgnum') or die; my $old = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum}); my %hash = $old->hash; -$hash{$_}= $cgi->param($_) ? parse_datetime($cgi->param($_)) : '' - foreach qw( start_date setup bill last_bill contract_end ); +foreach ( qw( start_date setup bill last_bill contract_end ) ) { + if ( $cgi->param($_) =~ /^(\d+)$/ ) { + $hash{$_} = $1; + } else { + $hash{$_} = ''; + } # adjourn, expire, resume not editable this way - -my @errors = (); - -push @errors, '_bill_areyousure' - if $hash{'bill'} != $old->bill # if the next bill date was changed - && $hash{'bill'} < time # to a date in the past - && ! $cgi->param('bill_areyousure'); # and it wasn't confirmed - -push @errors, '_setup_areyousure' - if ! $hash{'setup'} && $old->setup # if the setup date was removed - && ! $cgi->param('setup_areyousure'); # and it wasn't confirmed - -push @errors, '_setupadd_areyousure' - if $hash{'setup'} && ! $old->setup # if the setup date was added - && ! $cgi->param('setupadd_areyousure'); # and it wasn't confirmed - -push @errors, '_start' - if $hash{'start_date'} && !$old->start_date # if a start date was added - && $hash{'setup'}; # but there's a setup date +} my $new; my $error; -if ( @errors ) { - $error = join(',', @errors); -} else { - $new = new FS::cust_pkg \%hash; - $error = $new->replace($old); +$new = new FS::cust_pkg \%hash; +$error = $new->replace($old); + +if (!$error) { + my @supp_pkgs = $old->supplemental_pkgs; + foreach $new (@supp_pkgs) { + foreach ( qw( start_date setup contract_end ) ) { + # propagate these to supplementals + $new->set($_, $hash{$_}); + } + if ( $hash{'bill'} ne $old->get('bill') ) { + if ( $hash{'bill'} and $old->get('bill') ) { + # adjust by the same interval + my $diff = $hash{'bill'} - $old->get('bill'); + $new->set('bill', $new->get('bill') + $diff); + } else { + # absolute date + $new->set('bill', $hash{'bill'}); + } + } + $error = $new->replace; + $error .= ' (supplemental package '.$new->pkgnum.')' if $error; + last if $error; + } } </%init> diff --git a/httemplate/edit/process/part_pkg.cgi b/httemplate/edit/process/part_pkg.cgi index c388676df..2ac57f90b 100755 --- a/httemplate/edit/process/part_pkg.cgi +++ b/httemplate/edit/process/part_pkg.cgi @@ -185,6 +185,15 @@ my @process_m2m = ( grep /^svc_dst_pkgpart/, $cgi->param ], }, + { 'link_table' => 'part_pkg_link', + 'target_table' => 'part_pkg', + 'base_field' => 'src_pkgpart', + 'target_field' => 'dst_pkgpart', + 'hashref' => { 'link_type' => 'supp', 'hidden' => '' }, + 'params' => [ map $cgi->param($_), + grep /^supp_dst_pkgpart/, $cgi->param + ], + }, map { my $hidden = $_; { 'link_table' => 'part_pkg_link', |