summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2010-03-29 00:23:07 +0000
committerivan <ivan>2010-03-29 00:23:07 +0000
commitb516a7cb6c072871568bb0f217cc2bab6ebddd4a (patch)
tree28565d474bfbee6aa80d13e4964e8b335fd57ded
parentcc9855d8e52fe35a362f7bda01616d53f04a7aab (diff)
move from otaker to proper usernum FK
-rw-r--r--FS/FS/Schema.pm56
-rw-r--r--FS/FS/Upgrade.pm13
-rw-r--r--FS/FS/access_user.pm17
-rw-r--r--FS/FS/banned_pay.pm12
-rw-r--r--FS/FS/cust_attachment.pm14
-rw-r--r--FS/FS/cust_credit.pm23
-rw-r--r--FS/FS/cust_main.pm23
-rw-r--r--FS/FS/cust_main_note.pm23
-rw-r--r--FS/FS/cust_pay_void.pm18
-rw-r--r--FS/FS/cust_pkg.pm21
-rw-r--r--FS/FS/cust_pkg_discount.pm14
-rw-r--r--FS/FS/cust_pkg_reason.pm20
-rw-r--r--FS/FS/cust_refund.pm64
-rw-r--r--FS/FS/otaker_Mixin.pm67
14 files changed, 276 insertions, 109 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 677fa41..64fb092 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -391,7 +391,8 @@ sub tables_hashref {
'attachnum', 'serial', '', '', '', '',
'custnum', 'int', '', '', '', '',
'_date', @date_type, '', '',
- 'otaker', 'varchar', '', 32, '', '',
+ 'otaker', 'varchar', 'NULL', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
'filename', 'varchar', '', 255, '', '',
'mime_type', 'varchar', '', $char_d, '', '',
'title', 'varchar', 'NULL', $char_d, '', '',
@@ -400,7 +401,7 @@ sub tables_hashref {
],
'primary_key' => 'attachnum',
'unique' => [],
- 'index' => [ ['custnum'] ],
+ 'index' => [ ['custnum'], ['usernum'], ],
},
'cust_bill' => {
@@ -650,7 +651,8 @@ sub tables_hashref {
'custnum', 'int', '', '', '', '',
'_date', @date_type, '', '',
'amount', @money_type, '', '',
- 'otaker', 'varchar', '', 32, '', '',
+ 'otaker', 'varchar', 'NULL', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
'reason', 'text', 'NULL', '', '', '',
'reasonnum', 'int', 'NULL', '', '', '',
'addlinfo', 'text', 'NULL', '', '', '',
@@ -659,7 +661,7 @@ sub tables_hashref {
],
'primary_key' => 'crednum',
'unique' => [],
- 'index' => [ ['custnum'], ['_date'] ],
+ 'index' => [ ['custnum'], ['_date'], ['usernum'] ],
},
'cust_credit_bill' => {
@@ -755,7 +757,8 @@ sub tables_hashref {
'geocode', 'varchar', 'NULL', 20, '', '',
'censustract', 'varchar', 'NULL', 20, '', '', # 7 to save space?
'tax', 'char', 'NULL', 1, '', '',
- 'otaker', 'varchar', '', 32, '', '',
+ 'otaker', 'varchar', 'NULL', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
'refnum', 'int', '', '', '', '',
'referral_custnum', 'int', 'NULL', '', '', '',
'comments', 'text', 'NULL', '', '', '',
@@ -770,7 +773,7 @@ sub tables_hashref {
'unique' => [ [ 'agentnum', 'agent_custid' ] ],
#'index' => [ ['last'], ['company'] ],
'index' => [
- [ 'agentnum' ], [ 'refnum' ], [ 'classnum' ],
+ [ 'agentnum' ], [ 'refnum' ], [ 'classnum' ], [ 'usernum' ],
[ 'custbatch' ],
[ 'referral_custnum' ],
[ 'payby' ], [ 'paydate' ],
@@ -924,12 +927,13 @@ sub tables_hashref {
'notenum', 'serial', '', '', '', '',
'custnum', 'int', '', '', '', '',
'_date', @date_type, '', '',
- 'otaker', 'varchar', '', 32, '', '',
+ 'otaker', 'varchar', 'NULL', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
'comments', 'text', 'NULL', '', '', '',
],
'primary_key' => 'notenum',
'unique' => [],
- 'index' => [ [ 'custnum' ], [ '_date' ], ],
+ 'index' => [ [ 'custnum' ], [ '_date' ], [ 'usernum' ], ],
},
'cust_category' => {
@@ -1127,7 +1131,8 @@ sub tables_hashref {
'custnum', 'int', '', '', '', '',
'_date', @date_type, '', '',
'paid', @money_type, '', '',
- 'otaker', 'varchar', 'NULL', 32, '', '', #NULL for the upgrade so we can create & populate the field
+ 'otaker', 'varchar', 'NULL', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
'payby', 'char', '', 4, '', '', # CARD/BILL/COMP, should be
# index into payby table
# eventually
@@ -1141,7 +1146,7 @@ sub tables_hashref {
],
'primary_key' => 'paynum',
#i guess not now, with cust_pay_pending, if we actually make it here, we _do_ want to record it# 'unique' => [ [ 'payunique' ] ],
- 'index' => [ [ 'custnum' ], [ 'paybatch' ], [ 'payby' ], [ '_date' ] ],
+ 'index' => [ [ 'custnum' ], [ 'paybatch' ], [ 'payby' ], [ '_date' ], [ 'usernum' ] ],
},
'cust_pay_void' => {
@@ -1161,10 +1166,11 @@ sub tables_hashref {
'void_date', @date_type, '', '',
'reason', 'varchar', 'NULL', $char_d, '', '',
'otaker', 'varchar', '', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
],
'primary_key' => 'paynum',
'unique' => [],
- 'index' => [ [ 'custnum' ] ],
+ 'index' => [ [ 'custnum' ], [ 'usernum' ], ],
},
'cust_bill_pay' => {
@@ -1259,7 +1265,8 @@ sub tables_hashref {
'custnum', 'int', '', '', '', '',
'pkgpart', 'int', '', '', '', '',
'locationnum', 'int', 'NULL', '', '', '',
- 'otaker', 'varchar', '', 32, '', '',
+ 'otaker', 'varchar', 'NULL', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
'start_date', @date_type, '', '',
'setup', @date_type, '', '',
'bill', @date_type, '', '',
@@ -1278,7 +1285,7 @@ sub tables_hashref {
],
'primary_key' => 'pkgnum',
'unique' => [],
- 'index' => [ ['custnum'], ['pkgpart'], [ 'locationnum' ],
+ 'index' => [ ['custnum'], ['pkgpart'], [ 'locationnum' ], [ 'usernum' ],
[ 'start_date' ], ['setup'], ['last_bill'], ['bill'],
['susp'], ['adjourn'], ['expire'], ['cancel'],
['change_date'],
@@ -1316,12 +1323,13 @@ sub tables_hashref {
'pkgnum', 'int', '', '', '', '',
'reasonnum','int', '', '', '', '',
'action', 'char', 'NULL', 1, '', '', #should not be nullable
- 'otaker', 'varchar', '', 32, '', '',
+ 'otaker', 'varchar', 'NULL', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
'date', @date_type, '', '',
],
'primary_key' => 'num',
'unique' => [],
- 'index' => [ [ 'pkgnum' ], [ 'reasonnum' ], ['action'], ],
+ 'index' => [ [ 'pkgnum' ], [ 'reasonnum' ], ['action'], [ 'usernum' ], ],
},
'cust_pkg_discount' => {
@@ -1331,12 +1339,13 @@ sub tables_hashref {
'discountnum', 'int', '', '', '', '',
'months_used', 'decimal', 'NULL', '', '', '',
'end_date', @date_type, '', '',
- 'otaker', 'varchar', '', 32, '', '',
+ 'otaker', 'varchar', 'NULL', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
'disabled', 'char', 'NULL', 1, '', '',
],
'primary_key' => 'pkgdiscountnum',
'unique' => [],
- 'index' => [ [ 'pkgnum' ], [ 'discountnum' ] ],
+ 'index' => [ [ 'pkgnum' ], [ 'discountnum' ], [ 'usernum' ], ],
},
'cust_bill_pkg_discount' => {
@@ -1373,7 +1382,8 @@ sub tables_hashref {
'custnum', 'int', '', '', '', '',
'_date', @date_type, '', '',
'refund', @money_type, '', '',
- 'otaker', 'varchar', '', 32, '', '',
+ 'otaker', 'varchar', 'NULL', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
'reason', 'varchar', '', $char_d, '', '',
'payby', 'char', '', 4, '', '', # CARD/BILL/COMP, should
# be index into payby
@@ -1385,7 +1395,7 @@ sub tables_hashref {
],
'primary_key' => 'refundnum',
'unique' => [],
- 'index' => [ ['custnum'], ['_date'] ],
+ 'index' => [ ['custnum'], ['_date'], [ 'usernum' ], ],
},
'cust_credit_refund' => {
@@ -2286,12 +2296,13 @@ sub tables_hashref {
'payinfo', 'varchar', '', 128, '', '', #say, a 512-big digest _hex encoded
#'paymask', 'varchar', 'NULL', $char_d, '', ''
'_date', @date_type, '', '',
- 'otaker', 'varchar', '', 32, '', '',
+ 'otaker', 'varchar', 'NULL', 32, '', '',
+ 'usernum', 'int', 'NULL', '', '', '',
'reason', 'varchar', 'NULL', $char_d, '', '',
],
'primary_key' => 'bannum',
'unique' => [ [ 'payby', 'payinfo' ] ],
- 'index' => [],
+ 'index' => [ [ 'usernum' ] ],
},
'pkg_category' => {
@@ -2537,11 +2548,12 @@ sub tables_hashref {
'_password', 'varchar', '', $char_d, '', '',
'last', 'varchar', '', $char_d, '', '',
'first', 'varchar', '', $char_d, '', '',
+ 'user_custnum', 'int', 'NULL', '', '', '',
'disabled', 'char', 'NULL', 1, '', '',
],
'primary_key' => 'usernum',
'unique' => [ [ 'username' ] ],
- 'index' => [],
+ 'index' => [ [ 'user_custnum' ] ],
},
'access_user_pref' => {
diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index e5b0b44..576676f 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -140,6 +140,19 @@ sub upgrade_data {
#cdrbatch fixes
'cdr' => [],
+ #otaker->usernum
+ 'cust_attachment' => [],
+ #'cust_credit' => [],
+ #'cust_main' => [],
+ 'cust_main_note' => [],
+ #'cust_pay' => [],
+ 'cust_pay_void' => [],
+ 'cust_pkg' => [],
+ #'cust_pkg_reason' => [],
+ 'cust_pkg_discount' => [],
+ 'cust_refund' => [],
+ 'banned_pay' => [],
+
;
\%hash;
diff --git a/FS/FS/access_user.pm b/FS/FS/access_user.pm
index 8cc8b64..1bf6e93 100644
--- a/FS/FS/access_user.pm
+++ b/FS/FS/access_user.pm
@@ -10,6 +10,7 @@ use FS::option_Common;
use FS::access_user_pref;
use FS::access_usergroup;
use FS::agent;
+use FS::cust_main;
@ISA = qw( FS::m2m_Common FS::option_Common FS::Record );
#@ISA = qw( FS::m2m_Common FS::option_Common );
@@ -220,6 +221,9 @@ sub replace {
$dbh->rollback or die $dbh->errstr if $oldAutoCommit;
return $error;
}
+ } elsif ( $old->disabled && !$new->disabled
+ && $new->_password =~ /changeme/i ) {
+ return "Must change password when enabling this account";
}
my $error = $new->SUPER::replace($old, @_);
@@ -254,6 +258,7 @@ sub check {
|| $self->ut_text('_password')
|| $self->ut_text('last')
|| $self->ut_text('first')
+ || $self->ut_foreign_keyn('user_custnum', 'cust_main', 'custnum')
|| $self->ut_enum('disabled', [ '', 'Y' ] )
;
return $error if $error;
@@ -272,6 +277,18 @@ sub name {
$self->get('last'). ', '. $self->first;
}
+=item user_cust_main
+
+Returns the FS::cust_main object (see L<FS::cust_main>), if any, for this
+user.
+
+=cut
+
+sub user_cust_main {
+ my $self = shift;
+ qsearchs( 'cust_main', { 'custnum' => $self->user_custnum } );
+}
+
=item access_usergroup
Returns links to the the groups this user is a part of, as FS::access_usergroup
diff --git a/FS/FS/banned_pay.pm b/FS/FS/banned_pay.pm
index 1ad87f5..a862028 100644
--- a/FS/FS/banned_pay.pm
+++ b/FS/FS/banned_pay.pm
@@ -1,12 +1,10 @@
package FS::banned_pay;
use strict;
-use vars qw( @ISA );
+use base qw( FS::otaker_Mixin FS::Record );
use FS::Record qw( qsearch qsearchs );
use FS::UID qw( getotaker );
-@ISA = qw(FS::Record);
-
=head1 NAME
FS::banned_pay - Object methods for banned_pay records
@@ -117,11 +115,17 @@ sub check {
$self->_date(time) unless $self->_date;
- $self->otaker(getotaker);
+ $self->otaker(getotaker) unless $self->otaker;
$self->SUPER::check;
}
+# 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
diff --git a/FS/FS/cust_attachment.pm b/FS/FS/cust_attachment.pm
index 9527381..8a39883 100644
--- a/FS/FS/cust_attachment.pm
+++ b/FS/FS/cust_attachment.pm
@@ -1,7 +1,7 @@
package FS::cust_attachment;
use strict;
-use base qw( FS::Record );
+use base qw( FS::otaker_Mixin FS::Record );
use FS::Record qw( qsearch qsearchs );
use FS::Conf;
@@ -44,9 +44,9 @@ Customer number (see L<FS::cust_main>).
The date the record was last updated.
-=item otaker
+=item usernum
-Order taker (assigned automatically; see L<FS::UID>).
+Order taker (see L<FS::access_user>)
=item filename
@@ -128,7 +128,7 @@ sub check {
$self->ut_numbern('attachnum')
|| $self->ut_number('custnum')
|| $self->ut_numbern('_date')
- || $self->ut_text('otaker')
+ || $self->ut_alphan('otaker')
|| $self->ut_text('filename')
|| $self->ut_text('mime_type')
|| $self->ut_numbern('disabled')
@@ -154,6 +154,12 @@ sub size {
return length($self->body);
}
+# 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
diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index fda10de..a7de397 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -1,12 +1,12 @@
package FS::cust_credit;
use strict;
-use vars qw( @ISA $conf $unsuspendauto $me $DEBUG );
+use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::Record );
+use vars qw( $conf $unsuspendauto $me $DEBUG );
use Date::Format;
use FS::UID qw( dbh getotaker );
use FS::Misc qw(send_email);
use FS::Record qw( qsearch qsearchs dbdef );
-use FS::cust_main_Mixin;
use FS::cust_main;
use FS::cust_pkg;
use FS::cust_refund;
@@ -15,7 +15,6 @@ use FS::part_pkg;
use FS::reason_type;
use FS::reason;
-@ISA = qw( FS::cust_main_Mixin FS::Record );
$me = '[ FS::cust_credit ]';
$DEBUG = 0;
@@ -76,9 +75,9 @@ Amount of the credit
Specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
L<Time::Local> and L<Date::Parse> for conversion functions.
-=item otaker
+=item usernum
-Order taker (assigned automatically, see L<FS::UID>)
+Order taker (see L<FS::access_user>)
=item reason
@@ -152,7 +151,7 @@ sub insert {
);
unless($result) {
$dbh->rollback if $oldAutoCommit;
- return "failed to set reason for $me: ". $dbh->errstr;
+ return "failed to set reason for $me"; #: ". $dbh->errstr;
}
}
@@ -295,7 +294,7 @@ sub check {
|| $self->ut_number('custnum')
|| $self->ut_numbern('_date')
|| $self->ut_money('amount')
- || $self->ut_alpha('otaker')
+ || $self->ut_alphan('otaker')
|| $self->ut_textn('reason')
|| $self->ut_foreign_key('reasonnum', 'reason', 'reasonnum')
|| $self->ut_textn('addlinfo')
@@ -325,6 +324,7 @@ Returns all refund applications (see L<FS::cust_credit_refund>) for this credit.
sub cust_credit_refund {
my $self = shift;
+ map { $_ } #return $self->num_cust_credit_refund unless wantarray;
sort { $a->_date <=> $b->_date }
qsearch( 'cust_credit_refund', { 'crednum' => $self->crednum } )
;
@@ -339,6 +339,7 @@ credit.
sub cust_credit_bill {
my $self = shift;
+ map { $_ } #return $self->num_cust_credit_bill unless wantarray;
sort { $a->_date <=> $b->_date }
qsearch( 'cust_credit_bill', { 'crednum' => $self->crednum } )
;
@@ -416,7 +417,11 @@ sub reason {
'reason' => $value,
'disabled' => 'Y',
} );
- $reason->insert and $reason = undef;
+ my $error = $reason->insert;
+ if ( $error ) {
+ warn "error inserting reason: $error\n";
+ $reason = undef;
+ }
}
$self->reasonnum($reason ? $reason->reasonnum : '') ;
@@ -541,7 +546,7 @@ sub _upgrade_data { # class method
}
}
- '';
+ $class->_upgrade_otaker(%opts);
}
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 2574ca7..81b654c 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -2,7 +2,8 @@ package FS::cust_main;
require 5.006;
use strict;
-use vars qw( @ISA @EXPORT_OK $DEBUG $me $conf
+use base qw( FS::otaker_Mixin FS::payinfo_Mixin FS::Record );
+use vars qw( @EXPORT_OK $DEBUG $me $conf
@encrypted_fields
$import $ignore_expired_card
$skip_fuzzyfiles @fuzzyfields
@@ -25,7 +26,7 @@ use String::Approx qw(amatch);
use Business::CreditCard 0.28;
use Locale::Country;
use FS::UID qw( getotaker dbh driver_name );
-use FS::Record qw( qsearchs qsearch dbdef );
+use FS::Record qw( qsearchs qsearch dbdef regexp_sql );
use FS::Misc qw( generate_email send_email generate_ps do_print );
use FS::Msgcat qw(gettext);
use FS::payby;
@@ -66,11 +67,8 @@ use FS::type_pkgs;
use FS::payment_gateway;
use FS::agent_payment_gateway;
use FS::banned_pay;
-use FS::payinfo_Mixin;
use FS::TicketSystem;
-@ISA = qw( FS::payinfo_Mixin FS::Record );
-
@EXPORT_OK = qw( smart_search );
$realtime_bop_decline_quiet = 0;
@@ -304,9 +302,9 @@ IP address from which payment information was received
Tax exempt, empty or `Y'
-=item otaker
+=item usernum
-Order taker (assigned automatically, see L<FS::UID>)
+Order taker (see L<FS::access_user>)
=item comments
@@ -9710,14 +9708,7 @@ sub _agent_plandata {
my $agentnum = $self->agentnum;
- my $regexp = '';
- if ( driver_name =~ /^Pg/i ) {
- $regexp = '~';
- } elsif ( driver_name =~ /^mysql/i ) {
- $regexp = 'REGEXP';
- } else {
- die "don't know how to use regular expressions in ". driver_name. " databases";
- }
+ my $regexp = regexp_sql();
my $part_event_option =
qsearchs({
@@ -9783,6 +9774,8 @@ sub _upgrade_data { #class method
my $sth = dbh->prepare($sql) or die dbh->errstr;
$sth->execute or die $sth->errstr;
+ $class->_upgrade_otaker(%opts);
+
}
=back
diff --git a/FS/FS/cust_main_note.pm b/FS/FS/cust_main_note.pm
index 4732d12..43c9d56 100644
--- a/FS/FS/cust_main_note.pm
+++ b/FS/FS/cust_main_note.pm
@@ -1,11 +1,9 @@
package FS::cust_main_note;
use strict;
-use vars qw( @ISA );
+use base qw( FS::otaker_Mixin FS::Record );
use FS::Record qw( qsearch qsearchs );
-@ISA = qw(FS::Record);
-
=head1 NAME
FS::cust_main_note - Object methods for cust_main_note records
@@ -33,16 +31,17 @@ currently supported:
=over 4
-=item notenum - primary key
+=item notenum
-=item custnum -
+primary key
-=item _date -
+=item custnum
-=item otaker -
+=item _date
-=item comments -
+=item usernum
+=item comments
=back
@@ -107,7 +106,7 @@ sub check {
$self->ut_numbern('notenum')
|| $self->ut_number('custnum')
|| $self->ut_numbern('_date')
- || $self->ut_text('otaker')
+ || $self->ut_alphan('otaker')
|| $self->ut_anything('comments')
;
return $error if $error;
@@ -115,6 +114,12 @@ sub check {
$self->SUPER::check;
}
+# 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
diff --git a/FS/FS/cust_pay_void.pm b/FS/FS/cust_pay_void.pm
index 86fbbe5..fa851e1 100644
--- a/FS/FS/cust_pay_void.pm
+++ b/FS/FS/cust_pay_void.pm
@@ -1,6 +1,8 @@
package FS::cust_pay_void;
+
use strict;
-use vars qw( @ISA @encrypted_fields );
+use base qw( FS::otaker_Mixin FS::payinfo_Mixin FS::Record );
+use vars qw( @encrypted_fields );
use Business::CreditCard;
use FS::UID qw(getotaker);
use FS::Record qw(qsearchs dbh fields); # qsearch );
@@ -11,8 +13,6 @@ use FS::cust_pay;
#use FS::cust_main;
use FS::cust_pkg;
-@ISA = qw( FS::Record FS::payinfo_Mixin );
-
@encrypted_fields = ('payinfo');
=head1 NAME
@@ -58,6 +58,10 @@ Amount of this payment
specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
L<Time::Local> and L<Date::Parse> for conversion functions.
+=item otaker
+
+order taker (see L<FS::access_user>)
+
=item payby
`CARD' (credit cards), `CHEK' (electronic check/ACH),
@@ -215,7 +219,7 @@ sub check {
return $error if $error;
}
- $self->otaker(getotaker);
+ $self->otaker(getotaker) unless $self->otaker;
$self->SUPER::check;
}
@@ -231,6 +235,12 @@ sub cust_main {
qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
}
+# 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
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 5271d49..e9cc7d9 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -1,10 +1,9 @@
package FS::cust_pkg;
use strict;
-use base qw( FS::cust_main_Mixin FS::location_Mixin
- FS::m2m_Common FS::option_Common FS::Record
- );
-use vars qw(@ISA $disable_agentcheck $DEBUG $me);
+use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::location_Mixin
+ FS::m2m_Common FS::option_Common FS::Record );
+use vars qw($disable_agentcheck $DEBUG $me);
use Carp qw(cluck);
use Scalar::Util qw( blessed );
use List::Util qw(max);
@@ -157,9 +156,9 @@ date
date
-=item otaker
+=item usernum
-order taker (assigned automatically if null, see L<FS::UID>)
+order taker (see L<FS::access_user>)
=item manual_flag
@@ -425,7 +424,7 @@ sub replace {
: { @_ };
#return "Can't (yet?) change pkgpart!" if $old->pkgpart != $new->pkgpart;
- return "Can't change otaker!" if $old->otaker ne $new->otaker;
+ #return "Can't change otaker!" if $old->otaker ne $new->otaker;
#allow this *sigh*
#return "Can't change setup once it exists!"
@@ -565,8 +564,6 @@ sub check {
}
$self->otaker(getotaker) unless $self->otaker;
- $self->otaker =~ /^(\w{1,32})$/ or return "Illegal otaker";
- $self->otaker($1);
if ( $self->dbdef_table->column('manual_flag') ) {
$self->manual_flag('') if $self->manual_flag eq ' ';
@@ -3127,6 +3124,12 @@ sub bulk_change {
'';
}
+# 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
diff --git a/FS/FS/cust_pkg_discount.pm b/FS/FS/cust_pkg_discount.pm
index 1b97bba..3770a2b 100644
--- a/FS/FS/cust_pkg_discount.pm
+++ b/FS/FS/cust_pkg_discount.pm
@@ -1,7 +1,7 @@
package FS::cust_pkg_discount;
use strict;
-use base qw( FS::cust_main_Mixin FS::Record );
+use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::Record );
use FS::Record qw( dbh qsearchs ); # qsearch );
use FS::cust_pkg;
use FS::discount;
@@ -53,9 +53,9 @@ months_used
end_date
-=item otaker
+=item usernum
-otaker
+order taker, see L<FS::access_user>
=back
@@ -164,7 +164,7 @@ sub check {
|| $self->ut_foreign_key('discountnum', 'discount', 'discountnum' )
|| $self->ut_float('months_used') #actually decimal, but this will do
|| $self->ut_numbern('end_date')
- || $self->ut_text('otaker')
+ || $self->ut_alphan('otaker')
|| $self->ut_enum('disabled', [ '', 'Y' ] )
;
return $error if $error;
@@ -226,6 +226,12 @@ sub status {
}
}
+# 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
diff --git a/FS/FS/cust_pkg_reason.pm b/FS/FS/cust_pkg_reason.pm
index bb0542b..1ec5024 100644
--- a/FS/FS/cust_pkg_reason.pm
+++ b/FS/FS/cust_pkg_reason.pm
@@ -1,11 +1,9 @@
package FS::cust_pkg_reason;
use strict;
-use vars qw( @ISA );
+use base qw( FS::otaker_Mixin FS::Record );
use FS::Record qw( qsearch qsearchs );
-@ISA = qw(FS::Record);
-
=head1 NAME
FS::cust_pkg_reason - Object methods for cust_pkg_reason records
@@ -34,16 +32,17 @@ currently supported:
=over 4
-=item num - primary key
+=item num
-=item pkgnum -
+primary key
-=item reasonnum -
+=item pkgnum
-=item otaker -
+=item reasonnum
-=item date -
+=item usernum
+=item date
=back
@@ -99,7 +98,7 @@ sub check {
|| $self->ut_number('pkgnum')
|| $self->ut_number('reasonnum')
|| $self->ut_enum('action', [ 'A', 'C', 'E', 'S' ])
- || $self->ut_text('otaker')
+ || $self->ut_alphan('otaker')
|| $self->ut_numbern('date')
;
return $error if $error;
@@ -307,8 +306,7 @@ sub _upgrade_data { # class method
}
}
- '';
-
+ $class->_upgrade_otaker(%opts);
}
=back
diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm
index abc131e..e7c5a82 100644
--- a/FS/FS/cust_refund.pm
+++ b/FS/FS/cust_refund.pm
@@ -1,19 +1,17 @@
package FS::cust_refund;
use strict;
-use vars qw( @ISA @encrypted_fields );
+use base qw( FS::otaker_Mixin FS::payinfo_transaction_Mixin FS::cust_main_Mixin
+ FS::Record );
+use vars qw( @encrypted_fields );
use Business::CreditCard;
use FS::UID qw(getotaker);
use FS::Record qw( qsearch qsearchs dbh );
-use FS::cust_main_Mixin;
-use FS::payinfo_transaction_Mixin;
use FS::cust_credit;
use FS::cust_credit_refund;
use FS::cust_pay_refund;
use FS::cust_main;
-@ISA = qw( FS::payinfo_transaction_Mixin FS::cust_main_Mixin FS::Record );
-
@encrypted_fields = ('payinfo');
=head1 NAME
@@ -43,28 +41,50 @@ inherits from FS::Record. The following fields are currently supported:
=over 4
-=item refundnum - primary key (assigned automatically for new refunds)
+=item refundnum
+
+primary key (assigned automatically for new refunds)
+
+=item custnum
+
+customer (see L<FS::cust_main>)
-=item custnum - customer (see L<FS::cust_main>)
+=item refund
-=item refund - Amount of the refund
+Amount of the refund
-=item reason - Reason for the refund
+=item reason
-=item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
+Reason for the refund
+
+=item _date
+
+specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
L<Time::Local> and L<Date::Parse> for conversion functions.
-=item payby - Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
+=item payby
+
+Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
-=item payinfo - Payment Information (See L<FS::payinfo_Mixin> for data format)
+=item payinfo
-=item paymask - Masked payinfo (See L<FS::payinfo_Mixin> for how this works)
+Payment Information (See L<FS::payinfo_Mixin> for data format)
-=item paybatch - text field for tracking card processing
+=item paymask
-=item otaker - order taker (assigned automatically, see L<FS::UID>)
+Masked payinfo (See L<FS::payinfo_Mixin> for how this works)
-=item closed - books closed flag, empty or `Y'
+=item paybatch
+
+text field for tracking card processing
+
+=item usernum
+
+order taker (see L<FS::access_user>
+
+=item closed
+
+books closed flag, empty or `Y'
=back
@@ -236,13 +256,13 @@ returns the error, otherwise returns false. Called by the insert method.
sub check {
my $self = shift;
- $self->otaker(getotaker) unless ($self->otaker);
+ $self->otaker(getotaker) unless $self->otaker;
my $error =
$self->ut_numbern('refundnum')
|| $self->ut_numbern('custnum')
|| $self->ut_money('refund')
- || $self->ut_alpha('otaker')
+ || $self->ut_alphan('otaker')
|| $self->ut_text('reason')
|| $self->ut_numbern('_date')
|| $self->ut_textn('paybatch')
@@ -273,6 +293,7 @@ refund.
sub cust_credit_refund {
my $self = shift;
+ map { $_ } #return $self->num_cust_credit_refund unless wantarray;
sort { $a->_date <=> $b->_date }
qsearch( 'cust_credit_refund', { 'refundnum' => $self->refundnum } )
;
@@ -287,6 +308,7 @@ refund.
sub cust_pay_refund {
my $self = shift;
+ map { $_ } #return $self->num_cust_pay_refund unless wantarray;
sort { $a->_date <=> $b->_date }
qsearch( 'cust_pay_refund', { 'refundnum' => $self->refundnum } )
;
@@ -338,6 +360,12 @@ sub unapplied_sql {
}
+# 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
diff --git a/FS/FS/otaker_Mixin.pm b/FS/FS/otaker_Mixin.pm
new file mode 100644
index 0000000..071958c
--- /dev/null
+++ b/FS/FS/otaker_Mixin.pm
@@ -0,0 +1,67 @@
+package FS::otaker_Mixin;
+
+use strict;
+use Carp qw( croak ); #confess );
+use FS::Record qw( qsearch qsearchs );
+use FS::access_user;
+
+sub otaker {
+ my $self = shift;
+ if ( scalar(@_) ) { #set
+ my $otaker = shift;
+ my $access_user = qsearchs('access_user', { 'username' => $otaker } )
+ 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 {
+ '';
+ }
+ }
+}
+
+sub access_user {
+ my $self = shift;
+ qsearchs('access_user', { 'usernum' => $self->usernum } );
+}
+
+sub _upgrade_otaker {
+ my $class = shift;
+ my $table = $class->table;
+
+ while ( 1 ) {
+ my @records = qsearch({
+ 'table' => $table,
+ 'hashref' => {},
+ 'extra_sql' => 'WHERE otaker IS NOT NULL LIMIT 1000',
+ });
+ last unless @records;
+
+ foreach my $record (@records) {
+ eval { $record->otaker($record->otaker) };
+ if ( $@ ) {
+ my $access_user = new FS::access_user {
+ 'username' => $record->otaker,
+ '_password' => 'CHANGEME',
+ 'first' => 'Legacy',
+ 'last' => 'User',
+ 'disabled' => 'Y',
+ };
+ my $error = $access_user->insert;
+ die $error if $error;
+ $record->otaker($record->otaker);
+ }
+ $record->set('otaker', '');
+ my $error = $record->replace;
+ die $error if $error;
+ }
+
+ }
+
+}
+
+1;