projects
/
freeside.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
1239c0a
)
credit out self-service
author
ivan
<ivan>
Thu, 1 Jul 2004 13:49:32 +0000
(13:49 +0000)
committer
ivan
<ivan>
Thu, 1 Jul 2004 13:49:32 +0000
(13:49 +0000)
FS/FS/ClientAPI/MyAccount.pm
patch
|
blob
|
history
FS/FS/cust_main.pm
patch
|
blob
|
history
diff --git
a/FS/FS/ClientAPI/MyAccount.pm
b/FS/FS/ClientAPI/MyAccount.pm
index
e8ce6b4
..
58ab6c0
100644
(file)
--- a/
FS/FS/ClientAPI/MyAccount.pm
+++ b/
FS/FS/ClientAPI/MyAccount.pm
@@
-541,6
+541,11
@@
sub order_pkg {
if ( $cust_main->balance > $old_balance
&& $cust_main->payby !~ /^(BILL|DCRD|DCHK)$/ ) {
if ( $cust_main->balance > $old_balance
&& $cust_main->payby !~ /^(BILL|DCRD|DCHK)$/ ) {
+ #this makes sense. credit is "un-doing" the invoice
+ $cust_main->credit( sprintf("%.2f", $cust_main->balance - $old_balance ),
+ 'self-service decline' );
+ $cust_main->apply_credits( 'order' => 'newest' );
+
$cust_pkg->cancel('quiet'=>1);
return { 'error' => '_decline' };
} else {
$cust_pkg->cancel('quiet'=>1);
return { 'error' => '_decline' };
} else {
diff --git
a/FS/FS/cust_main.pm
b/FS/FS/cust_main.pm
index
c3a8ad8
..
740b483
100644
(file)
--- a/
FS/FS/cust_main.pm
+++ b/
FS/FS/cust_main.pm
@@
-1995,28
+1995,30
@@
sub total_owed_date {
sprintf( "%.2f", $total_bill );
}
sprintf( "%.2f", $total_bill );
}
-=item apply_credits
+=item apply_credits
OPTION => VALUE ...
Applies (see L<FS::cust_credit_bill>) unapplied credits (see L<FS::cust_credit>)
Applies (see L<FS::cust_credit_bill>) unapplied credits (see L<FS::cust_credit>)
-to outstanding invoice balances in chronological order and returns the value
-of any remaining unapplied credits available for refund
-(see L<FS::cust_refund>).
+to outstanding invoice balances in chronological order (or reverse
+chronological order if the I<order> option is set to B<newest>) and returns the
+value of any remaining unapplied credits available for refund (see
+L<FS::cust_refund>).
=cut
sub apply_credits {
my $self = shift;
=cut
sub apply_credits {
my $self = shift;
+ my %opt = @_;
return 0 unless $self->total_credited;
my @credits = sort { $b->_date <=> $a->_date} (grep { $_->credited > 0 }
qsearch('cust_credit', { 'custnum' => $self->custnum } ) );
return 0 unless $self->total_credited;
my @credits = sort { $b->_date <=> $a->_date} (grep { $_->credited > 0 }
qsearch('cust_credit', { 'custnum' => $self->custnum } ) );
- my @invoices = sort { $a->_date <=> $b->_date} (grep { $_->owed > 0 }
- qsearch('cust_bill', { 'custnum' => $self->custnum } ) );
+ my @invoices = $self->open_cust_bill;
+ @invoices = sort { $b->_date <=> $a->_date } @invoices
+ if defined($opt{'order'}) && $opt{'order'} eq 'newest';
my $credit;
my $credit;
-
foreach my $cust_bill ( @invoices ) {
my $amount;
foreach my $cust_bill ( @invoices ) {
my $amount;