Enhanced customer notes
authorjeff <jeff>
Tue, 3 Oct 2006 22:44:28 +0000 (22:44 +0000)
committerjeff <jeff>
Tue, 3 Oct 2006 22:44:28 +0000 (22:44 +0000)
12 files changed:
FS/FS/AccessRight.pm
FS/FS/Conf.pm
FS/FS/Schema.pm
FS/FS/cust_main.pm
FS/FS/cust_main_note.pm [new file with mode: 0644]
FS/MANIFEST
FS/t/cust_main_note.t [new file with mode: 0644]
httemplate/edit/cust_main.cgi
httemplate/edit/cust_main_note.cgi [new file with mode: 0755]
httemplate/edit/process/cust_main_note.cgi [new file with mode: 0755]
httemplate/view/cust_main.cgi
httemplate/view/cust_main/notes.html [new file with mode: 0755]

index 83291b8..aa45866 100644 (file)
@@ -92,6 +92,7 @@ assigned to users and/or groups.
   'Cancel customer',
   'Complimentary customer', #aka users-allow_comp 
   'Delete customer', #aka. deletecustomers #Enable customer deletions. Be very careful! Deleting a customer will remove all traces that this customer ever existed! It should probably only be used when auditing a legacy database. Normally, you cancel all of a customers' packages if they cancel service.
+  'Add customer note',
 
 ###
 # customer package rights
