From: Moritz Bunkus Date: Tue, 17 Jan 2017 16:26:29 +0000 (+0100) Subject: Hintergrundjob zum Schließen bei geschlossenen Aufträgen verlinkten Projekten X-Git-Tag: release-3.5.4~1701 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ff59808920276be5fc6ab6e8b007759e93c3cfcc;p=kivitendo-erp.git Hintergrundjob zum Schließen bei geschlossenen Aufträgen verlinkten Projekten Der Job ist per Default deaktiviert. Wenn eine solche Funktionalität für eine Installation benötigt wird, so muss der Admin manuell einen Hintergrundjob dafür anlegen. --- diff --git a/SL/BackgroundJob/ALL.pm b/SL/BackgroundJob/ALL.pm index ba9ce831d..938e62eab 100644 --- a/SL/BackgroundJob/ALL.pm +++ b/SL/BackgroundJob/ALL.pm @@ -5,8 +5,8 @@ use strict; use SL::BackgroundJob::Base; use SL::BackgroundJob::BackgroundJobCleanup; use SL::BackgroundJob::CleanBackgroundJobHistory; +use SL::BackgroundJob::CloseProjectsBelongingToClosedSalesOrders; use SL::BackgroundJob::CreatePeriodicInvoices; use SL::BackgroundJob::FailedBackgroundJobsReport; 1; - 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