X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main_note.pm;h=4c48eb60908d8b95eceeb456ebb14a7439b61c00;hp=4732d12ce1012a595391bbdcae01dfedbf4d149f;hb=389b6f1116c3309c2ee57a6c295ed1a793503095;hpb=9509e5bfb7f9331303153cac24d7bfecbe2ea9f1 diff --git a/FS/FS/cust_main_note.pm b/FS/FS/cust_main_note.pm index 4732d12ce..4c48eb609 100644 --- a/FS/FS/cust_main_note.pm +++ b/FS/FS/cust_main_note.pm @@ -1,10 +1,10 @@ package FS::cust_main_note; +use base qw( FS::otaker_Mixin FS::Record ); use strict; -use vars qw( @ISA ); -use FS::Record qw( qsearch qsearchs ); - -@ISA = qw(FS::Record); +use Carp; +use FS::Record qw( qsearchs ); #qw( qsearch qsearchs ); +use FS::Conf; =head1 NAME @@ -33,16 +33,19 @@ currently supported: =over 4 -=item notenum - primary key +=item notenum + +primary key -=item custnum - +=item custnum -=item _date - +=item classnum -=item otaker - +=item _date -=item comments - +=item usernum +=item comments =back @@ -106,15 +109,71 @@ 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_text('otaker') + || $self->ut_textn('otaker') || $self->ut_anything('comments') + || $self->ut_numbern('sticky') ; return $error if $error; + if (!$self->classnum) { + my $conf = new FS::Conf; + return 'Note class is required' + if $conf->exists('note-classes') + and $conf->config('note-classes') eq 'Required'; + } + $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. + +=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; + if ( scalar(@_) ) { #set + my $otaker = shift; + my($l,$f) = (split(', ', $otaker)); + my $access_user = qsearchs('access_user', { 'username'=>$otaker } ) + || qsearchs('access_user', { 'first'=>$f, 'last'=>$l } ) + or croak "can't set otaker: $otaker not found!"; #confess? + $self->usernum( $access_user->usernum ); + $otaker; #not sure return is used anywhere, but just in case + } else { #get + if ( $self->usernum ) { + $self->access_user->username; + } elsif ( length($self->get('otaker')) ) { + $self->get('otaker'); + } else { + ''; + } + } +} + +# Used by FS::Upgrade to migrate to a new database. +sub _upgrade_data { # class method + my ($class, %opts) = @_; + $class->_upgrade_otaker(%opts); +} + =back =head1 BUGS