index ee1692a..384ff52 100644 (file)
@@ -1744,6 +1744,27 @@ httemplate/docs/config.html
   },
 
   {
+    'key'         => 'cust_main-use_comments',
+    'section'     => 'UI',
+    'description' => 'Display free form comments on the customer edit screen.  Useful as a scratch pad.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cust_main-use_notes',
+    'section'     => 'UI',
+    'description' => 'Display link to add timestamped and user identified customr notes.  Useful in tracking who did what.',
+    'type'        => 'checkbox',
+  },
+
+  {
+    'key'         => 'cust_main_note-display_times',
+    'section'     => 'UI',
+    'description' => 'Display full timestamps (not just dates) for customer notes.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'cust_main-ticket_statuses',
     'section'     => 'UI',
     'description' => 'Show tickets with these statuses on the customer view page.',
index ef697b9..3d4fcc5 100644 (file)
@@ -473,6 +473,19 @@ sub tables_hashref {
       'index' => [ ['custnum'], ],
     },
 
+    'cust_main_note' => {
+      'columns' => [
+        'notenum',  'serial',  '',     '', '', '', 
+        'custnum',  'int',  '',     '', '', '', 
+        '_date',    @date_type, '', '', 
+        'otaker',   'varchar', '',    32, '', '', 
+        'comments', 'text', 'NULL', '', '', '', 
+      ],
+      'primary_key' => 'notenum',
+      'unique' => [],
+      'index' => [ [ 'custnum' ], [ '_date' ], ],
+    },
+
     'cust_main_county' => { #county+state+country are checked off the
                             #cust_main_county for validation and to provide
                             # a tax rate.
index 875db93..4841387 100644 (file)
@@ -1732,6 +1732,22 @@ sub _banned_pay_hashref {
   };
 }
 
+=item notes
+
+Returns all notes (see L<FS::cust_main_note>) for this customer.
+
+=cut
+
+sub notes {
+  my $self = shift;
+  #order by?
+  qsearch( 'cust_main_note',
+           { 'custnum' => $self->custnum },
+          '',
+          'ORDER BY _DATE DESC'
+        );
+}
+
 =item agent
 
 Returns the agent (see L<FS::agent>) for this customer.
diff --git a/FS/FS/cust_main_note.pm b/FS/FS/cust_main_note.pm
new file mode 100644 (file)
index 0000000..4732d12
--- /dev/null
@@ -0,0 +1,131 @@
+package FS::cust_main_note;
+
+use strict;
+use vars qw( @ISA );
+use FS::Record qw( qsearch qsearchs );
+
+@ISA = qw(FS::Record);
+
+=head1 NAME
+
+FS::cust_main_note - Object methods for cust_main_note records
+
+=head1 SYNOPSIS
+
+  use FS::cust_main_note;
+
+  $record = new FS::cust_main_note \%hash;
+  $record = new FS::cust_main_note { 'column' => 'value' };
+
+  $error = $record->insert;
+
+  $error = $new_record->replace($old_record);
+
+  $error = $record->delete;
+
+  $error = $record->check;
+
+=head1 DESCRIPTION
+
+An FS::cust_main_note object represents a note attachted to a customer.
+FS::cust_main_note inherits from FS::Record.  The following fields are
+currently supported:
+
+=over 4
+
+=item notenum - primary key
+
+=item custnum - 
+
+=item _date - 
+
+=item otaker - 
+
+=item comments - 
+
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF
+
+Creates a new customer note.  To add the note to the database, see L<"insert">.
+
+Note that this stores the hash reference, not a distinct copy of the hash it
+points to.  You can ask the object for a copy with the I<hash> method.
+
+=cut
+
+# the new method can be inherited from FS::Record, if a table method is defined
+
+sub table { 'cust_main_note'; }
+
+=item insert
+
+Adds this record to the database.  If there is an error, returns the error,
+otherwise returns false.
+
+=cut
+
+# the insert method can be inherited from FS::Record
+
+=item delete
+
+Delete this record from the database.
+
+=cut
+
+# the delete method can be inherited from FS::Record
+
+=item replace OLD_RECORD
+
+Replaces the OLD_RECORD with this one in the database.  If there is an error,
+returns the error, otherwise returns false.
+
+=cut
+
+# the replace method can be inherited from FS::Record
+
+=item check
+
+Checks all fields to make sure this is a valid example.  If there is
+an error, returns the error, otherwise returns false.  Called by the insert
+and replace methods.
+
+=cut
+
+# the check method should currently be supplied - FS::Record contains some
+# data checking routines
+
+sub check {
+  my $self = shift;
+
+  my $error = 
+    $self->ut_numbern('notenum')
+    || $self->ut_number('custnum')
+    || $self->ut_numbern('_date')
+    || $self->ut_text('otaker')
+    || $self->ut_anything('comments')
+  ;
+  return $error if $error;
+
+  $self->SUPER::check;
+}
+
+=back
+
+=head1 BUGS
+
+Lurking in the cracks.
+
+=head1 SEE ALSO
+
+L<FS::Record>, schema.html from the base documentation.
+
+=cut
+
+1;
+
index db09177..c67145b 100644 (file)
@@ -356,3 +356,5 @@ FS/cust_bill_pay_pkg.pm
 t/cust_bill_pay_pkg.t
 FS/cust_credit_bill_pkg.pm
 t/cust_credit_bill_pkg.t
+FS/cust_main_note.pm
+t/cust_main_note.t
diff --git a/FS/t/cust_main_note.t b/FS/t/cust_main_note.t
new file mode 100644 (file)
index 0000000..41a7bac
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::cust_main_note;
+$loaded=1;
+print "ok 1\n";
index dfcd040..99f849f 100755 (executable)
@@ -359,17 +359,20 @@ function copyelement(from, to) {
 
   <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
 % } 
-
+%
+% my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
+% if (!$ro_comments || $cust_main->comments) {
 
 <BR>Comments
 <% &ntable("#cccccc") %>
   <TR>
     <TD>
-      <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments"><% $cust_main->comments %></TEXTAREA>
+      <TEXTAREA COLS=80 ROWS=5 WRAP="HARD" NAME="comments" <%$ro_comments%>><% $cust_main->comments %></TEXTAREA>
     </TD>
   </TR>
 </TABLE>
 %
+% }
 %
 %unless ( $custnum ) {
 %  # pry the wrong place for this logic.  also pretty expensive
diff --git a/httemplate/edit/cust_main_note.cgi b/httemplate/edit/cust_main_note.cgi
new file mode 100755 (executable)
index 0000000..468ef00
--- /dev/null
@@ -0,0 +1,37 @@
+<% include('/elements/header-popup.html', 'Add Customer Note') %>
+
+% if ( $cgi->param('error') ) { 
+  <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
+  <BR><BR>
+% } 
+
+<FORM ACTION="<% popurl(1) %>process/cust_main_note.cgi" METHOD=POST>
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
+
+
+<BR><BR>
+<TEXTAREA NAME="comment" ROWS="12" COLS="60">
+<% $comment %>
+</TEXTAREA>
+
+<BR><BR>
+<INPUT TYPE="submit" VALUE="Add note">
+
+</FORM>
+</BODY>
+</HTML>
+
+<%init>
+my($custnum, $comment); 
+$comment = '';
+
+if ( $cgi->param('error') ) {
+  $comment     = $cgi->param('comment');
+}
+$cgi->param('custnum') =~ /^(\d+)$/;
+$custnum     = $1;
+
+die "illegal query ". $cgi->keywords unless $custnum;
+
+</%init>
+
diff --git a/httemplate/edit/process/cust_main_note.cgi b/httemplate/edit/process/cust_main_note.cgi
new file mode 100755 (executable)
index 0000000..d9251f0
--- /dev/null
@@ -0,0 +1,34 @@
+%
+%
+%$cgi->param('custnum') =~ /^(\d+)$/
+%  or die "Illegal custnum: ". $cgi->param('custnum');
+%my $custnum = $1;
+%
+%my $otaker = $FS::CurrentUser::CurrentUser->name;
+%$otaker = $FS::CurrentUser::CurrentUser->username
+%  if ($otaker eq "User, Legacy");
+%
+%my $new = new FS::cust_main_note ( {
+%  custnum  => $custnum,
+%  _date    => time,
+%  otaker   => $otaker,
+%  comments =>  $cgi->param('comment'),
+%} );
+%
+%my $error = $new->insert;
+%
+%if ($error) {
+%  $cgi->param('error', $error);
+%  print $cgi->redirect(popurl(2). 'cust_main_note.cgi?'. $cgi->query_string );
+%}
+%
+%    
+<% header('Note added') %>
+    <SCRIPT TYPE="text/javascript">
+      window.top.location.reload();
+    </SCRIPT>
+
+    </BODY></HTML>
+%
+%
+
index e82a519..6b22777 100755 (executable)
@@ -116,6 +116,34 @@ Comments
 </TR>
 </TABLE></TABLE>
 % } 
+<BR><BR>
+% my $notecount = scalar($cust_main->notes());
+% if ($conf->exists('cust_main-use_notes') || $notecount) {
+
+<A NAME="cust_main_note"><FONT SIZE="+2">Notes</FONT></A><BR>
+%   if ( $curuser->access_right('Add customer note') &&
+%        $conf->exists('cust_main-use_notes')
+%      ) {
+
+  <A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('<% $p %>edit/cust_main_note.cgi?custnum=<% $cust_main->custnum %>', 616, 386, 'cust_main_note_popup' ), CAPTION, 'Enter customer note', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">Add customer note</A>
+
+%   }
+
+<BR>
+
+%   if ($notecount) {
+
+<iframe src="<% $p %>view/cust_main/notes.html?custnum=<% $cust_main->custnum %>" height="186" width="616" name="cust_main_notes" frameborder="0" marginborder="0" marginheight="0" scrolling="auto">
+  <div><br>[iframe not supported]<br><br></div>
+</iframe>
+
+%   } else {
+
+<BR>
+%   }
+% }
+
+
 % if ( $conf->config('ticket_system') ) { 
 
   <BR>
diff --git a/httemplate/view/cust_main/notes.html b/httemplate/view/cust_main/notes.html
new file mode 100755 (executable)
index 0000000..c1a33b0
--- /dev/null
@@ -0,0 +1,74 @@
+%
+% my $conf = new FS::Conf;
+%
+% $cgi->param('custnum') =~ /^(\d+)$/
+%   or die "No customer specified (bad URL)!";
+% my $custnum = $1;
+%
+% my $cust_main = qsearchs('cust_main', {'custnum' => $custnum} );
+% die "Custimer not found!" unless $cust_main;
+%
+% my (@notes) = $cust_main->notes();
+% if ( scalar(@notes) ) { 
+
+<STYLE TYPE="text/css">
+
+body { background: #e8e8e8 }
+.inv table { border: none }
+.inv TH { border: none }
+.inv TD { border: none }
+
+</STYLE>
+
+<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 BORDER=0 >
+
+%#<% include('/elements/table-grid.html') %>
+%   my $bgcolor1 = '#eeeeee';
+%   my $bgcolor2 = '#ffffff';
+%   my $bgcolor = '';
+%
+%   foreach my $note (@notes) {
+%
+%   if ( $bgcolor eq $bgcolor1 ) {
+%     $bgcolor = $bgcolor2;
+%   } else {
+%     $bgcolor = $bgcolor1;
+%   }
+%
+%
+
+<TR>
+  <% note_datestr($note,$conf,$bgcolor) %>
+  <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
+    &nbsp;<%$note->otaker%>&nbsp;
+  </TD>
+  <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
+    &nbsp;<%$note->comments%>
+  </TD>
+</TR>
+
+% } #end display notes
+
+</TABLE>
+% } else { 
+
+<BR>
+% } 
+%
+%#subroutines
+%
+%sub note_datestr {
+% my($note, $conf, $bgcolor) = @_ or return '';
+% my $format=qq{<TD class="inv" bgcolor="$bgcolor" align="left"><B>%b</B></TD>}.
+%            qq{<TD class="inv" bgcolor="$bgcolor" align="right"><B>&nbsp;%o,</B></TD>}.
+%            qq{<TD class="inv" bgcolor="$bgcolor" align="right"><B>&nbsp;%Y&nbsp;</B></TD>};
+% $format .= qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="right"><B>&nbsp;%l</TD>}.
+%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="center"><B>:</B></TD>}.
+%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="left"><B>%M</B></TD>}.
+%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="left"><B>&nbsp;%P&nbsp;</B></TD>}
+%     if $conf->exists('cust_main_note-display_times');
+%   ( my $strip = time2str($format, $note->_date) ) =~ s/ (\d)/$1/g;
+%   $strip;
+% }
+%
+