X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fsched_item.pm;h=f2a82c857226222f52df9e41234683955ad36e9e;hp=5f55188e61fb1eff8c93c3c9b3d3a8de039cfbb2;hb=14f234a943f1e4b5bbc6fe90254b8f5ca677f028;hpb=0dfd49189b0ea878e99f1590a2939e55ab02c89c diff --git a/FS/FS/sched_item.pm b/FS/FS/sched_item.pm index 5f55188e6..f2a82c857 100644 --- a/FS/FS/sched_item.pm +++ b/FS/FS/sched_item.pm @@ -2,7 +2,8 @@ package FS::sched_item; use base qw( FS::Record ); use strict; -#use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( dbh ); # qsearch qsearchs ); +use FS::sched_avail; =head1 NAME @@ -99,7 +100,7 @@ sub check { =item name Returns a name for this item; either the name of the associated employee (see -L), or the itemname field. =cut @@ -109,6 +110,43 @@ sub name { $access_user ? $access_user->name : $self->itemname; } +=item replace_sched_avail SCHED_AVAIL, ... + +Replaces the existing availability schedule with the list of passed-in +FS::sched_avail objects + +=cut + +sub replace_sched_avail { + my( $self, @new_sched_avail ) = @_; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + foreach my $old_sched_avail ( $self->sched_avail ) { + my $error = $old_sched_avail->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + foreach my $new_sched_avail ( @new_sched_avail ) { + $new_sched_avail->itemnum( $self->itemnum ); + my $error = $new_sched_avail->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; + +} + =back =head1 BUGS