export host selection per service, RT#17914
[freeside.git] / FS / FS / svc_export_machine.pm
1 package FS::svc_export_machine;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearchs ); #qsearch );
6 use FS::cust_svc;
7 use FS::part_export;
8 use FS::part_export_machine;
9
10 sub _svc_child_partfields { ('exportnum') };
11
12 =head1 NAME
13
14 FS::svc_export_machine - Object methods for svc_export_machine records
15
16 =head1 SYNOPSIS
17
18   use FS::svc_export_machine;
19
20   $record = new FS::svc_export_machine \%hash;
21   $record = new FS::svc_export_machine { 'column' => 'value' };
22
23   $error = $record->insert;
24
25   $error = $new_record->replace($old_record);
26
27   $error = $record->delete;
28
29   $error = $record->check;
30
31 =head1 DESCRIPTION
32
33 An FS::svc_export_machine object represents a customer service export
34 hostname.  FS::svc_export_machine inherits from FS::Record.  The following
35 fields are currently supported:
36
37 =over 4
38
39 =item svcexportmachinenum
40
41 primary key
42
43 =item svcnum
44
45 Customer service, see L<FS::cust_svc>
46
47 =item machinenum
48
49 Export hostname, see L<FS::part_export_machine>
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 { 'svc_export_machine'; }
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 =item replace OLD_RECORD
78
79 Replaces the OLD_RECORD with this one in the database.  If there is an error,
80 returns the error, otherwise returns false.
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   my $error = 
94     $self->ut_numbern('svcexportmachinenum')
95     || $self->ut_foreign_key('svcnum',     'cust_svc',            'svcnum'    )
96     || $self->ut_foreign_key('exportnum',  'part_export',         'exportnum' )
97     || $self->ut_foreign_key('machinenum', 'part_export_machine', 'machinenum')
98   ;
99   return $error if $error;
100
101   $self->SUPER::check;
102 }
103
104 =item part_export_machine
105
106 =cut
107
108 sub part_export_machine {
109   my $self = shift;
110   qsearchs('part_export_machine', { 'machinenum' => $self->machinenum } );
111 }
112
113 =back
114
115 =head1 BUGS
116
117 =head1 SEE ALSO
118
119 L<FS::cust_svc>, L<FS::part_export_machine>, L<FS::Record>
120
121 =cut
122
123 1;
124