From 3684dae04773904d5500ef93253c5f4c2f6d7f38 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 14 Feb 2008 03:52:37 +0000 Subject: [PATCH] add cust_pay.otaker field; populate it based on history on upgrades, and show the order taker on all payments (on customer view and payment search) closes: #2953 --- FS/FS/Schema.pm | 3 +- FS/FS/Upgrade.pm | 4 +- FS/FS/cust_pay.pm | 74 ++++++++++++++++++++++++-- httemplate/search/cust_pay.cgi | 11 +++- httemplate/view/cust_main/payment_history.html | 8 ++- 5 files changed, 90 insertions(+), 10 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index eb18964d5..7f8e6dace 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -695,8 +695,9 @@ sub tables_hashref { 'columns' => [ 'paynum', 'serial', '', '', '', '', 'custnum', 'int', '', '', '', '', - 'paid', @money_type, '', '', '_date', @date_type, '', '', + 'paid', @money_type, '', '', + 'otaker', 'varchar', 'NULL', 32, '', '', #NULL for the upgrade so we can create & populate the field 'payby', 'char', '', 4, '', '', # CARD/BILL/COMP, should be # index into payby table # eventually diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index 2e4d2b42b..90e66d87d 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -84,8 +84,10 @@ sub upgrade_data { 'cust_credit' => [], #duplicate history records - 'h_cust_svc' => [], + 'h_cust_svc' => [], + #populate cust_pay.otaker + 'cust_pay' => [], ; \%hash; diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 2b2e9442a..67f34c387 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' ]) @@ -420,6 +432,8 @@ sub check { # " already exists"; # } + $self->otaker(getotaker); + $self->SUPER::check; } @@ -648,6 +662,56 @@ 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 $count_sql = + "SELECT COUNT(*) FROM cust_pay WHERE otaker IS NULL OR otaker = ''"; + + 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 otaker IS NULL OR otaker = ''", + 'order_by' => 'ORDER BY paynum LIMIT 1', + } ); + + return unless $cust_pay; + + my $h_cust_pay = $cust_pay->h_search('insert'); + $cust_pay->otaker($h_cust_pay->history_user); + my $error = $cust_pay->replace; + die $error if $error; + + $count++; + if ( $DEBUG > 1 && $lastprog + 30 < time ) { + warn "$me $count/$total (". sprintf('%.2f',100*$count/$total). '%)'. "\n"; + $lastprog = time; + } + + } + +} + =back =head1 SUBROUTINES diff --git a/httemplate/search/cust_pay.cgi b/httemplate/search/cust_pay.cgi index 2166eb16d..e5465aee8 100755 --- a/httemplate/search/cust_pay.cgi +++ b/httemplate/search/cust_pay.cgi @@ -7,6 +7,7 @@ 'header' => [ 'Payment', 'Amount', 'Date', + 'By', FS::UI::Web::cust_header(), ], 'fields' => [ @@ -32,14 +33,20 @@ }, sub { sprintf('$%.2f', shift->paid ) }, sub { time2str('%b %d %Y', shift->_date ) }, + sub { my $o = shift->otaker; + $o = 'auto billing' if $o eq 'fs_daily'; + $o = 'customer self-service' if $o eq 'fs_selfservice'; + $o; + }, \&FS::UI::Web::cust_fields, ], #'align' => 'lrrrll', - 'align' => 'rrr'.FS::UI::Web::cust_aligns(), + 'align' => 'rrrc'.FS::UI::Web::cust_aligns(), 'links' => [ $link, $link, $link, + '', ( map { $_ ne 'Cust. Status' ? $cust_link : '' } FS::UI::Web::cust_header() ), @@ -48,12 +55,14 @@ '', '', '', + '', FS::UI::Web::cust_colors(), ], 'style' => [ '', '', '', + '', FS::UI::Web::cust_styles(), ], ) diff --git a/httemplate/view/cust_main/payment_history.html b/httemplate/view/cust_main/payment_history.html index cbe143d59..44a888533 100644 --- a/httemplate/view/cust_main/payment_history.html +++ b/httemplate/view/cust_main/payment_history.html @@ -118,7 +118,7 @@ % $payby =~ s/^WEST$/Western Union/; % $payby =~ s/^MCRD$/Manual credit card/; % $payby =~ s/^BILL$//; -% my $info = $payby ? " ($payby$payinfo)" : ''; +% my $info = $payby ? "($payby$payinfo)" : ''; % % my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' ); % if ( scalar(@cust_bill_pay) == 0 @@ -243,9 +243,13 @@ % qq!>unapply)!; % } % +% my $otaker = $cust_pay->otaker; +% $otaker = 'auto billing' if $otaker eq 'fs_daily'; +% $otaker = 'customer self-service' if $otaker eq 'fs_selfservice'; +% % push @history, { % 'date' => $cust_pay->_date, -% 'desc' => $pre. "Payment$post$info$desc". +% 'desc' => $pre. "Payment$post by $otaker $info$desc". % "$view$apply$refund$void$delete$unapply", % 'payment' => $cust_pay->paid, % 'target' => $target, -- 2.11.0