installers, RT#16584
[freeside.git] / FS / FS / sched_item.pm
1 package FS::sched_item;
2 use base qw( FS::Record );
3
4 use strict;
5 #use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::sched_item - Object methods for sched_item records
10
11 =head1 SYNOPSIS
12
13   use FS::sched_item;
14
15   $record = new FS::sched_item \%hash;
16   $record = new FS::sched_item { '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::sched_item object represents an schedulable item, such as an installer,
29 meeting room or truck.  FS::sched_item inherits from FS::Record.  The following
30 fields are currently supported:
31
32 =over 4
33
34 =item itemnum
35
36 primary key
37
38 =item usernum
39
40 usernum
41
42 =item disabled
43
44 disabled
45
46
47 =back
48
49 =head1 METHODS
50
51 =over 4
52
53 =item new HASHREF
54
55 Creates a new item.  To add the item to the database, see L<"insert">.
56
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to.  You can ask the object for a copy with the I<hash> method.
59
60 =cut
61
62 sub table { 'sched_item'; }
63
64 =item insert
65
66 Adds this record to the database.  If there is an error, returns the error,
67 otherwise returns false.
68
69 =item delete
70
71 Delete this record from the database.
72
73 =item replace OLD_RECORD
74
75 Replaces the OLD_RECORD with this one in the database.  If there is an error,
76 returns the error, otherwise returns false.
77
78 =item check
79
80 Checks all fields to make sure this is a valid item.  If there is
81 an error, returns the error, otherwise returns false.  Called by the insert
82 and replace methods.
83
84 =cut
85
86 sub check {
87   my $self = shift;
88
89   my $error = 
90     $self->ut_numbern('itemnum')
91     || $self->ut_foreign_keyn('usernum', 'access_user', 'usernum')
92     || $self->ut_enum('disabled', [ '', 'Y' ])
93   ;
94   return $error if $error;
95
96   $self->SUPER::check;
97 }
98
99 =item name
100
101 Returns a name for this item; either the name of the associated employee (see
102 L<FS::access_user), or the itemname field.
103
104 =cut
105
106 sub name {
107   my $self = shift;
108   my $access_user = $self->access_user;
109   $access_user ? $access_user->name : $self->itemname;
110 }
111
112 =back
113
114 =head1 BUGS
115
116 =head1 SEE ALSO
117
118 L<FS::access_user>, L<FS::sched_avail>, L<FS::Record>
119
120 =cut
121
122 1;
123