1 <% include('elements/edit.html',
2 'name_singular' => 'prospect',
3 'table' => 'prospect_main',
4 'html_table_class'=> 'fsinnerbox',
5 'labels' => { 'prospectnum' => 'Prospect',
7 'refnum' => 'Advertising source',
8 'company' => 'Company',
9 'contactnum' => 'Contact',
10 'locationnum' => ' ',
11 'taxstatusnum'=> 'Tax status',
14 { 'field' => 'residential_commercial',
16 'options' => [ 'Residential', 'Commercial', ],
17 'onchange' => 'rescom_changed',
19 { 'field' => 'agentnum',
20 'type' => 'select-agent',
21 'empty_label' => 'Select agent',
24 { 'field' => 'refnum',
25 'type' => 'select-part_referral',
26 'empty_label' => 'Select advertising source',
29 { 'field' => 'company',
34 { 'field' => 'contactnum',
37 'prospectnum' => $prospectnum,
38 'm2m_method' => 'prospect_contact',
39 'm2m_dstcol' => 'contactnum',
40 'm2_label' => 'Contact',
41 'm2_error_callback' => $m2_error_callback,
42 'include_opt_callback' => sub { 'for_prospect' => 1 },
43 'js_spawn_test' => 'document.edit_topform.residential_commercial_Commercial.checked',
45 { 'field' => 'locationnum',
46 'type' => 'select-cust_location',
47 'empty_label' => 'No address',
48 'disable_empty' => $conf->exists('prospect_main-location_required'),
49 'alt_format' => $conf->exists('prospect_main-alt_address_format'),
50 'include_opt_callback' => sub {
51 'prospect_main' => shift
54 { 'field' => 'taxstatusnum',
55 'type' => 'select-tax_status',
60 'new_callback' => $new_callback,
61 'edit_callback' => $edit_callback,
62 'error_callback' => $error_callback,
64 'html_bottom' => $javascript,
65 'body_etc' => 'onLoad="rescom_changed()"',
70 my $curuser = $FS::CurrentUser::CurrentUser;
71 my $conf = new FS::Conf;
74 if ( $cgi->param('error') ) {
75 $cgi->param('prospectnum') =~ /^(\d*)$/ or die 'illegal prospectnum';
79 unless $curuser->access_right(($prospectnum ? 'Edit' : 'New'). ' prospect');
81 } elsif ( $cgi->keywords ) { #editing
83 my($query) = $cgi->keywords;
84 $query =~ /^(\d+)$/ or die 'no prospectnum';
88 unless $curuser->access_right('Edit prospect');
90 } else { #new prospect
95 unless $curuser->access_right('New prospect');
99 my $new_callback = sub {
100 my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
102 if ( $cgi->param('session') =~ /^(\w+)$/ ) {
105 #add a link to the image.cgi for this card
106 $opt_hashref->{'html_bottom'} .=
107 qq(<BR><IMG SRC="${p}view/image.cgi?type=png;prefname=bizcard$session" ).
108 ' WIDTH=604 HEIGHT=328><BR>';
110 #fill in the incoming params: name, address1/address2, city_state_zip
111 foreach my $param ( grep /^sel\d+$/, $cgi->param ) {
112 $param =~ /^sel(\d+)$/ or die 'again, wtf (daily)';
114 my $field = $cgi->param($param);
115 my $value = $cgi->param("val$num");
116 $cgi->param($field => $value);
119 if ( $cgi->param('company') ) {
120 $prospect_main->company( $cgi->param('company') );
123 if ( $cgi->param('name') =~ /^(.*\S+)\s+(\w+)\s*$/ ) {
124 $cgi->param('contactnum0_first' => $1);
125 $cgi->param('contactnum0_last' => $2);
128 if ( grep $cgi->param($_), qw( address1 address2 city_state_zip ) ) {
129 $cgi->param('locationnum', -1);
130 if ( $cgi->param('city_state_zip') =~ /^(\s*)([\w\s]+)[\., ]+(\w{2})[, ]+(\d{5}(-\d{4})?)/ ) {
131 $cgi->param('city' => $2);
132 $cgi->param('state' => $3);
133 $cgi->param('zip' => $4);
139 #config to default to commercial and/or disable residential when someone needs
140 $prospect_main->set('residential_commercial', 'Residential');
144 my $edit_callback = sub {
145 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
146 my( $cgi, $prospect_main ) = @_;
148 qsearch('cust_location', { 'prospectnum' => $prospect_main->prospectnum } );
149 die 'multiple locations for prospect '. $prospect_main->prospectnum
150 if scalar(@cust_location) > 1;
151 $prospect_main->set('locationnum', $cust_location[0]->locationnum)
152 if scalar(@cust_location);
153 #warn 'prospect_main.locationnum '.$prospect_main->get('locationnum');
155 $prospect_main->set('residential_commercial',
156 length($prospect_main->company)
162 my $error_callback = sub {
163 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
164 my( $cgi, $prospect_main ) = @_;
165 $cgi->param('locationnum') =~ /^(\-?\d*)$/
166 or die 'illegal locationnum '. $cgi->param('locationnum');
167 my $locationnum = $1;
168 $prospect_main->set('locationnum', $locationnum);
170 $prospect_main->set('residential_commercial',
171 ($cgi->param('residential_commercial') eq 'Commercial')
178 my $m2_error_callback = sub {
179 my($cgi, $object) = @_;
181 #process_o2m fields in process/prospect_main.html
182 my @fields = qw( first last title comment );
183 my @gfields = ( '', map "_$_", @fields );
186 if ( /^contactnum(\d+)$/ ) {
188 if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
189 my $x = new FS::contact {
190 'contactnum' => scalar($cgi->param("contactnum$num")),
191 map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
204 #my @agentnums = $FS::CurrentUser::CurrentUser->agentnums;
207 <SCRIPT TYPE="text/javascript">
208 function rescom_changed() {
210 var f = document.edit_topform;
211 if ( f.residential_commercial_Residential.checked ) {
212 $('#company_label').slideUp();
213 $('#company_input0').slideUp();
214 } else if ( f.residential_commercial_Commercial.checked ) {
215 $('#company_label').slideDown();
216 $('#company_input0').slideDown();