svc_hardware: better error messages for bad hw_addr when not validating as a MAC...
[freeside.git] / FS / FS / vend_bill_pay.pm
1 package FS::vend_bill_pay;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::Record qw( dbh ); #qsearch #qsearchs );
6
7 =head1 NAME
8
9 FS::vend_bill_pay - Object methods for vend_bill_pay records
10
11 =head1 SYNOPSIS
12
13   use FS::vend_bill_pay;
14
15   $record = new FS::vend_bill_pay \%hash;
16   $record = new FS::vend_bill_pay { '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::vend_bill_pay object represents the application of a vendor payment to a
29 specific invoice or payment. FS::vend_bill_pay inherits from FS::Record.  The
30 following fields are currently supported:
31
32 =over 4
33
34 =item vendbillpaynum
35
36 primary key
37
38 =item vendbillnum
39
40 vendbillnum
41
42 =item vendpaynum
43
44 vendpaynum
45
46 =item amount
47
48 amount
49
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new record.  To add the record to the database, see L<"insert">.
60
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to.  You can ask the object for a copy with the I<hash> method.
63
64 =cut
65
66 sub table { 'vend_bill_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 =item delete
74
75 Delete this record from the database.
76
77 =cut
78
79 sub delete {
80   my $self = shift;
81
82   my $oldAutoCommit = $FS::UID::AutoCommit;
83   local $FS::UID::AutoCommit = 0;
84   my $dbh = dbh;
85
86   my $error = $self->SUPER::delete;
87   if ( $error ) {
88     $dbh->rollback if $oldAutoCommit;
89     return $error;
90   }
91
92   #magically auto-deleting for the simple case
93   foreach my $vend_pay ( $self->vend_pay ) {
94     my $error = $vend_pay->delete;
95     if ( $error ) {
96       $dbh->rollback if $oldAutoCommit;
97       return $error;
98     }
99   }
100
101   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
102   '';
103
104 }
105
106
107 =item replace OLD_RECORD
108
109 Replaces the OLD_RECORD with this one in the database.  If there is an error,
110 returns the error, otherwise returns false.
111
112 =item check
113
114 Checks all fields to make sure this is a valid record.  If there is
115 an error, returns the error, otherwise returns false.  Called by the insert
116 and replace methods.
117
118 =cut
119
120 sub check {
121   my $self = shift;
122
123   my $error = 
124     $self->ut_numbern('vendbillpaynum')
125     || $self->ut_foreign_key('vendbillnum', 'vend_bill', 'vendbillnum')
126     || $self->ut_foreign_key('vendpaynum', 'vend_pay', 'vendpaynum')
127     || $self->ut_money('amount')
128   ;
129   return $error if $error;
130
131   $self->SUPER::check;
132 }
133
134 =item vend_pay
135
136 =back
137
138 =head1 BUGS
139
140 =head1 SEE ALSO
141
142 L<FS::Record>, schema.html from the base documentation.
143
144 =cut
145
146 1;
147