X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44..53593baa211863fbf66540cf1bcc36c8fb37257f:/SL/BackgroundJob/CloseProjectsBelongingToClosedSalesOrders.pm diff --git a/SL/BackgroundJob/CloseProjectsBelongingToClosedSalesOrders.pm b/SL/BackgroundJob/CloseProjectsBelongingToClosedSalesOrders.pm new file mode 100644 index 000000000..feb887a74 --- /dev/null +++ b/SL/BackgroundJob/CloseProjectsBelongingToClosedSalesOrders.pm @@ -0,0 +1,75 @@ +package SL::BackgroundJob::CloseProjectsBelongingToClosedSalesOrders; + +use strict; + +use parent qw(SL::BackgroundJob::Base); + +use SL::DB::Project; +use SL::DB::ProjectStatus; + +sub run { + my ($self, $db_obj) = @_; + + my $data = $db_obj->data_as_hash; + $data->{new_status} ||= 'done'; + $data->{set_inactive} = 1 if !exists $data->{set_inactive}; + + my $new_status = SL::DB::Manager::ProjectStatus->find_by(name => $data->{new_status}) || die "No project status named '$data->{new_status}' found!"; + + my %attributes = (project_status_id => $new_status->id); + $attributes{active} = 0 if $data->{set_inactive}; + + my $sql = <update_all( + set => \%attributes, + where => [ + '!project_status_id' => $new_status->id, + \$sql, + ], + ); + + return 1; +} + +1; + +__END__ + +=encoding utf8 + +=head1 NAME + +SL::BackgroundJob::CloseProjectsBelongingToClosedSalesOrders — +Background job for closing all projects which are linked to a closed +sales order (via C) + +=head1 SYNOPSIS + +This background job searches all closed sales orders for linked +projects. Those projects whose status is not C will be modified: +their status will be set to C and their C flag will be +set to C. + +Both of these can be configured via the job's data hash: C +is the new status' name (defaults to C), and C +determines whether or not the project will be set to inactive +(defaults to 1). + +The job is deactivated by default. Administrators of installations +where such a feature is wanted have to create a job entry manually. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut