more RT integration
authorivan <ivan>
Thu, 9 Dec 2004 09:21:43 +0000 (09:21 +0000)
committerivan <ivan>
Thu, 9 Dec 2004 09:21:43 +0000 (09:21 +0000)
FS/FS/TicketSystem/RT_External.pm
FS/FS/TicketSystem/RT_Internal.pm
httemplate/search/cust_main.cgi
httemplate/view/cust_main.cgi
httemplate/view/cust_main/billing.html [new file with mode: 0644]
httemplate/view/cust_main/contacts.html [new file with mode: 0644]
httemplate/view/cust_main/misc.html [new file with mode: 0644]
httemplate/view/cust_main/tickets.html [new file with mode: 0644]

index 3bb1991..7a39c91 100644 (file)
@@ -25,42 +25,93 @@ sub num_customer_tickets {
 
   #$dbh ||= create one from some config options
 
+  my( $from_sql, @param) = $self->_from_customer( $custnum, $priority );
+
+  my $sql = "select count(*) $from_sql";
+  my $sth = $dbh->prepare($sql) or die $dbh->errstr. " preparing $sql";
+  $sth->execute(@param)         or die $sth->errstr. " executing $sql";
+
+  $sth->fetchrow_arrayref->[0];
+
+}
+
+sub customer_tickets {
+  my( $self, $custnum, $limit, $priority, $dbh ) = @_;
+  $limit ||= 0;
+
+  #$dbh ||= create one from some config options
+
+  my( $from_sql, @param) = $self->_from_customer( $custnum, $priority );
+  my $sql = "select * $from_sql order by priority desc limit $limit";
+  my $sth = $dbh->prepare($sql) or die $dbh->errstr. "preparing $sql";
+  $sth->execute(@param)         or die $sth->errstr. "executing $sql";
+
+  #munge column names???  #httemplate/view/cust_main/tickets.html has column
+  #names that might not make sense now...
+  $sth->fetchall_arrayref({});
+
+}
+
+sub _from_customer {
+  my( $self, $custnum, $priority ) = @_;
+
   my @param = ();
-  my $priority_sql = '';
+  my $join = '';
+  my $where = '';
   if ( defined($priority) ) {
+
+    my $queue_sql = " customfields.queue = ( select id from queues
+                                              where queues.name = ? )
+                      or ( ? = '' and customfields.queue = 0 )";
+
     if ( length($priority) ) {
-      my $queue_sql = " queue = ( select id from queues where queues.name = ? )
-                        or ( ? = '' and queue = 0 )";
-      $priority_sql = "
-        and ? = ( select content from TicketCustomFieldValues
-                   where ticket = tickets.id
-                     and customfield = ( select id from customfields
-                                          where name = ?
-                                            and ( $queue_sql )
-                                       )
-                )
-      ";
-      push @param, $priority,
-                   $priority_field,
-                   $priority_field_queue,
-                   $priority_field_queue;
+      #$where = "    
+      #  and ? = ( select content from TicketCustomFieldValues
+      #             where ticket = tickets.id
+      #               and customfield = ( select id from customfields
+      #                                    where name = ?
+      #                                      and ( $queue_sql )
+      #                                 )
+      #          )
+      #";
+      push @param, $priority;
+
+      $join = "join TicketCustomFieldValues
+                 on ( tickets.id = TicketCustomFieldValues.ticket )";
+      
+      $where = "and content = ?
+                and customfield = ( select id from customfields
+                                     where name = ?
+                                       and ( $queue_sql )
+                                  )
+               ";
     } else {
-      return '0nothandledyet0';
+      $where =
+               "and 0 = ( select count(*) from TicketCustomFieldValues
+                           where ticket = tickets.id
+                             and customfield = ( select id from customfields
+                                                  where name = ?
+                                                    and ( $queue_sql )
+                                               )
+                        )
+               ";
     }
+    push @param, $priority_field,
+                 $priority_field_queue,
+                 $priority_field_queue;
   }
 
   my $sql = "
-    select count(*) from tickets
+                    from tickets
+                    join queues on ( tickets.queue = queues.id )
                     join links on ( tickets.id = links.localbase )
