1 package FS::cust_credit;
5 use FS::UID qw( getotaker );
6 use FS::Record qw( qsearchs );
9 @ISA = qw( FS::Record );
13 FS::cust_credit - Object methods for cust_credit records
19 $record = new FS::cust_credit \%hash;
20 $record = new FS::cust_credit { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::cust_credit object represents a credit. FS::cust_credit inherits from
33 FS::Record. The following fields are currently supported:
37 =item crednum - primary key (assigned automatically for new credits)
39 =item custnum - customer (see L<FS::cust_main>)
41 =item amount - amount of the credit
43 =item credited - how much of this credit that is still outstanding, which is
44 amount minus all refunds (see L<FS::cust_refund>).
46 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
47 L<Time::Local> and L<Date::Parse> for conversion functions.
49 =item otaker - order taker (assigned automatically, see L<FS::UID>)
61 Creates a new credit. To add the credit to the database, see L<"insert">.
65 sub table { 'cust_credit'; }
69 Adds this credit to the database ("Posts" the credit). If there is an error,
70 returns the error, otherwise returns false.
72 When adding new invoices, credited must be amount (or null, in which case it is
73 automatically set to amount).
80 $self->credited($self->amount) if $self->credited eq '';
81 return "credited != amount!"
82 unless $self->credited == $self->amount;
89 Currently unimplemented.
94 return "Can't remove credit!"
97 =item replace OLD_RECORD
99 Replaces the OLD_RECORD with this one in the database. If there is an error,
100 returns the error, otherwise returns false.
102 Only credited may be changed. Credited is normally updated by creating and
103 inserting a refund (see L<FS::cust_refund>).
108 my ( $new, $old ) = ( shift, shift );
110 return "Can't change custnum!" unless $old->custnum eq $new->custnum;
111 return "Can't change date!" unless $old->_date eq $new->_date;
112 return "Can't change amount!" unless $old->amount eq $new->amount;
113 return "(New) credited can't be > (new) amount!"
114 if $new->credited > $new->amount;
116 $new->SUPER::replace($old);
121 Checks all fields to make sure this is a valid credit. If there is an error,
122 returns the error, otherwise returns false. Called by the insert and replace
131 $self->ut_numbern('crednum')
132 || $self->ut_number('custnum')
133 || $self->ut_numbern('_date')
134 || $self->ut_money('amount')
135 || $self->ut_money('credited')
136 || $self->ut_textn('reason');
138 return $error if $error;
140 return "Unknown customer"
141 unless qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
143 $self->_date(time) unless $self->_date;
145 $self->otaker(getotaker);
154 $Id: cust_credit.pm,v 1.2 1998-12-29 11:59:38 ivan Exp $
162 L<FS::Record>, L<FS::cust_refund>, L<FS::cust_bill>, schema.html from the base
167 ivan@sisd.com 98-mar-17
169 pod, otaker from FS::UID ivan@sisd.com 98-sep-21
171 $Log: cust_credit.pm,v $
172 Revision 1.2 1998-12-29 11:59:38 ivan
173 mostly properly OO, some work still to be done with svc_ stuff