]> wagnertech.de Git - mfinanz.git/blob - SL/BackgroundJob/CloseQuotations.pm
date error in mapping
[mfinanz.git] / SL / BackgroundJob / CloseQuotations.pm
1 package SL::BackgroundJob::CloseQuotations;
2
3 use strict;
4
5 use parent qw(SL::BackgroundJob::Base);
6
7 use SL::DB::Manager::Order;
8 use SL::DB::Order::TypeData qw(:types);
9 use SL::Locale::String qw(t8);
10
11
12 sub run {
13   my ($self, $job_obj) = @_;
14   $self->{job_obj} = $job_obj;
15   my $data = $job_obj->data_as_hash;
16
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);
21
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],
26   ]);
27
28   my (@req_quos, @sal_quos);
29
30   my %dispatch = (
31     REQUEST_QUOTATION_TYPE() => \@req_quos,
32     SALES_QUOTATION_TYPE()   => \@sal_quos,
33   );
34
35   foreach my $quotation (@{ $quotations }) {
36     push @{ $dispatch{$quotation->record_type} }, $quotation->quonumber;
37
38     next if $dry_run;
39
40     $quotation->closed(1);
41     $quotation->save();
42   }
43
44   return $dry_run
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));
49 }
50
51 1;
52
53 __END__
54
55 =encoding utf8
56
57 =head1 NAME
58
59 SL::BackgroundJob::CloseQuotations —
60 Background job for closing all request and sales quotations older than a given number of years
61
62 =head1 SYNOPSIS
63
64 =head1 AUTHOR
65
66 Niklas Schmidt
67
68
69 =cut
70