1 package FS::sched_item;
2 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs dbh );
11 FS::sched_item - Object methods for sched_item records
17 $record = new FS::sched_item \%hash;
18 $record = new FS::sched_item { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::sched_item object represents an schedulable item, such as an installer,
31 meeting room or truck. FS::sched_item inherits from FS::Record. The following
32 fields are currently supported:
57 Creates a new item. To add the item to the database, see L<"insert">.
59 Note that this stores the hash reference, not a distinct copy of the hash it
60 points to. You can ask the object for a copy with the I<hash> method.
64 sub table { 'sched_item'; }
68 Adds this record to the database. If there is an error, returns the error,
69 otherwise returns false.
73 Delete this record from the database.
75 =item replace OLD_RECORD
77 Replaces the OLD_RECORD with this one in the database. If there is an error,
78 returns the error, otherwise returns false.
82 Checks all fields to make sure this is a valid item. If there is
83 an error, returns the error, otherwise returns false. Called by the insert
92 $self->ut_numbern('itemnum')
93 || $self->ut_foreign_keyn('usernum', 'access_user', 'usernum')
94 || $self->ut_enum('disabled', [ '', 'Y' ])
96 return $error if $error;
103 Returns a name for this item; either the name of the associated employee (see
104 L<FS::access_user), or the itemname field.
110 my $access_user = $self->access_user;
111 $access_user ? $access_user->name : $self->itemname;
116 qsearchs( 'access_user', { 'usernum' => $self->usernum } );
121 qsearch( 'sched_avail', { 'itemnum' => $self->itemnum } );
125 =item replace_sched_avail SCHED_AVAIL, ...
127 Replaces the existing availability schedule with the list of passed-in
128 FS::sched_avail objects
132 sub replace_sched_avail {
133 my( $self, @new_sched_avail ) = @_;
135 my $oldAutoCommit = $FS::UID::AutoCommit;
136 local $FS::UID::AutoCommit = 0;
139 foreach my $old_sched_avail ( $self->sched_avail ) {
140 my $error = $old_sched_avail->delete;
142 $dbh->rollback if $oldAutoCommit;
147 foreach my $new_sched_avail ( @new_sched_avail ) {
148 $new_sched_avail->itemnum( $self->itemnum );
149 my $error = $new_sched_avail->insert;
151 $dbh->rollback if $oldAutoCommit;
156 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
168 L<FS::access_user>, L<FS::sched_avail>, L<FS::Record>