show credit balance on invoices, #11564
[freeside.git] / FS / FS / banned_pay.pm
1 package FS::banned_pay;
2
3 use strict;
4 use base qw( FS::otaker_Mixin FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::UID qw( getotaker );
7 use FS::CurrentUser;
8
9 =head1 NAME
10
11 FS::banned_pay - Object methods for banned_pay records
12
13 =head1 SYNOPSIS
14
15   use FS::banned_pay;
16
17   $record = new FS::banned_pay \%hash;
18   $record = new FS::banned_pay { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::banned_pay object represents an banned credit card or ACH account.
31 FS::banned_pay inherits from FS::Record.  The following fields are currently
32 supported:
33
34 =over 4
35
36 =item bannum - primary key
37
38 =item payby - I<CARD> or I<CHEK>
39
40 =item payinfo - fingerprint of banned card (base64-encoded MD5 digest)
41
42 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
43 L<Time::Local> and L<Date::Parse> for conversion functions.
44
45 =item usernum - order taker (assigned automatically, see L<FS::access_user>)
46
47 =item reason - reason (text)
48
49 =back
50
51 =head1 METHODS
52
53 =over 4
54
55 =item new HASHREF
56
57 Creates a new ban.  To add the ban to the database, see L<"insert">.
58
59 Note that this stores the hash reference, not a distinct copy of the hash it
60 points to.  You can ask the object for a copy with the I<hash> method.
61
62 =cut
63
64 # the new method can be inherited from FS::Record, if a table method is defined
65
66 sub table { 'banned_pay'; }
67
68 =item insert
69
70 Adds this record to the database.  If there is an error, returns the error,
71 otherwise returns false.
72
73 =cut
74
75 # the insert method can be inherited from FS::Record
76
77 =item delete
78
79 Delete this record from the database.
80
81 =cut
82
83 # the delete method can be inherited from FS::Record
84
85 =item replace OLD_RECORD
86
87 Replaces the OLD_RECORD with this one in the database.  If there is an error,
88 returns the error, otherwise returns false.
89
90 =cut
91
92 # the replace method can be inherited from FS::Record
93
94 =item check
95
96 Checks all fields to make sure this is a valid ban.  If there is
97 an error, returns the error, otherwise returns false.  Called by the insert
98 and replace methods.
99
100 =cut
101
102 # the check method should currently be supplied - FS::Record contains some
103 # data checking routines
104
105 sub check {
106   my $self = shift;
107
108   my $error = 
109     $self->ut_numbern('bannum')
110     || $self->ut_enum('payby', [ 'CARD', 'CHEK' ] )
111     || $self->ut_text('payinfo')
112     || $self->ut_numbern('_date')
113     || $self->ut_textn('reason')
114   ;
115   return $error if $error;
116
117   $self->_date(time) unless $self->_date;
118
119   $self->usernum($FS::CurrentUser::CurrentUser->usernum) unless $self->usernum;
120
121   $self->SUPER::check;
122 }
123
124 # Used by FS::Upgrade to migrate to a new database.
125 sub _upgrade_data {  # class method
126   my ($class, %opts) = @_;
127   $class->_upgrade_otaker(%opts);
128 }
129
130 =back
131
132 =head1 BUGS
133
134 =head1 SEE ALSO
135
136 L<FS::Record>, schema.html from the base documentation.
137
138 =cut
139
140 1;
141