prospecting: proper contact error handling when you add a prospect
authorivan <ivan>
Thu, 31 Dec 2009 02:20:33 +0000 (02:20 +0000)
committerivan <ivan>
Thu, 31 Dec 2009 02:20:33 +0000 (02:20 +0000)
httemplate/edit/elements/edit.html
httemplate/edit/process/elements/process.html
httemplate/edit/prospect_main.html
httemplate/elements/contact.html
httemplate/elements/menu.html

index 4935ddc..43b7afe 100644 (file)
@@ -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">
 
index e24f3f6..87cadb7 100644 (file)
@@ -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;
index c4123a0..8ae76a9 100644 (file)
        { '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>
index 38703bf..2023a6c 100644 (file)
@@ -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>
index 167559d..573741e 100644 (file)
@@ -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'   ]