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' => $m2_error_callback,
27 'o2m_table' => 'contact',
28 'm2_label' => 'Contact',
29 'm2_error_callback' => $m2_error_callback,
32 { 'field' => 'locationnum',
33 'type' => 'select-cust_location',
34 'empty_label' => 'No address',
37 'edit_callback' => $edit_callback,
38 'error_callbacck' => $error_callback,
44 my $curuser = $FS::CurrentUser::CurrentUser;
47 if ( $cgi->param('error') ) {
48 $prospectnum = scalar($cgi->param('prospectnum'));
51 unless $curuser->access_right(($prospectnum ? 'Edit' : 'New'). ' prospect');
53 } elsif ( $cgi->keywords ) { #editing
56 unless $curuser->access_right('Edit prospect');
58 } else { #new prospect
61 unless $curuser->access_right('New prospect');
65 my $edit_callback = sub {
66 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
67 my( $cgi, $prospect_main ) = @_;
69 qsearch('cust_location', { 'prospectnum' => $prospect_main->prospectnum } );
70 die 'multiple locations for prospect '. $prospect_main->prospectnum
71 if scalar(@cust_location) > 1;
72 $prospect_main->set('locationnum', $cust_location[0]->locationnum)
73 if scalar(@cust_location);
74 #warn 'prospect_main.locationnum '.$prospect_main->get('locationnum');
77 my $error_callback = sub {
78 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
79 my( $cgi, $prospect_main ) = @_;
80 $cgi->param('locationnum') =~ /^(\-?\d*)$/
81 or die 'illegal locationnum '. $cgi->param('locationnum');
83 $prospect_main->set('locationnum', $locationnum);
86 my $m2_error_callback = sub {
87 my($cgi, $object) = @_;
89 #process_o2m fields in process/prospect_main.html
90 my @fields = qw( first last title comment );
91 my @gfields = ( '', map "_$_", @fields );
94 if ( /^contactnum(\d+)$/ ) {
96 if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
97 my $x = new FS::contact {
98 'contactnum' => $cgi->param("contactnum$num"),
99 map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
112 #my @agentnums = $FS::CurrentUser::CurrentUser->agentnums;