Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0d42912b

Von Jan Büren vor fast 4 Jahren hinzugefügt

  • ID 0d42912b210313b779d694aee65c9241a14ca8d3
  • Vorgänger 73cff733
  • Nachfolger 28cc69e2

CTR Mehr Benutzerparameter aus dem POD erlauben und prüfen

- Init rounding and link_project defaults
- Check for valid user param names
- Add params to each source entry for DO->new_from_time_recording
- some TODOS

Unterschiede anzeigen:

SL/BackgroundJob/ConvertTimeRecordings.pm
9 9

  
10 10
use SL::Locale::String qw(t8);
11 11

  
12
use Carp;
12 13
use DateTime;
13 14
use Try::Tiny;
14 15

  
15 16
sub create_job {
16 17
  $_[0]->create_standard_job('7 3 1 * *'); # every first day of month at 03:07
17 18
}
18

  
19
use Rose::Object::MakeMethods::Generic (
20
 'scalar --get_set_init' => [ qw(rounding link_project) ],
21
);
22

  
23
# valid parameters -> better as class members with rose generic set/get
24
my %params = (
25
              fromdate => '',
26
              todate   => '',
27
              customernumbers => '',
28
              part_id => '',
29
              rounding => 1,
30
              link_project => 0,
31
              project_id => '',
32
             );
19 33

  
20 34
#
21 35
# If job does not throw an error,
......
31 45
  $data = $db_obj->data_as_hash if $db_obj;
32 46

  
33 47
  $self->{$_} = [] for qw(job_errors);
48

  
49
  # check user input param names
50
  foreach my $param (keys %{ $data }) {
51
    croak "Not a valid key: $param" unless $params{$param};
52
  }
53

  
54
  # TODO check user input param values - (defaults are assigned later)
55
  # 1- If there are any customer numbers check if they refer to valid customers
56
  #    otherwise croak and do nothing
57
  # 2 .. n Same applies for other params if used at all (rounding -> 0|1  link_project -> 0|1)
58

  
34 59
  # from/to date from data. Defaults to begining and end of last month.
60
  # TODO get/set see above
35 61
  my $from_date;
36 62
  my $to_date;
37 63
  # handle errors with a catch handler
......
53 79
                                                                                 or => [booked => 0, booked => undef],
54 80
                                                                                 %customer_where],
55 81
                                                                with_objects => ['customer']);
82
  # no time recordings at all ? -> better exit here before iterating a empty hash
83
  # return undef or message unless ref $time_recordings->[0] eq SL::DB::Manager::TimeRecording;
56 84
  my %time_recordings_by_customer_id;
57
  push @{ $time_recordings_by_customer_id{$_->customer_id} }, $_ for @$time_recordings;
58

  
85
  # push @{ $time_recordings_by_customer_id{$_->customer_id} }, $_ for @$time_recordings;
86
  # loop over all entries and add default or user defined params:
87

  
88
  for my $source_entry (@$time_recordings) {
89
    # set user defaults for processing
90
    $source_entry->{$_} = $self->$_ for qw(rounding link_project);
91
    foreach (qw(project_id parts_id)) {
92
      $source_entry->{$_} = $self->{$_} if length ($self->{$_});
93
    }
94
    push @{ $time_recordings_by_customer_id{$source_entry->customer_id} }, $source_entry;
95
  }
59 96
  my @donumbers;
60 97
  foreach my $customer_id (keys %time_recordings_by_customer_id) {
61 98
    my $do;
......
99 136
  return $msg;
100 137
}
101 138

  
139
# inits
140

  
141
sub init_rounding {
142
  1
143
}
144

  
145
sub init_link_project {
146
  0
147
}
148

  
102 149
1;
103 150

  
104 151
# possible data

Auch abrufbar als: Unified diff