+                    $join 
        where ( status = 'new' or status = 'open' or status = 'stalled' )
          and target = 'freeside://freeside/cust_main/$custnum'
-         $priority_sql
+         $where
   ";
 
-  my $sth = $dbh->prepare($sql) or die $dbh->errstr;
-  $sth->execute(@param)         or die $sth->errstr;
-
-  $sth->fetchrow_arrayref->[0];
+  ( $sql, @param );
 
 }
 
@@ -99,5 +150,16 @@ sub href_customer_tickets {
   $href;
 }
 
+
+sub href_new_ticket {
+  my( $self, $custnum ) = @_;
+  'Ticket/Create.html?Queue=1&new-MemberOf=freeside://freeside/cust_main/'.$custnum;
+}
+
+sub href_ticket {
+  my($self, $ticketnum) = @_;
+  'Ticket/Display.html?id='.$ticketnum;
+}
+
 1;
 
index a2cd024..0039823 100644 (file)
@@ -8,7 +8,7 @@ use FS::TicketSystem::RT_Libs;
 
 @ISA = qw( FS::TicketSystem::RT_Libs );
 
-sub sql_customer_tickets {
+sub sql_num_customer_tickets {
   "( select count(*) from tickets
                      join links on ( tickets.id = links.localbase )
      where ( status = 'new' or status = 'open' or status = 'stalled' )
@@ -21,11 +21,28 @@ sub num_customer_tickets {
   $self->SUPER::num_customer_tickets( $custnum, $priority, dbh );
 }
 
+sub customer_tickets {
+  my( $self, $custnum, $limit, $priority ) = ( shift, shift, shift, shift );
+  $self->SUPER::customer_tickets( $custnum, $limit, $priority, dbh );
+}
+
 sub href_customer_tickets {
   my $self = shift;
   # well, 2 is wrong here but will have to do for now
   popurl(2).'rt/'. $self->SUPER::href_customer_tickets(@_);
 }
 
+sub href_new_ticket {
+  my $self = shift;
+  # well, 2 is wrong here but will have to do for now
+  popurl(2).'rt/'. $self->SUPER::href_new_ticket(@_);
+}
+
+sub href_ticket {
+  my $self = shift;
+  # well, 2 is wrong here but will have to do for now
+  popurl(2).'rt/'. $self->SUPER::href_ticket(@_);
+}
+
 1;
 
index a12c180..ca9df87 100755 (executable)
@@ -71,7 +71,7 @@ if ( $cgi->param('browse')
     } elsif ( $query eq 'tickets' ) {
       $sortby = \*tickets_sort;
       $orderby = "ORDER BY tickets DESC";
-      push @select, FS::TicketSystem->sql_customer_tickets. " as tickets";
+      push @select, FS::TicketSystem->sql_num_customer_tickets. " as tickets";
       push @addl_headers, 'Tickets';
       push @addl_cols, 'tickets';
     } else {
@@ -402,7 +402,7 @@ END
       if ( $addl_col eq 'tickets' ) {
         if ( @custom_priorities ) {
           print '<TABLE>';
-          foreach my $priority ( @custom_priorities ) {
+          foreach my $priority ( @custom_priorities, '' ) {
             my $ahref =
               '<A HREF="'.
                 FS::TicketSystem->href_customer_tickets($custnum,$priority).
@@ -410,16 +410,19 @@ END
             print "<TR><TD ALIGN=right>$ahref".
                     FS::TicketSystem->num_customer_tickets($custnum,$priority).
                   "</A></TD>".
-                  "<TD ALIGN=left>$ahref$priority</A></TD></TR>";
+                  "<TD ALIGN=left>$ahref".
+                  ( $priority || '<i>(none)</i>' ).
+                  </A></TD></TR>";
           }
-          print "<TR><TD ALIGN=right>";
+          print '<TR><TD BGCOLOR="#000000" COLSPAN=2>&nbsp;</TD></TR>'.
+                '<TR><TD ALIGN=right>';
         }
         my $ahref =
           '<A HREF="'.
             FS::TicketSystem->href_customer_tickets($custnum).
           '">';
         print $ahref. $cust_main->get($addl_col). '</A>';
-        print "</TD><TD ALIGN=left>${ahref}total</A></TD></TR></TABLE>"
+        print "</TD><TD ALIGN=left>${ahref}Total</A></TD></TR></TABLE>"
           if @custom_priorities;
       } else {
         print $cust_main->get($addl_col);
index 9aa0089..322f067 100755 (executable)
@@ -70,239 +70,43 @@ print "This customer's signup URL: ".
       "<a href=\"$signupurl?ref=$custnum\">$signupurl?ref=$custnum</a><BR><BR>";
 }
 
-print '<A NAME="cust_main"></A>';
-
-print &itable(), '<TR>';
-
-print '<TD VALIGN="top">';
-
-  print "Billing address", &ntable("#cccccc"), "<TR><TD>",
-        &ntable("#cccccc",2),
-    '<TR><TD ALIGN="right">Contact&nbsp;name</TD>',
-      '<TD COLSPAN=3 BGCOLOR="#ffffff">',
-      $cust_main->last, ', ', $cust_main->first,
-      '</TD>';
-print '<TD ALIGN="right">SS#</TD><TD BGCOLOR="#ffffff">',
-      $cust_main->ss || '&nbsp', '</TD>'
-  if $conf->exists('show_ss');
-
-print '</TR>',
-    '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
-      $cust_main->company,
-      '</TD></TR>',
-    '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
-      $cust_main->address1,
-      '</TD></TR>',
-  ;
-  print '<TR><TD ALIGN="right">&nbsp;</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
-        $cust_main->address2, '</TD></TR>'
-    if $cust_main->address2;
-  print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->city,
-          '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->state,
-          '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->zip, '</TD></TR>',
-        '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->country,
-          '</TD></TR>',
-  ;
-  my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day&nbsp;Phone';
-  my $night_label = FS::Msgcat::_gettext('night') || 'Night&nbsp;Phone';
-  print '<TR><TD ALIGN="right">'. $daytime_label.
-          '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
-          $cust_main->daytime || '&nbsp', '</TD></TR>',
-        '<TR><TD ALIGN="right">'. $night_label. 
-          '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
-          $cust_main->night || '&nbsp', '</TD></TR>',
-        '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
-          $cust_main->fax || '&nbsp', '</TD></TR>',
-        '</TABLE>', "</TD></TR></TABLE>"
-  ;
-
-  if ( defined $cust_main->dbdef_table->column('ship_last') ) {
-
-    my $pre = $cust_main->ship_last ? 'ship_' : '';
-
-    print "<BR>Service address", &ntable("#cccccc"), "<TR><TD>",
-          &ntable("#cccccc",2),
-      '<TR><TD ALIGN="right">Contact name</TD>',
-        '<TD COLSPAN=5 BGCOLOR="#ffffff">',
-        $cust_main->get("${pre}last"), ', ', $cust_main->get("${pre}first"),
-        '</TD></TR>',
-      '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
-        $cust_main->get("${pre}company"),
-        '</TD></TR>',
-      '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
-        $cust_main->get("${pre}address1"),
-        '</TD></TR>',
-    ;
-    print '<TR><TD ALIGN="right">&nbsp;</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
-          $cust_main->get("${pre}address2"), '</TD></TR>'
-      if $cust_main->get("${pre}address2");
-    print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
-            $cust_main->get("${pre}city"),
-            '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
-            $cust_main->get("${pre}state"),
-            '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
-            $cust_main->get("${pre}zip"), '</TD></TR>',
-          '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
-            $cust_main->get("${pre}country"),
-            '</TD></TR>',
-    ;
-    print '<TR><TD ALIGN="right">'. $daytime_label. '</TD>',
-          '<TD COLSPAN=5 BGCOLOR="#ffffff">',
-            $cust_main->get("${pre}daytime") || '&nbsp', '</TD></TR>',
-          '<TR><TD ALIGN="right">'. $night_label. '</TD>'.
-          '<TD COLSPAN=5 BGCOLOR="#ffffff">',
-            $cust_main->get("${pre}night") || '&nbsp', '</TD></TR>',
-          '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
-            $cust_main->get("${pre}fax") || '&nbsp', '</TD></TR>',
-          '</TABLE>', "</TD></TR></TABLE>"
-    ;
-
-  }
-
-print '</TD>';
-
-print '<TD VALIGN="top">';
-
-  print &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
-        '<TR><TD ALIGN="right">Customer&nbsp;number</TD><TD BGCOLOR="#ffffff">',
-        $custnum, '</TD></TR>',
-  ;
-
-  my @agents = qsearch( 'agent', {} );
-  my $agent;
-  unless ( scalar(@agents) == 1 ) {
-    $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );
-    print '<TR><TD ALIGN="right">Agent</TD><TD BGCOLOR="#ffffff">',
-        $agent->agentnum, ": ", $agent->agent, '</TD></TR>';
-  } else {
-    $agent = $agents[0];
-  }
-  my @referrals = qsearch( 'part_referral', {} );
-  unless ( scalar(@referrals) == 1 ) {
-    my $referral = qsearchs('part_referral', {
-      'refnum' => $cust_main->refnum
-    } );
-    print '<TR><TD ALIGN="right">Advertising&nbsp;source</TD><TD BGCOLOR="#ffffff">',
-          $referral->refnum, ": ", $referral->referral, '</TD></TR>';
-  }
-  print '<TR><TD ALIGN="right">Order taker</TD><TD BGCOLOR="#ffffff">',
-    $cust_main->otaker, '</TD></TR>';
-
-  print '<TR><TD ALIGN="right">Referring&nbsp;Customer</TD><TD BGCOLOR="#ffffff">';
-  my $referring_cust_main = '';
-  if ( $cust_main->referral_custnum
-       && ( $referring_cust_main =
-            qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
-          )
-     ) {
-    print '<A HREF="'. popurl(1). 'cust_main.cgi?'.
-          $cust_main->referral_custnum. '">'.
-          $cust_main->referral_custnum. ': '.
-          ( $referring_cust_main->company
-              ? $referring_cust_main->company. ' ('.
-                  $referring_cust_main->last. ', '. $referring_cust_main->first.
-                  ')'
-              : $referring_cust_main->last. ', '. $referring_cust_main->first
-          ).
-          '</A>';
-  }
-  print '</TD></TR>';
-
-  print '</TABLE></TD></TR></TABLE>';
-
-print '<BR>';
-
-if ( $conf->config('payby-default') ne 'HIDE' ) {
-
-  my @invoicing_list = $cust_main->invoicing_list;
-  print "Billing information (",
-       qq!<A HREF="!, popurl(2), qq!misc/bill.cgi?$custnum">!, "Bill now</A>)",
-        &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
-        '<TR><TD ALIGN="right">Tax&nbsp;exempt</TD><TD BGCOLOR="#ffffff">',
-        $cust_main->tax ? 'yes' : 'no',
-        '</TD></TR>',
-        '<TR><TD ALIGN="right">Postal&nbsp;invoices</TD><TD BGCOLOR="#ffffff">',
-        ( grep { $_ eq 'POST' } @invoicing_list ) ? 'yes' : 'no',
-        '</TD></TR>',
-        '<TR><TD ALIGN="right">Email&nbsp;invoices</TD><TD BGCOLOR="#ffffff">',
-        join(', ', grep { $_ ne 'POST' } @invoicing_list ) || 'no',
-        '</TD></TR>',
-        '<TR><TD ALIGN="right">Billing&nbsp;type</TD><TD BGCOLOR="#ffffff">',
-  ;
-
-  if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) {
-    my $payinfo = $cust_main->payinfo_masked;
-    print 'Credit&nbsp;card&nbsp;',
-          ( $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' ),
-          '</TD></TR>',
-          '<TR><TD ALIGN="right">Card number</TD><TD BGCOLOR="#ffffff">',
-          $payinfo, '</TD></TR>',
-          '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->paydate, '</TD></TR>',
-          '<TR><TD ALIGN="right">Name on card</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->payname, '</TD></TR>'
-    ;
-  } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') {
-    my( $account, $aba ) = split('@', $cust_main->payinfo );
-    print 'Electronic&nbsp;check&nbsp;',
-          ( $cust_main->payby eq 'CHEK' ? '(automatic)' : '(on-demand)' ),
-          '</TD></TR>',
-          '<TR><TD ALIGN="right">Account number</TD><TD BGCOLOR="#ffffff">',
-          $account, '</TD></TR>',
-          '<TR><TD ALIGN="right">ABA/Routing code</TD><TD BGCOLOR="#ffffff">',
-          $aba, '</TD></TR>',
-          '<TR><TD ALIGN="right">Bank name</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->payname, '</TD></TR>'
-    ;
-  } elsif ( $cust_main->payby eq 'LECB' ) {
-    $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/;
-    my $payinfo = "$1-$2-$3";
-    print 'Phone&nbsp;bill&nbsp;billing</TD></TR>',
-          '<TR><TD ALIGN="right">Phone number</TD><TD BGCOLOR="#ffffff">',
-          $payinfo, '</TD></TR>',
-    ;
-  } elsif ( $cust_main->payby eq 'BILL' ) {
-    print 'Billing</TD></TR>';
-    print '<TR><TD ALIGN="right">P.O. </TD><TD BGCOLOR="#ffffff">',
-          $cust_main->payinfo, '</TD></TR>',
-      if $cust_main->payinfo;
-    print '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->paydate, '</TD></TR>',
-          '<TR><TD ALIGN="right">Attention</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->payname, '</TD></TR>',
-    ;
-  } elsif ( $cust_main->payby eq 'COMP' ) {
-    print 'Complimentary</TD></TR>',
-          '<TR><TD ALIGN="right">Authorized&nbsp;by</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->payinfo, '</TD></TR>',
-          '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
-          $cust_main->paydate, '</TD></TR>',
-    ;
-  }
-
-  print "</TABLE></TD></TR></TABLE>";
-
-}
+%>
 
-print '</TD></TR></TABLE>';
+<A NAME="cust_main"></A>
+<%= &itable() %>
+<TR>
+  <TD VALIGN="top">
+    <%= include('cust_main/contacts.html', $cust_main ) %>
+  </TD>
+  <TD VALIGN="top">
+    <%= include('cust_main/misc.html', $cust_main ) %>
+    <% if ( $conf->config('payby-default') ne 'HIDE' ) { %>
+      <BR>
+      <%= include('cust_main/billing.html', $cust_main ) %>
+    <% } %>
+  </TD>
+</TR>
+</TABLE>
 
+<%
 if ( defined $cust_main->dbdef_table->column('comments')
-     && $cust_main->comments =~ /[^\s\n\r]/ )
-{
-  print "<BR>Comments". &ntable("#cccccc"). "<TR><TD>".
-        &ntable("#cccccc",2).
-        '<TR><TD BGCOLOR="#ffffff"><PRE>'.
-        encode_entities($cust_main->comments).
-        '</PRE></TD></TR></TABLE></TABLE>';
-}
-
+     && $cust_main->comments =~ /[^\s\n\r]/              ) {
 %>
+<BR>
+Comments
+<%= ntable("#cccccc") %><TR><TD><%= ntable("#cccccc",2) %>
+<TR>
+  <TD BGCOLOR="#ffffff">
+    <PRE><%= encode_entities($cust_main->comments) %></PRE>
+  </TD>
+</TR>
+</TABLE></TABLE>
+<% } %>
 
-</TD></TR></TABLE>
+<% if ( $conf->config('ticket_system') ) { %>
+  <BR>
+  <%= include('cust_main/tickets.html', $cust_main ) %>
+<% } %>
 
 <BR>
 <SCRIPT TYPE="text/javascript">
@@ -319,6 +123,15 @@ function enable_order_pkg () {
 <SELECT NAME="pkgpart" onChange="enable_order_pkg()"><OPTION>Order additional package
 
 <%
+
+my @agents = qsearch( 'agent', {} );
+my $agent;
+unless ( scalar(@agents) == 1 ) {
+  $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );
+} else {
+  $agent = $agents[0];
+}
+
 foreach my $part_pkg (
   qsearch( 'part_pkg', { 'disabled' => '' }, '',
            ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
@@ -330,7 +143,7 @@ foreach my $part_pkg (
 <OPTION VALUE="<%= $part_pkg->pkgpart %>"><%= $part_pkg->pkg %> - <%= $part_pkg->comment %>
 <% } %>
 
-</SELECT><INPUT NAME="submit" TYPE="submit" VALUE="Order Package" disabled></FORM><BR>
+</SELECT><INPUT NAME="submit" TYPE="submit" VALUE="Order Package" disabled></FORM>
 
 <%
 
@@ -364,7 +177,7 @@ if ( $conf->config('payby-default') ne 'HIDE' ) {
 }
 
 print qq!<A NAME="cust_pkg">Packages</A> !,
-      qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Order and cancel packages</A> (preserves services) )!,
+      qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Bulk order and cancel packages</A> (preserves services) )!,
 ;
 
 #begin display packages
diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html
new file mode 100644 (file)
index 0000000..18a203b
--- /dev/null
@@ -0,0 +1,119 @@
+<%
+  my( $cust_main ) = @_;
+  my @invoicing_list = $cust_main->invoicing_list;
+%>
+
+Billing information
+(<A HREF="<%= $p %>misc/bill.cgi?<%= $cust_main->custnum %>">Bill now</A>)
+<%= ntable("#cccccc") %><TR><TD><%= ntable("#cccccc",2) %>
+<TR>
+  <TD ALIGN="right">Tax&nbsp;exempt</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->tax ? 'yes' : 'no' %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Postal&nbsp;invoices</TD>
+  <TD BGCOLOR="#ffffff">
+    <%= ( grep { $_ eq 'POST' } @invoicing_list ) ? 'yes' : 'no' %>
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Email&nbsp;invoices</TD>
+  <TD BGCOLOR="#ffffff">
+    <%= join(', ', grep { $_ ne 'POST' } @invoicing_list ) || 'no' %>
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Billing&nbsp;type</TD>
+  <TD BGCOLOR="#ffffff">
+
+<% if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) { %>
+
+    Credit&nbsp;card&nbsp;<%= $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' %>
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Card number</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->payinfo_masked %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Expiration</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->paydate %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Name on card</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->payname %></TD>
+</TR>
+
+<% } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') {
+     my( $account, $aba ) = split('@', $cust_main->payinfo );
+%>
+
+    Electronic&nbsp;check&nbsp;<%= $cust_main->payby eq 'CHEK' ? '(automatic)' : '(on-demand)' %>
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right">ABA/Routing code</TD>
+  <TD BGCOLOR="#ffffff"><%= $aba %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Account number</TD>
+  <TD BGCOLOR="#ffffff"><%= $account %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Bank name</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->payname %></TD>
+</TR>
+
+<% } elsif ( $cust_main->payby eq 'LECB' ) {
+     $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/;
+     my $payinfo = "$1-$2-$3";
+%>
+
+    Phone&nbsp;bill&nbsp;billing
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Phone number</TD>
+  <TD BGCOLOR="#ffffff"><%= $payinfo %></TD>
+</TR>
+
+<% } elsif ( $cust_main->payby eq 'BILL' ) { %>
+
+    Billing
+  </TD>
+</TR>
+
+  <% if ( $cust_main->payinfo ) { %>
+<TR>
+  <TD ALIGN="right">P.O. </TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->payinfo %></TD>
+</TR>
+  <% } %>
+
+<TR>
+  <TD ALIGN="right">Expiration</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->paydate %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Attention</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->payname %></TD>
+</TR>
+
+<% } elsif ( $cust_main->payby eq 'COMP' ) { %>
+
+    Complimentary
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Authorized&nbsp;by</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->payinfo %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Expiration</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->paydate %></TD>
+</TR>
+
+<% } %>
+
+</TABLE></TD></TR></TABLE>
+
diff --git a/httemplate/view/cust_main/contacts.html b/httemplate/view/cust_main/contacts.html
new file mode 100644 (file)
index 0000000..456d117
--- /dev/null
@@ -0,0 +1,131 @@
+<%
+  my( $cust_main ) = @_;
+  my $conf = new FS::Conf;
+%>
+
+Billing address
+<%= ntable("#cccccc") %><TR><TD><%= ntable("#cccccc",2) %>
+<TR>
+  <TD ALIGN="right">Contact&nbsp;name</TD>
+  <TD COLSPAN=3 BGCOLOR="#ffffff">
+    <%= $cust_main->last. ', '. $cust_main->first %>
+  </TD>
+<% if ( $conf->exists('show_ss') ) { %>
+  <TD ALIGN="right">SS#</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->ss || '&nbsp' %></TD>
+<% } %>
+</TR>
+<TR>
+  <TD ALIGN="right">Company</TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff"><%= $cust_main->company %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Address</TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff"><%= $cust_main->address1 %></TD>
+</TR>
+<% if ( $cust_main->address2 ) { %>
+<TR>
+  <TD ALIGN="right">&nbsp;</TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff"><%= $cust_main->address2 %></TD>
+</TR>
+<% } %>
+<TR>
+  <TD ALIGN="right">City</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->city %></TD>
+  <TD ALIGN="right">State</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->state %></TD>
+  <TD ALIGN="right">Zip</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->zip %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Country</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->country %></TD>
+</TR>
+<%
+  my $daytime_label = FS::Msgcat::_gettext('daytime') =~ /^(daytime)?$/
+                        ? 'Day&nbsp;Phone'
+                        : FS::Msgcat::_gettext('daytime');
+  my $night_label = FS::Msgcat::_gettext('night') =~ /^(night)?$/
+                        ? 'Night&nbsp;Phone'
+                        : FS::Msgcat::_gettext('night');
+%>
+<TR>
+  <TD ALIGN="right"><%= $daytime_label %></TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff">
+    <%= $cust_main->daytime || '&nbsp' %>
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right"><%= $night_label %></TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff">
+    <%= $cust_main->night || '&nbsp' %>
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Fax</TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff">
+    <%= $cust_main->fax || '&nbsp' %>
+  </TD>
+</TR>
+</TABLE></TD></TR></TABLE>
+
+<% if ( defined $cust_main->dbdef_table->column('ship_last') ) {
+     my $pre = $cust_main->ship_last ? 'ship_' : '';
+%>
+
+<BR>
+Service address
+<%= ntable("#cccccc") %><TR><TD><%= ntable("#cccccc",2) %>
+<TR>
+  <TD ALIGN="right">Contact name</TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff">
+    <%= $cust_main->get("${pre}last"). ', '. $cust_main->get("${pre}first") %>
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Company</TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff"><%= $cust_main->get("${pre}company") %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Address</TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff"><%= $cust_main->get("${pre}address1") %></TD>
+</TR>
+<% if ( $cust_main->get("${pre}address2") ) { %>
+<TR>
+  <TD ALIGN="right">&nbsp;</TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff"><%= $cust_main->get("${pre}address2") %></TD>
+</TR>
+<% } %>
+<TR>
+  <TD ALIGN="right">City</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->get("${pre}city") %></TD>
+  <TD ALIGN="right">State</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->get("${pre}state") %></TD>
+  <TD ALIGN="right">Zip</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->get("${pre}zip") %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Country</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->get("${pre}country") %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right"><%= $daytime_label %></TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff">
+    <%= $cust_main->get("${pre}daytime") || '&nbsp' %>
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right"><%= $night_label %></TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff">
+    <%= $cust_main->get("${pre}night") || '&nbsp' %>
+  </TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Fax</TD>
+  <TD COLSPAN=5 BGCOLOR="#ffffff">
+    <%= $cust_main->get("${pre}fax") || '&nbsp' %>
+  </TD>
+</TR>
+</TABLE></TD></TR></TABLE>
+
+<% } %>
diff --git a/httemplate/view/cust_main/misc.html b/httemplate/view/cust_main/misc.html
new file mode 100644 (file)
index 0000000..69e1205
--- /dev/null
@@ -0,0 +1,75 @@
+<%
+  my( $cust_main ) = @_;
+%>
+
+<%= ntable("#cccccc") %><TR><TD><%= &ntable("#cccccc",2) %>
+<TR>
+  <TD ALIGN="right">Customer&nbsp;number</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->custnum %></TD>
+</TR>
+
+<%
+  my @agents = qsearch( 'agent', {} );
+  my $agent;
+  unless ( scalar(@agents) == 1 ) {
+    $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );
+%>
+
+<TR>
+  <TD ALIGN="right">Agent</TD>
+  <TD BGCOLOR="#ffffff"><%= $agent->agentnum %>: <%= $agent->agent %></TD>
+</TR>
+
+<%
+  } else {
+    $agent = $agents[0];
+  }
+
+  my @referrals = qsearch( 'part_referral', {} );
+  unless ( scalar(@referrals) == 1 ) {
+    my $referral = qsearchs('part_referral', {
+      'refnum' => $cust_main->refnum
+    } );
+%>
+
+<TR>
+  <TD ALIGN="right">Advertising&nbsp;source</TD>
+  <TD BGCOLOR="#ffffff"><%= $referral->refnum %>: <%= $referral->referral%></TD>
+</TR>
+
+<% } %>
+
+<TR>
+  <TD ALIGN="right">Order taker</TD>
+  <TD BGCOLOR="#ffffff"><%= $cust_main->otaker %></TD>
+</TR>
+<TR>
+  <TD ALIGN="right">Referring&nbsp;Customer</TD>
+  <TD BGCOLOR="#ffffff">
+
+<%
+  my $referring_cust_main = '';
+  if ( $cust_main->referral_custnum
+       && ( $referring_cust_main =
+            qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
+          )
+     ) {
+%>
+
+<A HREF="<%= popurl(1) %>cust_main.cgi?<%= $cust_main->referral_custnum %>"><%=$cust_main->referral_custnum %>: 
+<%=
+  ( $referring_cust_main->company
+      ? $referring_cust_main->company. ' ('.
+          $referring_cust_main->last. ', '. $referring_cust_main->first.
+          ')'
+      : $referring_cust_main->last. ', '. $referring_cust_main->first
+  )
+%></A>
+
+<% } %>
+
+  </TD>
+</TR>
+
+</TABLE></TD></TR></TABLE>
+
diff --git a/httemplate/view/cust_main/tickets.html b/httemplate/view/cust_main/tickets.html
new file mode 100644 (file)
index 0000000..61c94d6
--- /dev/null
@@ -0,0 +1,54 @@
+<%
+  my( $cust_main ) = @_;
+
+  my $conf = new FS::Conf;
+  my $num = 10;
+
+  my @tickets = ();
+  unless ( $conf->config('ticket_system-custom_priority_field') ) {
+
+    @tickets =
+      @{ FS::TicketSystem->customer_tickets($cust_main->custnum, $num) };
+
+  } else {
+
+    foreach my $priority (
+      $conf->config('ticket_system-custom_priority_field-values'), ''
+    ) {
+      last if scalar(@tickets) >= $num;
+      push @tickets, 
+        @{ FS::TicketSystem->customer_tickets( $cust_main->custnum,
+                                               $num - scalar(@tickets),
+                                               $priority,
+                                             )
+         };
+    }
+
+  }
+
+%>
+
+Highest priority tickets
+(<A HREF="<%= FS::TicketSystem->href_customer_tickets($cust_main->custnum) %>">View all tickets for this customer</A>)
+(<A HREF="<%= FS::TicketSystem->href_new_ticket($cust_main->custnum) %>">New ticket for this customer</A>)
+<%= table() %>
+<TR>
+  <TH>#</TH>
+  <TH>Subject</TH>
+  <TH>Priority</TH>
+  <TH>Queue</TH>
+  <TH>Status</TH>
+</TR>
+<% foreach my $ticket ( @tickets ) {
+     my $href = FS::TicketSystem->href_ticket($ticket->{id});
+%>
+<TR>
+  <TD><A HREF=<%=$href%>><%= $ticket->{id} %></A></TD>
+  <TD><A HREF=<%=$href%>><%= $ticket->{subject} %></A></TD>
+  <TD ALIGN="right"><%= $ticket->{content} || $ticket->{priority} %></TD>
+  <TD><%= $ticket->{name} %></TD>
+  <TD><%= $ticket->{status} %></TD>
+</TR>
+<% } %>
+</TABLE>
+