RT# 83450 - fixed rateplan export
[freeside.git] / FS / FS / cust_bill_pay_batch.pm
1 package FS::cust_bill_pay_batch;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::Record qw( dbh );
6
7 =head1 NAME
8
9 FS::cust_bill_pay_batch - Object methods for cust_bill_pay_batch records
10
11 =head1 SYNOPSIS
12
13   use FS::cust_bill_pay_batch;
14
15   $record = new FS::cust_bill_pay_batch \%hash;
16   $record = new FS::cust_bill_pay_batch { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::cust_bill_pay_batch object represents a relationship between a
29 customer's bill and a batch.  FS::cust_bill_pay_batch inherits from
30 FS::Record.  The following fields are currently supported:
31
32 =over 4
33
34 =item billpaynum - primary key
35
36 =item invnum - customer's bill (invoice)
37
38 =item paybatchnum - entry in cust_pay_batch table
39
40 =item amount - 
41
42 =item _date - 
43
44
45 =back
46
47 =head1 METHODS
48
49 =over 4
50
51 =item new HASHREF
52
53 Creates a new record.  To add the record to the database, see L<"insert">.
54
55 Note that this stores the hash reference, not a distinct copy of the hash it
56 points to.  You can ask the object for a copy with the I<hash> method.
57
58 =cut
59
60 sub table { 'cust_bill_pay_batch'; }
61
62 =item insert
63
64 Adds this record to the database.  If there is an error, returns the error,
65 otherwise returns false.
66
67 =cut
68
69 =item delete
70
71 Delete this record from the database.
72
73 =cut
74
75 =item replace OLD_RECORD
76
77 Replaces the OLD_RECORD with this one in the database.  If there is an error,
78 returns the error, otherwise returns false.
79
80 =cut
81
82 =item check
83
84 Checks all fields to make sure this is a valid example.  If there is
85 an error, returns the error, otherwise returns false.  Called by the insert
86 and replace methods.
87
88 =cut
89
90 sub check {
91   my $self = shift;
92
93   my $error = 
94     $self->ut_numbern('billpaynum')
95     || $self->ut_number('invnum')
96     || $self->ut_number('paybatchnum')
97     || $self->ut_money('amount')
98     || $self->ut_numbern('_date')
99   ;
100   return $error if $error;
101
102   $self->SUPER::check;
103 }
104
105 =back
106
107 =cut
108
109
110 sub _upgrade_schema {
111   my ($class, %opts) = @_;
112
113   my $sql = '
114     DELETE FROM cust_bill_pay_batch WHERE NOT EXISTS
115       ( SELECT 1 FROM cust_pay_batch WHERE cust_pay_batch.paybatchnum = cust_bill_pay_batch.paybatchnum )
116   ';
117
118   my $sth = dbh->prepare($sql) or die dbh->errstr;
119   $sth->execute or die $sth->errstr;
120   '';
121
122 }
123
124
125 =head1 BUGS
126
127 Just hangs there.
128
129 =head1 SEE ALSO
130
131 L<FS::Record>, schema.html from the base documentation.
132
133 =cut
134
135 1;
136