5 <& /elements/tr-select-sales.html',
7 #recommended to keep things "sticky" on errors
8 'curr_value' => $curr_value,
14 'label' => 'Sales Person',
15 'empty_label' => 'Select sales person', #override default
16 'disable_empty' => 0, #on byd efault, pass 0 to disable
17 'field' => 'salesnum', #HTML element name and ID
22 % if ( scalar(@sales) == 0 || $opt{'fixed'} ) {
24 <INPUT TYPE = "hidden"
27 VALUE = "<% $salesnum %>"
30 % if ( scalar(@sales) > 0 ) {
33 <TH ALIGN="right"><% $opt{'label'} || emt('Sales Person') %></TH>
35 <TD ALIGN="right"><% $opt{'label'} || emt('Sales Person') %></TD>
37 <TD BGCOLOR="#dddddd" <% $colspan %>>
38 % my $sales = qsearchs('sales', { 'salesnum' => $salesnum });
39 <% $sales ? $sales->salesperson : '(none)' |h %>
43 % } else { # YUCK. empty row so we don't throw g_row in edit.html off :/
52 <TH ALIGN="right"><% $opt{'label'} || emt('Sales Person') %></TH>
54 <TD ALIGN="right"><% $opt{'label'} || emt('Sales Person') %></TD>
57 <& /elements/select-sales.html,
58 'curr_value' => $salesnum,
67 <& /elements/xmlhttp.html,
68 'url' => $p.'misc/sales.cgi',
69 'subs' => [ 'get_sales' ],
71 <SCRIPT TYPE="text/javascript">
73 % # false laziness w/ elements/tr-select-cust-part_pkg.html
75 function <% $field %>_opt(what, value, text) {
76 var optionName = new Option(text, value, false, false);
77 var length = what.length;
78 what.options[length] = optionName;
81 function <% $field %>_agentnum_changed(what) {
82 what.form.<% $field %>.disabled = 'disabled'; //disable sales dropdown
84 agentnum = what.options[what.selectedIndex].value;
86 function update_<% $field %>(sales) {
88 if ( what.form.<% $field %>.type == 'hidden' ) {
89 what.form.<% $field %>.disabled = ''; //re-enable sales dropdown
93 // save the current salesnum
94 var salesnum = what.form.<% $field %>.value;
96 // blank the current sales people
97 for ( var i = what.form.<% $field %>.length; i>= 0; i-- )
98 what.form.<% $field %>.options[i] = null;
100 // add the new sales people
102 % my @pre_options = $opt{pre_options} ? @{ $opt{pre_options} } : ();
103 % while ( @pre_options ) {
104 % my $pre_opt = shift(@pre_options);
105 % my $pre_label = shift(@pre_options);
106 % #my $selected = ( $salesnum eq $pre_opt );
107 <% $field %>_opt( what.form.<% $field %>,
108 <% $pre_opt |js_string %>,
109 <% $pre_label |js_string %>
113 % unless ( $opt{'disable_empty'} ) {
114 <% $field %>_opt( what.form.<% $field %>,
116 <% $opt{'empty_label'} || '(none)' |js_string %>
120 var salesArray = eval('(' + sales + ')' );
121 for ( var s = 0; s < salesArray.length; s=s+2 ) {
122 //surely this should be some kind of JSON structure
123 var salesLabel = salesArray[s+1];
124 <% $field %>_opt( what.form.<% $field %>, salesArray[s], salesLabel );
127 what.form.<% $field %>.disabled = ''; //re-enable sales dropdown
129 //restore salesnum if possible
130 what.form.<% $field %>.value = salesnum;
139 <&| /elements/onload.js &>
140 <% $field %>_agentnum_changed(document.getElementById('agentnum'));
147 my $curuser = $FS::CurrentUser::CurrentUser;
150 my $salesnum = $opt{'curr_value'} || $opt{'value'};
151 my $field = $opt{'element_name'} || $opt{'field'} || 'salesnum';
152 my $id = $opt{'id'} || $opt{'field'} || 'salesnum';
154 my @sales = qsearch({ 'table' => 'sales',
155 'hashref' => { 'disabled' => '' },
156 'extra_sql' => ' AND '. $curuser->agentnums_sql,
157 'order_by' => 'ORDER BY salesperson',
160 my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : '';