diff options
author | ivan <ivan> | 2009-12-31 02:20:33 +0000 |
---|---|---|
committer | ivan <ivan> | 2009-12-31 02:20:33 +0000 |
commit | 2e928dafa3cf6383ea9e97f48af61af05e5a292a (patch) | |
tree | 107c9908948a9c5463ffcb80add9323245d6fa54 | |
parent | 0d2d8c0b11b715fa7ba1d889e04637194d97e275 (diff) |
prospecting: proper contact error handling when you add a prospect
-rw-r--r-- | httemplate/edit/elements/edit.html | 20 | ||||
-rw-r--r-- | httemplate/edit/process/elements/process.html | 25 | ||||
-rw-r--r-- | httemplate/edit/prospect_main.html | 42 | ||||
-rw-r--r-- | httemplate/elements/contact.html | 56 | ||||
-rw-r--r-- | httemplate/elements/menu.html | 7 |
5 files changed, 96 insertions, 54 deletions
diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 4935ddc1a..43b7afe11 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -40,14 +40,14 @@ Example: 'disabled' => 0, 'onchange' => 'javascript_function', - #m2 stuff only tested w/selectlayers so far - #might work w/select too, dunno others 'm2name_table' => 'table_name', 'm2name_namecol' => 'name_column', #OR# 'm2m_method' => #'m2m_srccol' => #opt, if not the same as this table 'm2m_dstcol' => #required for now, eventuaully opt, if not the same as target table + #OR# + 'o2m_table' => 'm2_label' => 'Label', # 'm2_new_default' => \@table_name_objects, #default @@ -235,6 +235,7 @@ Example: % $layer_values = &{ $f->{'layer_values_callback'} }( $cgi, $object ) % if $f->{'layer_values_callback'} % && ! $f->{'m2name_table'} +% && ! $f->{'o2m_table'} % && ! $f->{'m2m_method'}; % % warn "layer values: ". Dumper($layer_values) @@ -356,12 +357,15 @@ Example: % % my $fieldnum = ''; % my $curr_value = ''; -% if ( $f->{'m2name_table'} || $f->{'m2m_method'} ) { #XXX test this for all -% #types of fields +% if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) { +% % my($table, $col); % if ( $f->{'m2name_table'} ) { % $table = $f->{'m2name_table'}; % $col = $f->{'m2name_namecol'}; +% } elsif ( $f->{'o2m_table'} ) { +% $table = $f->{'o2m_table'}; +% $col = dbdef->table($f->{'o2m_table'})->primary_key; % } elsif ( $f->{'m2m_method'} ) { % $table = $f->{'m2m_method'}; % $col = $f->{'m2m_dstcol'}; @@ -374,8 +378,8 @@ Example: % @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object ); % } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone' % @existing = $object->$table(); -% warn scalar(@existing). " from $object->$table: ". join('/', @existing) -% if $opt{'debug'}; +% warn scalar(@existing). " from $object->$table: ". join('/', @existing) +% if $opt{'debug'}; % } elsif ( $f->{'m2_new_default'} ) { # && $mode eq 'new' % @existing = @{ $f->{'m2_new_default'} }; % } @@ -459,7 +463,7 @@ Example: % ( $fieldnum ? ('cell_style' => 'border-top:1px solid black') : () ), % ); % -% if ( $f->{'m2name_table'} || $f->{'m2m_method'} ) { +% if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) { % $include[0] =~ s(^/elements/tr-)(/elements/); % my @label = @include; % $label[0] = '/elements/tr-td-label.html'; @@ -492,7 +496,7 @@ Example: <% include( @include ) %> % } -% if ( $f->{'m2name_table'} || $f->{'m2m_method'} ) { +% if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) { <SCRIPT TYPE="text/javascript"> diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html index e24f3f681..87cadb774 100644 --- a/httemplate/edit/process/elements/process.html +++ b/httemplate/edit/process/elements/process.html @@ -190,11 +190,26 @@ if ($old && exists($opt{'copy_on_empty'})) { } if ( $opt{'agent_virt'} ) { - die "illegal agentnum" - unless $curuser->agentnums_href->{$new->agentnum} - or $opt{'agent_null_right'} - && ! $new->agentnum - && $curuser->access_right($opt{'agent_null_right'}); + + if ( ! $new->agentnum + && ( ! $opt{'agent_null_right'} + || ! $curuser->access_right($opt{'agent_null_right'}) + ) + ) + { + + $error ||= 'Select an agent'; + + } else { + + die "illegal agentnum" + unless $curuser->agentnums_href->{$new->agentnum} + or $opt{'agent_null_right'} + && ! $new->agentnum + && $curuser->access_right($opt{'agent_null_right'}); + + } + } $error ||= $new->check; diff --git a/httemplate/edit/prospect_main.html b/httemplate/edit/prospect_main.html index c4123a078..8ae76a9a1 100644 --- a/httemplate/edit/prospect_main.html +++ b/httemplate/edit/prospect_main.html @@ -18,11 +18,16 @@ { 'field' => 'contactnum', 'type' => 'contact', 'colspan' => 6, - #actually o2m, but this seems to be working for edit so far - 'm2name_table' => 'contact', - 'm2name_namecol' => 'contactnum', - 'm2_label' => 'Contact', - 'm2_error_callback' => sub { my($cgi, $object) = @_; (); }, #XXX + ##actually o2m, but this seems to be working for edit so far + #'m2name_table' => 'contact', + #'m2name_namecol' => 'contactnum', + #'m2_label' => 'Contact', + #'m2_error_callback' => $m2_error_callback, + + 'o2m_table' => 'contact', + 'm2_label' => 'Contact', + 'm2_error_callback' => $m2_error_callback, + }, { 'field' => 'locationnum', 'type' => 'select-cust_location', @@ -78,6 +83,33 @@ my $error_callback = sub { $prospect_main->set('locationnum', $locationnum); }; +my $m2_error_callback = sub { + my($cgi, $object) = @_; + + #process_o2m fields in process/prospect_main.html + my @fields = qw( first last title comment ); + my @gfields = ( '', map "_$_", @fields ); + + map { + if ( /^contactnum(\d+)$/ ) { + my $num = $1; + if ( grep $cgi->param("contactnum$num$_"), @gfields ) { + my $x = new FS::contact { + 'contactnum' => $cgi->param("contactnum$num"), + map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields, + }; + use Data::Dumper; warn Dumper $x; + $x; + } else { + (); + } + } else { + (); + } + } + $cgi->param; +}; + my @agentnums = $FS::CurrentUser::CurrentUser->agentnums; </%init> diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html index 38703bfef..2023a6cfe 100644 --- a/httemplate/elements/contact.html +++ b/httemplate/elements/contact.html @@ -4,42 +4,18 @@ <TABLE> <TR> - <TD> - <INPUT TYPE = "text" - NAME = "<%$name%>_first" - ID = "<%$id%>_id" - VALUE = "<% $contact->first |h %>" - <% $onchange %> - ><BR> - <FONT SIZE="-2">First name</FONT> - </TD> - <TD> - <INPUT TYPE = "text" - NAME = "<%$name%>_last" - ID = "<%$id%>_id" - VALUE = "<% $contact->get('last') |h %>" - <% $onchange %> - ><BR> - <FONT SIZE="-2">Last name</FONT> - </TD> - <TD> - <INPUT TYPE = "text" - NAME = "<%$name%>_title" - ID = "<%$id%>_id" - VALUE = "<% $contact->title |h %>" - <% $onchange %> - ><BR> - <FONT SIZE="-2">Title/Position</FONT> - </TD> - <TD> - <INPUT TYPE = "text" - NAME = "<%$name%>_comment" - ID = "<%$id%>_id" - VALUE = "<% $contact->comment |h %>" - <% $onchange %> - ><BR> - <FONT SIZE="-2">Comment</FONT> - </TD> +% foreach my $field ( @fields ) { + <TD> + <INPUT TYPE = "text" + NAME = "<%$name%>_<%$field%>" + ID = "<%$id%>_<%$field%>" + VALUE = "<% scalar($cgi->param($name."_$field")) + || $contact->get($field) |h %>" + <% $onchange %> + ><BR> + <FONT SIZE="-2"><% $label{$field} %></FONT> + </TD> +% } </TR> </TABLE> @@ -69,4 +45,12 @@ if ( $curr_value ) { $contact = new FS::contact {}; } +tie my %label, 'Tie::IxHash', + 'first' => 'First name', + 'last' => 'Last name', + 'title' => 'Title/Position', + 'comment' => 'Comment', +; +my @fields = keys %label; + </%init> diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index 167559d0b..573741e21 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -60,6 +60,11 @@ my $curuser = $FS::CurrentUser::CurrentUser; #XXX Active tickets not assigned to a customer +tie my %report_prospects, 'Tie::IxHash', + 'List prospects' => [ $fsurl. 'search/prospect_main.html', '' ], + 'Advanced prospect reports' => [ $fsurl. 'search/report_prospect_main.html', '' ], +; + tie my %report_customers_lists, 'Tie::IxHash', 'by customer number' => [ $fsurl. 'search/cust_main.cgi?browse=custnum', '' ], 'by last name' => [ $fsurl. 'search/cust_main.cgi?browse=last', '' ], @@ -251,6 +256,8 @@ if($curuser->access_right('Financial reports')) { } # else $report_financial contains nothing. tie my %report_menu, 'Tie::IxHash'; +$report_menu{'Prospects'} = [ \%report_prospects, 'Prospect reports' ] + if $curuser->access_right('List prospects'); $report_menu{'Customers'} = [ \%report_customers, 'Customer reports' ] if $curuser->access_right('List customers'); $report_menu{'Invoices'} = [ \%report_invoices, 'Invoice reports' ] |