1 package FS::sched_item;
2 use base qw( FS::Record );
5 use FS::Record qw( dbh ); # qsearch qsearchs );
10 FS::sched_item - Object methods for sched_item records
16 $record = new FS::sched_item \%hash;
17 $record = new FS::sched_item { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::sched_item object represents an schedulable item, such as an installer,
30 meeting room or truck. FS::sched_item inherits from FS::Record. The following
31 fields are currently supported:
56 Creates a new item. To add the item to the database, see L<"insert">.
58 Note that this stores the hash reference, not a distinct copy of the hash it
59 points to. You can ask the object for a copy with the I<hash> method.
63 sub table { 'sched_item'; }
67 Adds this record to the database. If there is an error, returns the error,
68 otherwise returns false.
72 Delete this record from the database.
74 =item replace OLD_RECORD
76 Replaces the OLD_RECORD with this one in the database. If there is an error,
77 returns the error, otherwise returns false.
81 Checks all fields to make sure this is a valid item. If there is
82 an error, returns the error, otherwise returns false. Called by the insert
91 $self->ut_numbern('itemnum')
92 || $self->ut_foreign_keyn('usernum', 'access_user', 'usernum')
93 || $self->ut_enum('disabled', [ '', 'Y' ])
95 return $error if $error;
102 Returns a name for this item; either the name of the associated employee (see
103 L<FS::access_user>), or the itemname field.
109 my $access_user = $self->access_user;
110 $access_user ? $access_user->name : $self->itemname;
113 =item replace_sched_avail SCHED_AVAIL, ...
115 Replaces the existing availability schedule with the list of passed-in
116 FS::sched_avail objects
120 sub replace_sched_avail {
121 my( $self, @new_sched_avail ) = @_;
123 my $oldAutoCommit = $FS::UID::AutoCommit;
124 local $FS::UID::AutoCommit = 0;
127 foreach my $old_sched_avail ( $self->sched_avail ) {
128 my $error = $old_sched_avail->delete;
130 $dbh->rollback if $oldAutoCommit;
135 foreach my $new_sched_avail ( @new_sched_avail ) {
136 $new_sched_avail->itemnum( $self->itemnum );
137 my $error = $new_sched_avail->insert;
139 $dbh->rollback if $oldAutoCommit;
144 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
156 L<FS::access_user>, L<FS::sched_avail>, L<FS::Record>