Index: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm
===================================================================
--- trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm	(revision 2293)
+++ trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm	(revision 2296)
@@ -18,5 +18,5 @@
 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];
 
-sub SCHEMA_VERSION { 35 };
+sub SCHEMA_VERSION { 36 };
 
 =head1 NAME
Index: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employment.pm
===================================================================
--- trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employment.pm	(revision 2293)
+++ trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employment.pm	(revision 2296)
@@ -345,4 +345,5 @@
     if ($res) {
         my $ouser = $base->get_object('user', $user);
+        $ouser->StoreEmployementSummary;
         $ouser->applyCurrentEmployment;
     }
@@ -362,4 +363,5 @@
         };
 
+        $user->StoreEmployementSummary;
         $user->applyCurrentEmployment;
     }
Index: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employmentsummary.pm
===================================================================
--- trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employmentsummary.pm	(revision 2296)
+++ trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employmentsummary.pm	(revision 2296)
@@ -0,0 +1,82 @@
+package LATMOS::Accounts::Bases::Sql::Employmentsummary;
+
+use 5.010000;
+use strict;
+use warnings;
+
+use base qw(LATMOS::Accounts::Bases::Sql::objects);
+use LATMOS::Accounts::Log;
+use LATMOS::Accounts::I18N;
+
+our $VERSION = (q$Rev: 341 $ =~ /^Rev: (\d+) /)[0];
+
+=head1 NAME
+
+LATMOS::Ad - Perl extension for blah blah blah
+
+=head1 SYNOPSIS
+
+  use LATMOS::Accounts::Bases;
+  my $base = LATMOS::Accounts::Bases->new('sql');
+  ...
+
+=head1 DESCRIPTION
+
+Account base access over standard unix file format.
+
+=head1 FUNCTIONS
+
+=cut
+
+=head2 new(%config)
+
+Create a new LATMOS::Ad object for windows AD $domain.
+
+domain / server: either the Ad domain or directly the server
+
+ldap_args is an optionnal list of arguments to pass to L<Net::LDAP>.
+
+=cut
+
+sub _object_table { 'employmentsum' }
+
+sub _key_field { 'name' }
+
+sub _has_extended_attributes { 0 }
+
+sub _get_attr_schema {
+    my ($class, $base) = @_;
+
+    $class->SUPER::_get_attr_schema($base,
+        {
+            name            => { reference => 'user', inline => 1, ro => 1 },
+            firstday        => { formtype => 'DATE',  inline => 1, ro => 1 },
+            lastday         => { formtype => 'DATE',  inline => 1, ro => 1 },
+            contrattype     => { inline => 1, ro => 1 },
+        }
+    )
+}
+
+
+1;
+
+__END__
+
+=head1 SEE ALSO
+
+L<LATMOS::Accounts::Bases::Sql> 
+
+=head1 AUTHOR
+
+Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2008, 2009 CNRS SA/CETP/LATMOS
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.10.0 or,
+at your option, any later version of Perl 5 you may have available.
+
+
+=cut
Index: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm
===================================================================
--- trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm	(revision 2293)
+++ trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm	(revision 2296)
@@ -2107,4 +2107,5 @@
     });
     $sth->execute($self->id);
+    warn $self->id;
     my @values;
     my $prevContrat = ':';
@@ -2117,4 +2118,6 @@
         my $curContrat  = $Emp->get_attributes('contratType') || '';
         my $DTfirstday  = DateTime::Format::Pg->parse_datetime( $Emp->get_attributes('firstday') );
+
+        warn $DTfirstday->ymd('-');
 
         if ($curContrat ne $prevContrat) {
@@ -2150,4 +2153,48 @@
 
     @values
+}
+
+=head2 StoreEmployementSummary
+
+Store into database the employment summary
+
+=cut
+
+sub StoreEmployementSummary {
+    my ( $self ) = @_;
+
+    my $stu = $self->base->db->prepare_cached(q{
+        UPDATE employmentsum set
+            "user" = ?,
+            firstday = ?,
+            lastday  = ?,
+            contrattype = ?,
+            nodelete = 't'
+        WHERE name = ?
+    });
+    my $sti = $self->base->db->prepare_cached(q{
+        INSERT INTO employmentsum
+        ("user", firstday, lastday, contrattype, name, nodelete)
+        VALUES
+        (?, ?, ?, ?, ?, 1)
+    });
+
+    my @values = $self->EmploymentSummary;
+
+    my @names;
+
+    foreach (@values) {
+        my $name = $self->id . '-' . $_->{firstday};
+        my $res = $stu->execute($self->id, $_->{firstday}, $_->{lastday}, $_->{contrattype}, $name);
+        if ($res == 0) {
+            $sti->execute($self->id, $_->{firstday}, $_->{lastday}, $_->{contrattype}, $name);
+        }
+        push(@names, $name);
+    }
+
+    my $std = $self->base->db->prepare_cached(q{
+        DELETE FROM employmentsum WHERE "user" = ? AND name != ALL (?)
+    });
+    $std->execute($self->id, \@names);
 }
 
Index: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm
===================================================================
--- trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm	(revision 2293)
+++ trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm	(revision 2296)
@@ -1269,4 +1269,53 @@
             ],
         },
+        {
+            ver => 36,
+            sql => [
+                q{
+                CREATE TABLE public.employmentsum
+                (
+                  "user" text NOT NULL,
+                  firstday date NOT NULL DEFAULT now(),
+                  lastday date,
+                  contrattype text,
+                  CONSTRAINT employmentsum_pkey PRIMARY KEY (name),
+                  CONSTRAINT employmentsum_check CHECK (lastday IS NULL OR firstday <= lastday),
+                  CONSTRAINT employmentsum_name_user_fkey FOREIGN KEY ("user")
+                      REFERENCES public."user" (name) MATCH SIMPLE
+                      ON UPDATE CASCADE ON DELETE CASCADE
+                )
+                INHERITS (public.objects)
+                WITH (
+                  OIDS=FALSE
+                );
+
+                CREATE INDEX fki_employmentsum_name_user_fkey
+                  ON public.employmentsum
+                  USING btree
+                  (name COLLATE pg_catalog."default");
+
+                CREATE INDEX fki_employmentsum_user_fkey
+                  ON public.employmentsum
+                  USING btree
+                  (name COLLATE pg_catalog."default");
+
+                CREATE INDEX employmentsum_exported_idx
+                  ON public.employmentsum
+                  USING btree
+                  (exported);
+
+                CREATE INDEX employmentsum_rev_idx
+                  ON public.employmentsum
+                  USING btree
+                  (rev);
+
+                CREATE TRIGGER employmentsum_rev_tg
+                  BEFORE INSERT OR UPDATE OR DELETE
+                  ON public.employmentsum
+                  FOR EACH ROW
+                  EXECUTE PROCEDURE public.rev_tg_f();
+                }
+            ],
+        },
     );
 
