1 package FS::cust_credit;
5 use FS::UID qw( getotaker );
6 use FS::Record qw( qsearchs );
10 @ISA = qw( FS::Record );
14 FS::cust_credit - Object methods for cust_credit records
20 $record = new FS::cust_credit \%hash;
21 $record = new FS::cust_credit { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::cust_credit object represents a credit; the equivalent of a negative
34 B<cust_bill> record (see L<FS::cust_bill>). FS::cust_credit inherits from
35 FS::Record. The following fields are currently supported:
39 =item crednum - primary key (assigned automatically for new credits)
41 =item custnum - customer (see L<FS::cust_main>)
43 =item amount - amount of the credit
45 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
46 L<Time::Local> and L<Date::Parse> for conversion functions.
48 =item otaker - order taker (assigned automatically, see L<FS::UID>)
60 Creates a new credit. To add the credit to the database, see L<"insert">.
64 sub table { 'cust_credit'; }
68 Adds this credit to the database ("Posts" the credit). If there is an error,
69 returns the error, otherwise returns false.
73 Currently unimplemented.
78 return "Can't remove credit!"
81 =item replace OLD_RECORD
83 Credits may not be modified; there would then be no record the credit was ever
89 return "Can't modify credit!"
94 Checks all fields to make sure this is a valid credit. If there is an error,
95 returns the error, otherwise returns false. Called by the insert and replace
104 $self->ut_numbern('crednum')
105 || $self->ut_number('custnum')
106 || $self->ut_numbern('_date')
107 || $self->ut_money('amount')
108 || $self->ut_textn('reason');
110 return $error if $error;
112 return "Unknown customer"
113 unless qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
115 $self->_date(time) unless $self->_date;
117 $self->otaker(getotaker);
124 Returns all refunds (see L<FS::cust_refund>) for this credit.
130 sort { $a->_date <=> $b->_date }
131 qsearch( 'cust_refund', { 'crednum' => $self->crednum } )
137 Returns the amount of this credit that is still outstanding; which is
138 amount minus all refunds (see L<FS::cust_refund>).
144 my $amount = $self->amount;
145 $amount -= $_->refund foreach ( $self->cust_refund );
153 $Id: cust_credit.pm,v 1.5 2001-04-23 19:27:28 ivan Exp $
161 L<FS::Record>, L<FS::cust_refund>, L<FS::cust_bill>, schema.html from the base