show credit balance on invoices, #11564
[freeside.git] / FS / FS / export_device.pm
1 package FS::export_device;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs dbh );
6 use FS::part_export;
7 use FS::part_device;
8
9 =head1 NAME
10
11 FS::export_device - Object methods for export_device records
12
13 =head1 SYNOPSIS
14
15   use FS::export_device;
16
17   $record = new FS::export_device \%hash;
18   $record = new FS::export_device { '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::export_device object links a device definition (see L<FS::part_device>)
31 to an export (see L<FS::part_export>).  FS::export_device inherits from
32 FS::Record.  The following fields are currently supported:
33
34 =over 4
35
36 =item exportdevicenum - primary key
37
38 =item exportnum - export (see L<FS::part_export>)
39
40 =item devicepart - device definition (see L<FS::part_device>)
41
42 =back
43
44 =head1 METHODS
45
46 =over 4
47
48 =item new HASHREF
49
50 Creates a new record.  To add the record to the database, see L<"insert">.
51
52 Note that this stores the hash reference, not a distinct copy of the hash it
53 points to.  You can ask the object for a copy with the I<hash> method.
54
55 =cut
56
57 sub table { 'export_device'; }
58
59 =item insert
60
61 Adds this record to the database.  If there is an error, returns the error,
62 otherwise returns false.
63
64 =cut
65
66 # may want to check for duplicates against either services or devices
67 # cf FS::export_svc
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 record.  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   $self->ut_numbern('exportdevicenum')
94     || $self->ut_number('exportnum')
95     || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum')
96     || $self->ut_number('devicepart')
97     || $self->ut_foreign_key('devicepart', 'part_device', 'devicepart')
98     || $self->SUPER::check
99   ;
100 }
101
102 =item part_export
103
104 Returns the FS::part_export object (see L<FS::part_export>).
105
106 =cut
107
108 sub part_export {
109   my $self = shift;
110   qsearchs( 'part_export', { 'exportnum' => $self->exportnum } );
111 }
112
113 =item part_device
114
115 Returns the FS::part_device object (see L<FS::part_device>).
116
117 =cut
118
119 sub part_device {
120   my $self = shift;
121   qsearchs( 'part_device', { 'svcpart' => $self->devicepart } );
122 }
123
124 =back
125
126 =head1 BUGS
127
128 =head1 SEE ALSO
129
130 L<FS::part_export>, L<FS::part_device>, L<FS::Record>, schema.html from the base
131 documentation.
132
133 =cut
134
135 1;
136