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 if ( what.type == 'hidden' ) {
85 agentnum = what.value;
87 agentnum = what.options[what.selectedIndex].value;
90 function update_<% $field %>(sales) {
92 if ( what.form.<% $field %>.type == 'hidden' ) {
93 what.form.<% $field %>.disabled = ''; //re-enable sales dropdown
97 // save the current salesnum
98 var salesnum = what.form.<% $field %>.value;
100 // blank the current sales people
101 for ( var i = what.form.<% $field %>.length; i>= 0; i-- )
102 what.form.<% $field %>.options[i] = null;
104 // add the new sales people
106 % my @pre_options = $opt{pre_options} ? @{ $opt{pre_options} } : ();
107 % while ( @pre_options ) {
108 % my $pre_opt = shift(@pre_options);
109 % my $pre_label = shift(@pre_options);
110 % #my $selected = ( $salesnum eq $pre_opt );
111 <% $field %>_opt( what.form.<% $field %>,
112 <% $pre_opt |js_string %>,
113 <% $pre_label |js_string %>
117 % unless ( $opt{'disable_empty'} ) {
118 <% $field %>_opt( what.form.<% $field %>,
120 <% $opt{'empty_label'} || '(none)' |js_string %>
124 var salesArray = eval('(' + sales + ')' );
125 for ( var s = 0; s < salesArray.length; s=s+2 ) {
126 //surely this should be some kind of JSON structure
127 var salesLabel = salesArray[s+1];
128 <% $field %>_opt( what.form.<% $field %>, salesArray[s], salesLabel );
131 what.form.<% $field %>.disabled = ''; //re-enable sales dropdown
133 //restore salesnum if possible
134 what.form.<% $field %>.value = salesnum;
143 <&| /elements/onload.js &>
144 <% $field %>_agentnum_changed(document.getElementById('agentnum'));
151 my $curuser = $FS::CurrentUser::CurrentUser;
154 my $salesnum = $opt{'curr_value'} || $opt{'value'};
155 my $field = $opt{'element_name'} || $opt{'field'} || 'salesnum';
156 my $id = $opt{'id'} || $opt{'field'} || 'salesnum';
158 my $hashref = { disabled => '' };
159 $hashref->{agentnum} = $opt{agentnum} if $opt{agentnum};
161 my @sales = qsearch({ 'table' => 'sales',
162 'hashref' => $hashref,
163 'extra_sql' => ' AND '. $curuser->agentnums_sql,
164 'order_by' => 'ORDER BY salesperson',
167 my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : '';