don't allow a start date for packages definitions with prorate_defer_bill, RT#25650
[freeside.git] / httemplate / misc / cust-part_pkg.cgi
1 <% objToJson( \@return ) %>
2 <%init>
3
4 my( $custnum, $classnum ) = $cgi->param('arg');
5
6 #XXX i guess i should be agent-virtualized.  cause "packages a customer can
7 #order" is such a huge deal
8 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
9
10 my %hash = ( 'disabled' => '' );
11 if ( $classnum > 0 ) {
12   $hash{'classnum'} = $classnum;
13 } elsif ( $classnum eq '' || $classnum == 0 ) {
14   $hash{'classnum'} = '';
15 } #else -1, all classes, so don't set classnum
16
17 my @part_pkg = qsearch({
18   'table'     => 'part_pkg',
19   'hashref'   => \%hash,
20   'extra_sql' =>
21     ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ).
22     ' AND '. FS::part_pkg->agent_pkgs_sql( $cust_main->agent ),
23   'order_by'  => 'ORDER BY pkg',
24 });
25
26 my $conf = new FS::Conf;
27
28 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
29
30 my $default_start_date = $conf->exists('order_pkg-no_start_date')
31                            ? ''
32                            : $cust_main->next_bill_date;
33
34 #num_billing_pkgs may be slightly better (will allow you to fill in a start
35 # date in the weird edge case where you're using sync_next_bill and
36 # prorate_defer_bill in flat.pm and there's one-time charges hanging around
37 # for this customer but no active ones)
38 #but we don't have an easy method for that, and definitely don't want to pull
39 # all package objects
40 my $num_ncancelled_pkgs = $cust_main ? $cust_main->num_ncancelled_pkgs : 0;
41
42 my @return = map  {
43                     my $start_date = $_->delay_start_date
44                                    || $default_start_date;
45                     $start_date = time2str($date_format, $start_date)
46                       if $start_date;
47                     ( $_->pkgpart,
48                       $_->pkg_comment,
49                       $_->can_discount,
50                       $_->can_start_date(
51                         num_ncancelled_pkgs => $num_ncancelled_pkgs,
52                       ),
53                       $start_date,
54                     )
55                   }
56                   #sort { $a->pkg_comment cmp $b->pkg_comment }
57                   @part_pkg;
58
59 </%init>