From 8d4abaa99403699aa5b5f02e899d2ea33980f913 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 9 Dec 2004 09:21:43 +0000 Subject: [PATCH] more RT integration --- FS/FS/TicketSystem/RT_External.pm | 108 ++++++++++--- FS/FS/TicketSystem/RT_Internal.pm | 19 ++- httemplate/search/cust_main.cgi | 13 +- httemplate/view/cust_main.cgi | 273 +++++--------------------------- httemplate/view/cust_main/billing.html | 119 ++++++++++++++ httemplate/view/cust_main/contacts.html | 131 +++++++++++++++ httemplate/view/cust_main/misc.html | 75 +++++++++ httemplate/view/cust_main/tickets.html | 54 +++++++ 8 files changed, 533 insertions(+), 259 deletions(-) create mode 100644 httemplate/view/cust_main/billing.html create mode 100644 httemplate/view/cust_main/contacts.html create mode 100644 httemplate/view/cust_main/misc.html create mode 100644 httemplate/view/cust_main/tickets.html diff --git a/FS/FS/TicketSystem/RT_External.pm b/FS/FS/TicketSystem/RT_External.pm index 3bb1991f5..7a39c9153 100644 --- a/FS/FS/TicketSystem/RT_External.pm +++ b/FS/FS/TicketSystem/RT_External.pm @@ -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; diff --git a/FS/FS/TicketSystem/RT_Internal.pm b/FS/FS/TicketSystem/RT_Internal.pm index a2cd0246a..00398230f 100644 --- a/FS/FS/TicketSystem/RT_Internal.pm +++ b/FS/FS/TicketSystem/RT_Internal.pm @@ -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; diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index a12c180a5..ca9df87a6 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -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 ''; - foreach my $priority ( @custom_priorities ) { + foreach my $priority ( @custom_priorities, '' ) { my $ahref = '". - ""; + ""; } - print "'. + '
$ahref". FS::TicketSystem->num_customer_tickets($custnum,$priority). "$ahref$priority
$ahref". + ( $priority || '(none)' ). +
"; + print '
 
'; } my $ahref = ''; print $ahref. $cust_main->get($addl_col). ''; - print "${ahref}total
" + print "${ahref}Total" if @custom_priorities; } else { print $cust_main->get($addl_col); diff --git a/httemplate/view/cust_main.cgi b/httemplate/view/cust_main.cgi index 9aa008969..322f0674e 100755 --- a/httemplate/view/cust_main.cgi +++ b/httemplate/view/cust_main.cgi @@ -70,239 +70,43 @@ print "This customer's signup URL: ". "$signupurl?ref=$custnum

"; } -print ''; - -print &itable(), ''; - -print ''; - - print "Billing address", &ntable("#cccccc"), "", - &ntable("#cccccc",2), - 'Contact name', - '', - $cust_main->last, ', ', $cust_main->first, - ''; -print 'SS#', - $cust_main->ss || ' ', '' - if $conf->exists('show_ss'); - -print '', - 'Company', - $cust_main->company, - '', - 'Address', - $cust_main->address1, - '', - ; - print ' ', - $cust_main->address2, '' - if $cust_main->address2; - print 'City', - $cust_main->city, - 'State', - $cust_main->state, - 'Zip', - $cust_main->zip, '', - 'Country', - $cust_main->country, - '', - ; - my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone'; - my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone'; - print ''. $daytime_label. - '', - $cust_main->daytime || ' ', '', - ''. $night_label. - '', - $cust_main->night || ' ', '', - 'Fax', - $cust_main->fax || ' ', '', - '', "" - ; - - if ( defined $cust_main->dbdef_table->column('ship_last') ) { - - my $pre = $cust_main->ship_last ? 'ship_' : ''; - - print "
Service address", &ntable("#cccccc"), "", - &ntable("#cccccc",2), - 'Contact name', - '', - $cust_main->get("${pre}last"), ', ', $cust_main->get("${pre}first"), - '', - 'Company', - $cust_main->get("${pre}company"), - '', - 'Address', - $cust_main->get("${pre}address1"), - '', - ; - print ' ', - $cust_main->get("${pre}address2"), '' - if $cust_main->get("${pre}address2"); - print 'City', - $cust_main->get("${pre}city"), - 'State', - $cust_main->get("${pre}state"), - 'Zip', - $cust_main->get("${pre}zip"), '', - 'Country', - $cust_main->get("${pre}country"), - '', - ; - print ''. $daytime_label. '', - '', - $cust_main->get("${pre}daytime") || ' ', '', - ''. $night_label. ''. - '', - $cust_main->get("${pre}night") || ' ', '', - 'Fax', - $cust_main->get("${pre}fax") || ' ', '', - '', "" - ; - - } - -print ''; - -print ''; - - print &ntable("#cccccc"), "", &ntable("#cccccc",2), - 'Customer number', - $custnum, '', - ; - - my @agents = qsearch( 'agent', {} ); - my $agent; - unless ( scalar(@agents) == 1 ) { - $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } ); - print 'Agent', - $agent->agentnum, ": ", $agent->agent, ''; - } else { - $agent = $agents[0]; - } - my @referrals = qsearch( 'part_referral', {} ); - unless ( scalar(@referrals) == 1 ) { - my $referral = qsearchs('part_referral', { - 'refnum' => $cust_main->refnum - } ); - print 'Advertising source', - $referral->refnum, ": ", $referral->referral, ''; - } - print 'Order taker', - $cust_main->otaker, ''; - - print 'Referring Customer'; - my $referring_cust_main = ''; - if ( $cust_main->referral_custnum - && ( $referring_cust_main = - qsearchs('cust_main', { custnum => $cust_main->referral_custnum } ) - ) - ) { - print ''. - $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 - ). - ''; - } - print ''; - - print ''; - -print '
'; - -if ( $conf->config('payby-default') ne 'HIDE' ) { - - my @invoicing_list = $cust_main->invoicing_list; - print "Billing information (", - qq!!, "Bill now)", - &ntable("#cccccc"), "", &ntable("#cccccc",2), - 'Tax exempt', - $cust_main->tax ? 'yes' : 'no', - '', - 'Postal invoices', - ( grep { $_ eq 'POST' } @invoicing_list ) ? 'yes' : 'no', - '', - 'Email invoices', - join(', ', grep { $_ ne 'POST' } @invoicing_list ) || 'no', - '', - 'Billing type', - ; - - if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) { - my $payinfo = $cust_main->payinfo_masked; - print 'Credit card ', - ( $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' ), - '', - 'Card number', - $payinfo, '', - 'Expiration', - $cust_main->paydate, '', - 'Name on card', - $cust_main->payname, '' - ; - } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') { - my( $account, $aba ) = split('@', $cust_main->payinfo ); - print 'Electronic check ', - ( $cust_main->payby eq 'CHEK' ? '(automatic)' : '(on-demand)' ), - '', - 'Account number', - $account, '', - 'ABA/Routing code', - $aba, '', - 'Bank name', - $cust_main->payname, '' - ; - } elsif ( $cust_main->payby eq 'LECB' ) { - $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/; - my $payinfo = "$1-$2-$3"; - print 'Phone bill billing', - 'Phone number', - $payinfo, '', - ; - } elsif ( $cust_main->payby eq 'BILL' ) { - print 'Billing'; - print 'P.O. ', - $cust_main->payinfo, '', - if $cust_main->payinfo; - print 'Expiration', - $cust_main->paydate, '', - 'Attention', - $cust_main->payname, '', - ; - } elsif ( $cust_main->payby eq 'COMP' ) { - print 'Complimentary', - 'Authorized by', - $cust_main->payinfo, '', - 'Expiration', - $cust_main->paydate, '', - ; - } - - print ""; - -} +%> -print ''; + +<%= &itable() %> + + + <%= include('cust_main/contacts.html', $cust_main ) %> + + + <%= include('cust_main/misc.html', $cust_main ) %> + <% if ( $conf->config('payby-default') ne 'HIDE' ) { %> +
+ <%= include('cust_main/billing.html', $cust_main ) %> + <% } %> + + + +<% if ( defined $cust_main->dbdef_table->column('comments') - && $cust_main->comments =~ /[^\s\n\r]/ ) -{ - print "
Comments". &ntable("#cccccc"). "". - &ntable("#cccccc",2). - '
'.
-        encode_entities($cust_main->comments).
-        '
'; -} - + && $cust_main->comments =~ /[^\s\n\r]/ ) { %> +
+Comments +<%= ntable("#cccccc") %><%= ntable("#cccccc",2) %> + + +
<%= encode_entities($cust_main->comments) %>
+ + + +<% } %> - +<% if ( $conf->config('ticket_system') ) { %> +
+ <%= include('cust_main/tickets.html', $cust_main ) %> +<% } %>