From ff59808920276be5fc6ab6e8b007759e93c3cfcc Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 17 Jan 2017 17:26:29 +0100 Subject: [PATCH] =?utf8?q?Hintergrundjob=20zum=20Schlie=C3=9Fen=20bei=20ge?= =?utf8?q?schlossenen=20Auftr=C3=A4gen=20verlinkten=20Projekten?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- SL/BackgroundJob/ALL.pm | 2 +- ...oseProjectsBelongingToClosedSalesOrders.pm | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 SL/BackgroundJob/CloseProjectsBelongingToClosedSalesOrders.pm 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 -- 2.20.1