1 package SL::BackgroundJob::CloseQuotations;
5 use parent qw(SL::BackgroundJob::Base);
7 use SL::DB::Manager::Order;
8 use SL::DB::Order::TypeData qw(:types);
9 use SL::Locale::String qw(t8);
13 my ($self, $job_obj) = @_;
14 $self->{job_obj} = $job_obj;
15 my $data = $job_obj->data_as_hash;
17 my $dry_run = ($data->{dry_run}) ? 1 : 0;
18 my $today = DateTime->today;
19 my $years = $data->{years} // 1;
20 my $end = $today->subtract(years => $years);
22 my $quotations = SL::DB::Manager::Order->get_all(where => [
23 record_type => [ REQUEST_QUOTATION_TYPE(), SALES_QUOTATION_TYPE() ],
24 transdate => { le => $end },
25 or => [ closed => 0, closed => undef],
28 my (@req_quos, @sal_quos);
31 REQUEST_QUOTATION_TYPE() => \@req_quos,
32 SALES_QUOTATION_TYPE() => \@sal_quos,
35 foreach my $quotation (@{ $quotations }) {
36 push @{ $dispatch{$quotation->record_type} }, $quotation->quonumber;
40 $quotation->closed(1);
45 ? t8('Request quotations not yet closed: #1 Sales quotations not yet closed: #2',
46 join(', ', @req_quos), join(', ', @sal_quos))
47 : t8('Request quotations closed: #1 Sales quotations closed: #2',
48 join(', ', @req_quos), join(', ', @sal_quos));
59 SL::BackgroundJob::CloseQuotations —
60 Background job for closing all request and sales quotations older than a given number of years