hide start date on package order for specific package definitions, RT#13783
[freeside.git] / httemplate / elements / tr-select-cust-part_pkg.html
1 %if ( scalar(@pkg_class) > 1 && ! $conf->exists('disable-cust-pkg_class') ) {
2
3   <% include('/elements/xmlhttp.html',
4                 'url'  => $p.'misc/cust-part_pkg.cgi',
5                 'subs' => [ 'get_part_pkg' ],
6             )
7   %>
8
9   <SCRIPT TYPE="text/javascript">
10
11     function part_pkg_opt(what, value, text, can_discount, can_start_date) {
12       var optionName = new Option(text, value, false, false);
13       optionName.setAttribute('data-can_discount',   can_discount);
14       optionName.setAttribute('data-can_start_date', can_start_date);
15       var length = what.length;
16       what.options[length] = optionName;
17     }
18
19     function classnum_changed(what) {
20
21       what.form.pkgpart.disabled = 'disabled'; //disable part_pkg dropdown
22       var submitButton = what.form.submitButton; // || what.form.submit;
23       if ( submitButton ) {
24         submitButton.disabled = true; //disable the submit button
25       }
26       var discountnum = what.form.discountnum;
27       if ( discountnum ) {
28         discountnum.disabled = true; //disable discount dropdown
29       }
30
31       classnum = what.options[what.selectedIndex].value;
32
33       function update_part_pkg(part_pkg) {
34
35         // blank the current packages
36         for ( var i = what.form.pkgpart.length; i>= 0; i-- )
37           what.form.pkgpart.options[i] = null;
38
39         // add the new packages
40         opt(what.form.pkgpart, '', 'Select package');
41         var packagesArray = eval('(' + part_pkg + ')' );
42         for ( var s = 0; s < packagesArray.length; s=s+4 ) {
43           var packagesLabel  = packagesArray[s+1];
44           var can_discount   = packagesArray[s+2];
45           var can_start_date = packagesArray[s+3];
46           part_pkg_opt(
47             what.form.pkgpart, packagesArray[s], packagesLabel, can_discount, can_start_date
48           );
49         }
50
51         what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown
52
53       }
54
55       get_part_pkg( <% $cust_main->custnum %>, classnum, update_part_pkg );
56     
57     }
58
59   </SCRIPT>
60
61   <TR>
62     <TH ALIGN="right">Package Class</TH>
63     <TD COLSPAN=7>
64       <% include('/elements/select-cust-pkg_class.html',
65                    'curr_value' => $opt{'classnum'},
66                    'pkg_class'  => \@pkg_class,
67                    'onchange'   => 'classnum_changed',
68                 )
69       %>
70     </TD>
71   </TR>
72
73 %}
74
75 <TR>
76   <TH ALIGN="right">Package</TH>
77   <TD COLSPAN=7>
78     <& /elements/select-cust-part_pkg.html,
79                  'curr_value' => $opt{'curr_value'}, #$pkgpart
80                  'classnum'   => $opt{'classnum'},
81                  'cust_main'  => $opt{'cust_main'},  #$cust_main
82                  'onchange'   => 'pkg_changed',
83     &>
84   </TD>
85 </TR>
86
87 <%init>
88
89 my $conf = new FS::Conf;
90
91 my %opt = @_;
92
93 my $pre_label = $opt{'pre_label'} || '';
94 $pre_label .= ' ' if length($pre_label) && $pre_label =~ /\S$/;
95
96 my $cust_main = $opt{'cust_main'}
97   or die "cust_main not specified";
98
99 #my @pkg_class = sort { $a->classname cmp $b->classname }
100 #                     qsearch( 'pkg_class', { 'disabled' => '' } );
101
102 #"normal" part_pkg agent virtualization (agentnum or type)
103 my @part_pkg = qsearch({
104   'select'    => 'DISTINCT classnum',
105   'table'     => 'part_pkg',
106   'hashref'   => { 'disabled' => '' },
107   'extra_sql' =>
108     ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ).
109     ' AND '. FS::part_pkg->agent_pkgs_sql( $opt{'cust_main'}->agent ),
110 });
111
112 my @pkg_class =
113   sort { $a->classname cmp $b->classname } #should get a sort order in config
114   map  { $_->pkg_class || new FS::pkg_class { 'classnum'  => '',
115                                               'classname' => '(none)' }
116        }
117   @part_pkg;
118
119 </%init>