source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Json/EmploymentByPeriod.pm @ 2006

Last change on this file since 2006 was 1761, checked in by nanardon, 8 years ago

Add trickery to make stat working

File size: 2.1 KB
Line 
1package LATMOS::Accounts::Web::Controller::Json::EmploymentByPeriod;
2use Moose;
3use namespace::autoclean;
4
5BEGIN { extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::Json::EmploymentByPeriod - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub index :Path :Args(0) {
25    my ( $self, $c ) = @_;
26
27    my $base = $c->model('Accounts')->db;
28
29    my ($sday, $smonth, $syear) = split('/', $c->req->param('start'));
30    my ($eday, $emonth, $eyear) = split('/', $c->req->param('end'));
31
32    my $start = DateTime->new(year => $syear, month => $smonth, day => $sday);
33    my $end   = DateTime->new(year => $eyear, month => $emonth, day => $eday);
34
35    my @filteredObj = $base->search_objects(
36        'employment', sprintf('firstday<=%s', $end->ymd('-')), sprintf('lastday>=%s', $start->ymd('-')), 'lastday=NULL'
37    );
38    my %atstart = map { $_ => 1 } $base->search_objects(
39        'employment', sprintf('firstday>=%s', $start->ymd('-'))
40    );
41    my %atend = map { $_ => 1 } $base->search_objects(
42        'employment', sprintf('lastday<=%s', $end->ymd('-'))
43    );
44
45    my %empusers = $base->attributes_summary_by_object('employment', 'user');
46    my %emptypes = $base->attributes_summary_by_object('employment', 'contratType');
47
48    my %results;
49    my $atstart = $c->req->param('atstart');
50    my $atend =   $c->req->param('atend');
51
52    foreach my $emp (@filteredObj) {
53        if ($atstart) {
54            $atstart{$emp} or next;
55        }
56        if ($atend) {
57            $atend{$emp} or next;
58        }
59        my $user = $empusers{$emp}[0];
60        my $type = $emptypes{$emp}[0];
61        $results{$type}{$user} = 1;
62    }
63
64    $c->stash->{data} = [ 
65        sort { $b->[1] <=> $a->[1] } 
66        map { [ $_, scalar(keys %{$results{$_}}) ] } keys %results
67    ];
68}
69
70=encoding utf8
71
72=head1 AUTHOR
73
74Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,
75
76=head1 LICENSE
77
78This library is free software. You can redistribute it and/or modify
79it under the same terms as Perl itself.
80
81=cut
82
83__PACKAGE__->meta->make_immutable;
84
851;
Note: See TracBrowser for help on using the repository browser.