mark advertising source as a required field
[freeside.git] / httemplate / edit / cust_main / top_misc.html
1 <TABLE CLASS="fsinnerbox">
2
3 <TR>
4   <TD ALIGN="right">Residential</TD>
5   <TD><INPUT TYPE     = "radio"
6              NAME     = "residential_commercial"
7              ID       = "residential_commercial_Residential"
8              VALUE    = "Residential"
9              onChange = "rescom_changed(this)"
10        <% $cust_main->residential_commercial eq 'Commercial' ? '' : 'CHECKED' %>
11   ></TD>
12 </TR>
13 <TR>
14   <TD ALIGN="right">Commercial</TD>
15   <TD><INPUT TYPE     = "radio"
16              NAME     = "residential_commercial"
17              ID       = "residential_commercial_Commercial"
18              VALUE    = "Commercial"
19              onChange = "rescom_changed(this)"
20        <% $cust_main->residential_commercial eq 'Commercial' ? 'CHECKED' : '' %>
21   ></TD>
22 </TR>
23
24 <SCRIPT TYPE="text/javascript">
25
26   function rescom_changed(what) {
27     if ( what.checked == (what.value == 'Commercial' ) ) {
28       document.getElementById('company_row').style.display = '';
29       document.getElementById('contacts_div').style.display = '';
30     } else {
31       if ( document.getElementById('company').value.length == 0 ) {
32         document.getElementById('company_row').style.display = 'none';
33       }
34       document.getElementById('contacts_div').style.display = 'none';
35     }
36   }
37
38
39   var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>;
40   var ship_fields = ['address1', 'city', 'state', 'zip', 'country', 
41     'latitude', 'longitude', 'district'];
42
43   function agent_changed(what) {
44     var agentnum = what.value;
45
46 %   # unlock/lock service location
47
48     var f = what.form;
49     if ( ship_locked_agents[agentnum] ) {
50 %     # For this agent, the service location (except address2)
51 %     # should be locked to the agent's location.
52 %     # Set the ship_ fields to those values (just for display) and
53 %     # then disable them.
54       for(var x in ship_locked_agents[agentnum]) {
55         f['ship_'+x].value = ship_locked_agents[agentnum][x];
56         f['ship_'+x].disabled = true;
57       }
58       f['same'].checked = false;
59       f['same'].disabled = true;
60     } else {
61 %     # Unlock the ship_ location fields.  If they were previously
62 %     # disabled, then they contain some agent's address, which is 
63 %     # no longer meaningful.  So set them back to the customer's 
64 %     # current location.
65       for(var i=0; i<ship_fields.length; i++) {
66         x = ship_fields[i];
67         if ( f['ship_'+x].disabled )  {
68           f['ship_'+x].value  = f['old_ship_'+x].value;
69         }
70         f['ship_'+x].disabled = false;
71       }
72       f['same'].disabled = false;
73     }
74     samechanged(f['same']);
75
76 %   # update sales dropdown
77     salesnum_agentnum_changed(what);
78
79   }
80
81   <&| /elements/onload.js &>
82   agent_changed(document.getElementById('agentnum'))
83   </&>
84  
85 </SCRIPT>
86
87 % foreach my $field ($cust_main->virtual_fields) {
88     <% $cust_main->pvf($field)->widget('HTML', 'edit',$cust_main->getfield($field)) %>
89 % }
90
91 %# tags
92 <& /elements/tr-select-cust_tag.html,
93              'custnum' => $custnum,
94              'cgi'     => $cgi,
95 &>
96
97 %# agent
98 % if ( $cgi->param('lock_agentnum') =~ /^(\d+)$/ && $curuser->agentnum($1) ) {
99 %
100 %   my $agentnum = $1;
101 %   $cust_main->agentnum($agentnum);
102
103     <INPUT TYPE="hidden" NAME="lock_agentnum" VALUE="<% $agentnum %>">
104     <INPUT TYPE="hidden" NAME="agentnum"      ID="agentnum" 
105       VALUE="<% $agentnum %>">
106     <TR>
107       <TD ALIGN="right"><% mt('Agent') |h %></TD>
108       <TD CLASS="fsdisabled"><% $cust_main->agent->agent |h %></TD>
109     </TR>
110
111 % } else {
112
113   <& /elements/tr-select-agent.html, 
114                 'curr_value'    => $cust_main->agentnum,
115                 'label'         => "<B>${r}".emt('Agent')."</B>",
116                 'empty_label'   => emt('Select agent'),
117                 'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
118                 'viewall_right' => emt('None'), 
119                 'onchange'      => 'agent_changed(this)',
120   &>
121
122 % }
123
124 %# agent_custid
125 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
126
127     <TR>
128       <TD ALIGN="right"><% mt('Customer identifier') |h %></TD>
129       <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
130     </TR>
131
132 % } else {
133
134     <INPUT TYPE="hidden" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>">
135
136 % }
137
138 %# class
139 <& /elements/tr-select-cust_class.html,
140              'curr_value'  => $cust_main->classnum,
141              'label'       => emt("Class"),
142 &>
143
144 %#sales person
145 <& /elements/tr-select-sales.html,
146      'curr_value' => $cust_main->salesnum,
147 &>
148
149 %# referral (advertising source)
150 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
151 %if ( $custnum && ! $conf->exists('editreferrals') ) {
152
153   <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
154
155 % } else { 
156
157   <& /elements/tr-select-part_referral.html,
158                 'curr_value' => $refnum,
159                 'label'      => "<B>${r}".emt('Advertising source')."</B>"
160   &>
161 % } 
162
163
164 %# referring customer
165 %my $referring_cust_main = '';
166 %if ( $cust_main->referral_custnum
167 %     and $referring_cust_main =
168 %           qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
169 %     and ! $curuser->access_right('Edit referring customer')
170 %) {
171
172   <TR>
173     <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
174     <TD>
175       <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name |h %></A>
176     </TD>
177   </TR>
178   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
179
180 % } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
181
182   <TR>
183     <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
184     <TD>
185       <& /elements/search-cust_main.html,
186                     'field_name' => 'referral_custnum',
187                     'curr_value' => $cust_main->referral_custnum,
188       &>
189     </TD>
190   </TR>
191
192 % } else { 
193   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
194 % } 
195
196 %# signup date
197 % if ( $conf->exists('cust_main-edit_signupdate') ) {
198     <& /elements/tr-input-date-field.html, {
199                   'name'        => 'signupdate',
200                   'value'       => $cust_main->signupdate,
201                   'label'       => emt('Signup date'),
202                   'format'      => ( $conf->config('date_format') || "%m/%d/%Y" ),
203               }
204     &>
205 % }
206
207 % # permission to edit ticket subjects
208 % if ( $conf->exists('ticket_system-selfservice_edit_subject') ) {
209   <TR>
210     <TD ALIGN="right">
211       <INPUT TYPE="checkbox" NAME="edit_subject" VALUE="Y" <% 
212         $cust_main->edit_subject ? 'CHECKED' : '' %>></TD>
213     <TD ALIGN="left"><% mt('Can edit ticket subjects') |h %></TD>
214   </TR>
215 % } else {
216   <INPUT TYPE="hidden" NAME="edit_subject" VALUE="<% $cust_main->edit_subject %>">
217 % }
218
219 % # permission to edit
220 % if ( $conf->exists('cust_main-edit_calling_list_exempt') ) {
221   <TR>
222     <TD ALIGN="right">
223       <INPUT TYPE="checkbox" NAME="calling_list_exempt" VALUE="Y" <% 
224         $cust_main->calling_list_exempt ? 'CHECKED' : '' %>></TD>
225     <TD ALIGN="left"><% mt('Calling list exempt') |h %></TD>
226   </TR>
227 % } else {
228   <INPUT TYPE="hidden" NAME="calling_list_exempt" VALUE="<% $cust_main->calling_list_exempt %>">
229 % }
230
231 </TABLE>
232
233 <%init>
234
235 my( $cust_main, %opt ) = @_;
236
237 my $custnum = $opt{'custnum'};
238
239 if ( $cgi->param('error') ) {
240   $cust_main->set('residential_commercial',
241     ($cgi->param('residential_commercial') eq 'Commercial')
242       ? 'Commercial'
243       : 'Residential'
244   );
245 } elsif ( $custnum ) { #editing
246   $cust_main->set('residential_commercial',
247     length($cust_main->company)
248       ? 'Commercial'
249       : 'Residential'
250   );
251 } else { #new customer
252   #config to default to commercial and/or disable residential when someone needs
253   $cust_main->set('residential_commercial', 'Residential');
254 }
255
256 my $conf = new FS::Conf;
257
258 my $curuser = $FS::CurrentUser::CurrentUser;
259
260 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
261
262 # which agents lock the service address, if any
263 my %ship_locked_agents;
264 foreach (qsearch('agent',{})) {
265   my $agentnum = $_->agentnum;
266   next unless $conf->exists('agent-ship_address', $_->agentnum);
267   my $cust_main = $_->agent_cust_main or next;
268   my $agent_ship_location = $cust_main->ship_location;
269   $ship_locked_agents{$agentnum} = +{
270     map { $_ => $agent_ship_location->$_ }
271     qw(address1 city state zip country latitude longitude district)
272   };
273 }
274
275 </%init>