allow payment modification so we can import order_number info
[freeside.git] / FS / FS / cust_pay.pm
index 3317a32..d901c78 100644 (file)
@@ -325,13 +325,7 @@ sub delete {
 
 =item replace OLD_RECORD
 
-Currently unimplemented (accounting reasons).
-
-=cut
-
-sub replace {
-   return "Can't (yet?) modify cust_pay records!";
-}
+You probably shouldn't modify payments...
 
 =item check
 
@@ -396,7 +390,8 @@ payment.
 
 sub cust_bill_pay {
   my $self = shift;
-  sort { $a->_date <=> $b->_date }
+  sort {    $a->_date  <=> $b->_date
+         || $a->invnum <=> $b->invnum }
     qsearch( 'cust_bill_pay', { 'paynum' => $self->paynum } )
   ;
 }
@@ -432,6 +427,21 @@ sub unapplied {
   sprintf("%.2f", $amount );
 }
 
+=item unrefunded
+
+Returns the amount of this payment that has not been refuned; which is
+paid minus all  refund applications (see L<FS::cust_pay_refund>).
+
+=cut
+
+sub unrefunded {
+  my $self = shift;
+  my $amount = $self->paid;
+  $amount -= $_->amount foreach ( $self->cust_pay_refund );
+  sprintf("%.2f", $amount );
+}
+
+
 =item cust_main
 
 Returns the parent customer object (see L<FS::cust_main>).