1 <% include('elements/edit.html',
2 'name_singular' => 'prospect',
3 'table' => 'prospect_main',
4 'labels' => { 'prospectnum' => 'Prospect',
6 'company' => 'Company',
7 'contactnum' => 'Contact',
10 { 'field' => 'agentnum',
11 'type' => 'select-agent',
12 'empty_label' => 'Select agent',
14 { 'field' => 'company',
18 { 'field' => 'contactnum',
21 #actually o2m, but this seems to be working for edit so far
22 'm2name_table' => 'contact',
23 'm2name_namecol' => 'contactnum',
24 'm2_label' => 'Contact',
25 'm2_error_callback' => sub { my($cgi, $object) = @_; (); }, #XXX
27 { 'field' => 'locationnum',
28 'type' => 'select-cust_location',
29 'empty_label' => 'No address',
32 'edit_callback' => $edit_callback,
33 'error_callbacck' => $error_callback,
39 my $curuser = $FS::CurrentUser::CurrentUser;
42 if ( $cgi->param('error') ) {
43 $prospectnum = scalar($cgi->param('prospectnum'));
46 unless $curuser->access_right(($prospectnum ? 'Edit' : 'New'). ' prospect');
48 } elsif ( $cgi->keywords ) { #editing
51 unless $curuser->access_right('Edit prospect');
53 } else { #new prospect
56 unless $curuser->access_right('New prospect');
60 my $edit_callback = sub {
61 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
62 my( $cgi, $prospect_main ) = @_;
64 qsearch('cust_location', { 'prospectnum' => $prospect_main->prospectnum } );
65 die 'multiple locations for prospect '. $prospect_main->prospectnum
66 if scalar(@cust_location) > 1;
67 $prospect_main->set('locationnum', $cust_location[0]->locationnum)
68 if scalar(@cust_location);
69 #warn 'prospect_main.locationnum '.$prospect_main->get('locationnum');
72 my $error_callback = sub {
73 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
74 my( $cgi, $prospect_main ) = @_;
75 $cgi->param('locationnum') =~ /^(\-?\d*)$/
76 or die 'illegal locationnum '. $cgi->param('locationnum');
78 $prospect_main->set('locationnum', $locationnum);
81 my @agentnums = $FS::CurrentUser::CurrentUser->agentnums;