X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pay.pm;h=acb2844290b39934a652f8ee14df5423f2b3b404;hb=41ed76e0e3625c9f175743d253ad06fc67302d0f;hp=2b2e9442a08fc089d23ce80851edcf68586d7af4;hpb=0b4247f88f8a290a7bbbdebe93404baef2d1e29d;p=freeside.git diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 2b2e9442a..acb284429 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -1,11 +1,14 @@ package FS::cust_pay; use strict; -use vars qw( @ISA $conf $unsuspendauto $ignore_noapply @encrypted_fields ); +use vars qw( @ISA $DEBUG $me $conf @encrypted_fields + $unsuspendauto $ignore_noapply + ); use Date::Format; use Business::CreditCard; use Text::Template; -use FS::Misc qw(send_email); +use FS::UID qw( getotaker ); +use FS::Misc qw( send_email ); use FS::Record qw( dbh qsearch qsearchs ); use FS::payby; use FS::cust_main_Mixin; @@ -18,6 +21,10 @@ use FS::cust_pay_void; @ISA = qw(FS::Record FS::cust_main_Mixin FS::payinfo_Mixin ); +$DEBUG = 0; + +$me = '[FS::cust_pay]'; + $ignore_noapply = 0; #ask FS::UID to run this stuff for us later @@ -59,11 +66,13 @@ currently supported: =item custnum - customer (see L) -=item paid - Amount of this payment - =item _date - specified as a UNIX timestamp; see L. Also see L and L for conversion functions. +=item paid - Amount of this payment + +=item otaker - order taker (assigned automatically, see L) + =item payby - Payment Type (See L for valid payby values) =item payinfo - Payment Information (See L for data format) @@ -389,11 +398,14 @@ returns the error, otherwise returns false. Called by the insert method. sub check { my $self = shift; + $self->otaker(getotaker) unless ($self->otaker); + my $error = $self->ut_numbern('paynum') || $self->ut_numbern('custnum') - || $self->ut_money('paid') || $self->ut_numbern('_date') + || $self->ut_money('paid') + || $self->ut_alpha('otaker') || $self->ut_textn('paybatch') || $self->ut_textn('payunique') || $self->ut_enum('closed', [ '', 'Y' ]) @@ -648,6 +660,64 @@ sub unapplied_sql { } +# _upgrade_data +# +# Used by FS::Upgrade to migrate to a new database. + +use FS::h_cust_pay; + +sub _upgrade_data { #class method + my ($class, %opts) = @_; + + warn "$me upgrading $class\n" if $DEBUG; + + #not the most efficient, but hey, it only has to run once + + my $where = "WHERE otaker IS NULL OR otaker = '' OR otaker = 'ivan' "; + + my $count_sql = "SELECT COUNT(*) FROM cust_pay $where"; + + my $sth = dbh->prepare($count_sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + my $total = $sth->fetchrow_arrayref->[0]; + + local($DEBUG) = 2 if $total > 1000; #could be a while, force progress info + + my $count = 0; + my $lastprog = 0; + while (1) { + + my $cust_pay = qsearchs( { + 'table' => 'cust_pay', + 'hashref' => {}, + 'extra_sql' => $where, + 'order_by' => 'ORDER BY paynum LIMIT 1', + } ); + + return unless $cust_pay; + + my $h_cust_pay = $cust_pay->h_search('insert'); + if ( $h_cust_pay ) { + $cust_pay->otaker($h_cust_pay->history_user); + } else { + $cust_pay->otaker('legacy'); + } + + delete $FS::payby::hash{'COMP'}->{cust_pay}; #quelle kludge + my $error = $cust_pay->replace; + die $error if $error; + $FS::payby::hash{'COMP'}->{cust_pay} = ''; #restore it + + $count++; + if ( $DEBUG > 1 && $lastprog + 30 < time ) { + warn "$me $count/$total (". sprintf('%.2f',100*$count/$total). '%)'. "\n"; + $lastprog = time; + } + + } + +} + =back =head1 SUBROUTINES