8b446b95d49e7883c1aa43ecaaebcf9b4fb7c8fa
[freeside.git] / httemplate / elements / select-cust-part_pkg.html
1 <%doc>
2
3 Example:
4
5   include( '/elements/select-cust-part_pkg.html',
6
7     #required
8     'cust_main'  => $cust_main, #or 'custnum' ? 
9              
10     #strongly recommended (you want your forms to be "sticky" on errors, right?)
11     'curr_value' => 'current_value',
12   
13     #opt
14     'part_pkg'   => \@records,
15
16     #select-table.html options
17   )
18
19 </%doc>
20
21 <% include( '/elements/select-table.html',
22               'table'          => 'part_pkg',
23               'name_col'       => 'pkg',
24               'empty_label'    => 'Select package',
25               'label_callback' => sub { $_[0]->pkgpart. ': '.
26                                         $_[0]->pkg.     ' - '.
27                                         $_[0]->comment;
28                                       },
29               %opt,
30           )
31 %>
32 <%init>
33
34 my( %opt ) = @_;
35
36 my $cust_main = $opt{'cust_main'}
37   or die "cust_main not specified";
38
39 $opt{'records'} = delete $opt{'part_pkg'}
40   if $opt{'part_pkg'};
41
42 my $extra_sql = $opt{'extra_sql'}.
43   ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
44   '             WHERE typenum = '. $cust_main->agent->typenum.
45   '             AND type_pkgs.pkgpart = part_pkg.pkgpart )';
46
47 $opt{'records'} ||= [ qsearch({ 
48                                 'table'     => 'part_pkg',
49                                 'hashref'   => { 'disabled' => '', },
50                                 'extra_sql' => "$extra_sql ORDER BY pkg",
51                                 #'extra_sql' => $extra_sql,
52                                 #'order_by'  => 'ORDER BY pkg',
53                              })
54                     ];
55
56 </%init>