From eca5199332bb2ba562fe9897a1832d557d5143a5 Mon Sep 17 00:00:00 2001 From: levinse Date: Thu, 27 Jan 2011 05:10:11 +0000 Subject: note classes backport to 2.1 branch, RT9995 --- FS/FS.pm | 2 + FS/FS/Conf.pm | 12 +++ FS/FS/Mason.pm | 1 + FS/FS/Schema.pm | 12 +++ FS/FS/cust_main.pm | 7 +- FS/FS/cust_main_note.pm | 34 +++++++++ FS/FS/cust_note_class.pm | 105 +++++++++++++++++++++++++++ FS/MANIFEST | 2 + FS/t/cust_note_class.t | 6 ++ httemplate/browse/cust_note_class.html | 35 +++++++++ httemplate/edit/cust_main_note.cgi | 19 ++++- httemplate/edit/cust_note_class.html | 7 ++ httemplate/edit/elements/class_Common.html | 6 +- httemplate/edit/process/cust_main_note.cgi | 4 + httemplate/edit/process/cust_note_class.html | 12 +++ httemplate/elements/menu.html | 3 + httemplate/view/cust_main.cgi | 2 +- httemplate/view/cust_main/notes.html | 102 ++++++++++++++++++++++---- 18 files changed, 349 insertions(+), 22 deletions(-) create mode 100644 FS/FS/cust_note_class.pm create mode 100644 FS/t/cust_note_class.t create mode 100644 httemplate/browse/cust_note_class.html create mode 100644 httemplate/edit/cust_note_class.html create mode 100644 httemplate/edit/process/cust_note_class.html diff --git a/FS/FS.pm b/FS/FS.pm index aca33de6a..af35d9602 100644 --- a/FS/FS.pm +++ b/FS/FS.pm @@ -292,6 +292,8 @@ L - Customer tax exemption class L - Customer note class +L - Customer note classification class + L - Banned payment information class L - Invoice class diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 95a9574a2..116533bd2 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -4236,6 +4236,18 @@ and customer address. Include units.', 'select_enum' => [ 'Classic', 'Recurring' ], }, + { + 'key' => 'note-classes', + 'section' => 'UI', + 'description' => 'Use customer note classes', + 'type' => 'select', + 'select_hash' => [ + 0 => 'Disabled', + 1 => 'Enabled', + 2 => 'Enabled, with tabs', + ], + }, + { key => "apacheroot", section => "deprecated", description => "DEPRECATED", type => "text" }, { key => "apachemachine", section => "deprecated", description => "DEPRECATED", type => "text" }, { key => "apachemachines", section => "deprecated", description => "DEPRECATED", type => "text" }, diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index d3c04db27..b66dc8cee 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -258,6 +258,7 @@ if ( -e $addl_handler_use_file ) { use FS::acct_snarf; use FS::part_pkg_discount; use FS::svc_cert; + use FS::cust_note_class; # Sammath Naur if ( $FS::Mason::addl_handler_use ) { diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index ce1cd4fae..a7f0bfacc 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -930,6 +930,7 @@ sub tables_hashref { 'columns' => [ 'notenum', 'serial', '', '', '', '', 'custnum', 'int', '', '', '', '', + 'classnum', 'int', 'NULL', '', '', '', '_date', @date_type, '', '', 'otaker', 'varchar', 'NULL', 32, '', '', 'usernum', 'int', 'NULL', '', '', '', @@ -940,6 +941,17 @@ sub tables_hashref { 'index' => [ [ 'custnum' ], [ '_date' ], [ 'usernum' ], ], }, + 'cust_note_class' => { + 'columns' => [ + 'classnum', 'serial', '', '', '', '', + 'classname', 'varchar', '', $char_d, '', '', + 'disabled', 'char', 'NULL', 1, '', '', + ], + 'primary_key' => 'classnum', + 'unique' => [], + 'index' => [ ['disabled'] ], + }, + 'cust_category' => { 'columns' => [ 'categorynum', 'serial', '', '', '', '', diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index e4ff3bf3c..cf4c6d915 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -2211,12 +2211,13 @@ Returns all notes (see L) for this customer. =cut sub notes { - my $self = shift; - #order by? + my($self,$orderby_classnum) = (shift,shift); + my $orderby = "_DATE DESC"; + $orderby = "CLASSNUM ASC, $orderby" if $orderby_classnum; qsearch( 'cust_main_note', { 'custnum' => $self->custnum }, '', - 'ORDER BY _DATE DESC' + "ORDER BY $orderby", ); } diff --git a/FS/FS/cust_main_note.pm b/FS/FS/cust_main_note.pm index 0a203a8f4..06da0965a 100644 --- a/FS/FS/cust_main_note.pm +++ b/FS/FS/cust_main_note.pm @@ -4,6 +4,7 @@ use strict; use base qw( FS::otaker_Mixin FS::Record ); use Carp; use FS::Record qw( qsearch qsearchs ); +use FS::cust_note_class; =head1 NAME @@ -38,6 +39,8 @@ primary key =item custnum +=item classnum + =item _date =item usernum @@ -106,6 +109,7 @@ sub check { my $error = $self->ut_numbern('notenum') || $self->ut_number('custnum') + || $self->ut_foreign_keyn('classnum', 'cust_note_class', 'classnum') || $self->ut_numbern('_date') || $self->ut_textn('otaker') || $self->ut_anything('comments') @@ -115,6 +119,36 @@ sub check { $self->SUPER::check; } +=item cust_note_class + +Returns the customer note class, as an FS::cust_note_class object, or the empty +string if there is no note class. + +=cut + +sub cust_note_class { + my $self = shift; + if ( $self->classnum ) { + qsearchs('cust_note_class', { 'classnum' => $self->classnum } ); + } else { + return ''; + } +} + +=item classname + +Returns the customer note class name, or the empty string if there is no +customer note class. + +=cut + +sub classname { + my $self = shift; + my $cust_note_class = $self->cust_note_class; + $cust_note_class ? $cust_note_class->classname : ''; +} + + #false laziness w/otaker_Mixin & cust_attachment sub otaker { my $self = shift; diff --git a/FS/FS/cust_note_class.pm b/FS/FS/cust_note_class.pm new file mode 100644 index 000000000..0cb967754 --- /dev/null +++ b/FS/FS/cust_note_class.pm @@ -0,0 +1,105 @@ +package FS::cust_note_class; + +use strict; +use base qw( FS::class_Common ); +use FS::cust_main_note; + +=head1 NAME + +FS::cust_note_class - Object methods for cust_note_class records + +=head1 SYNOPSIS + + use FS::cust_note_class; + + $record = new FS::cust_note_class \%hash; + $record = new FS::cust_note_class { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::cust_note_class object represents a customer note class. Every customer +note (see L. + +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 method. + +=cut + +sub table { 'cust_note_class'; } +sub _target_table { 'cust_main_note'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +=item delete + +Delete this record from the database. + +=cut + +=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 + +=item check + +Checks all fields to make sure this is a valid note class. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L, L, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/MANIFEST b/FS/MANIFEST index 8b9cec91d..58728e4b0 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -541,3 +541,5 @@ t/part_pkg_discount.t FS/svc_cert.pm t/svc_cert.t FS/cust_main/Status.pm +FS/cust_note_class.pm +t/cust_note_class.t diff --git a/FS/t/cust_note_class.t b/FS/t/cust_note_class.t new file mode 100644 index 000000000..feeb78c28 --- /dev/null +++ b/FS/t/cust_note_class.t @@ -0,0 +1,6 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::cust_note_class; +$loaded=1; +print "ok 1\n"; + diff --git a/httemplate/browse/cust_note_class.html b/httemplate/browse/cust_note_class.html new file mode 100644 index 000000000..889ee3208 --- /dev/null +++ b/httemplate/browse/cust_note_class.html @@ -0,0 +1,35 @@ +<% include( 'elements/browse.html', + 'title' => 'Customer note classes', + 'html_init' => $html_init, + 'name' => 'customer note classes', + 'disableable' => 1, + 'disabled_statuspos' => 2, + 'query' => { 'table' => 'cust_note_class', + 'hashref' => {}, + 'order_by' => 'ORDER BY classnum', + }, + 'count_query' => $count_query, + 'header' => $header, + 'fields' => $fields, + 'links' => $links, + ) +%> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $html_init = + 'Customer note classes define groups of notes for reporting.

'. + qq!Add a customer note class

!; + +my $count_query = 'SELECT COUNT(*) FROM cust_note_class'; + +my $link = [ $p.'edit/cust_note_class.html?', 'classnum' ]; + +my $header = [ '#', 'Class' ]; +my $fields = [ 'classnum', 'classname' ]; +my $links = [ $link, $link ]; + + + diff --git a/httemplate/edit/cust_main_note.cgi b/httemplate/edit/cust_main_note.cgi index 439c84414..c4ec071b8 100755 --- a/httemplate/edit/cust_main_note.cgi +++ b/httemplate/edit/cust_main_note.cgi @@ -6,6 +6,18 @@ +% if ($conf->exists('note-classes') && $conf->config('note-classes') > 0) { + Class   + <% include( '/elements/select-table.html', + 'table' => 'cust_note_class', + 'name_col' => 'classname', + 'curr_value' => $classnum, + 'empty_label' => '(none)', + 'hashref' => { 'disabled' => '' }, + ) %> +
+% } + % if( $FS::CurrentUser::CurrentUser->option('disable_html_editor') ) {