Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Marica::Base::Agenda::agenda_general ;
- use lib qw(/home/lib);
- use strict ;
- use warnings ;
- use Apache2::Const -compile => qw( OK REDIRECT ) ;
- use Marica::dictionary ;
- sub handler {
- my $r = shift ;
- my $req = Apache2::Request->new($r) ;
- my $id_client = $r->pnotes('session')->{id_client} ;
- my $content = '<h1>' . _( 'Agenda général', $r ) . '</h1>' ;
- #récupérer les arguments
- my %args ;
- my @args ;
- if ($req->param) { #si présence de paramètres
- @args = $req->param ;
- for (@args) {
- $args{$_} = $req->param($_) ;
- }
- }
- my $args_hash = \%args;
- my $dbh = $r->pnotes('dbh') ;
- #affichage des deux semaines à partir de $start_date et des éléments déjà enregistrés
- $content .= display_agenda( $r, $dbh, $id_client ) ;
- $r->no_cache(1) ;
- $r->content_type('text/html; charset=utf-8') ;
- print $content ;
- return Apache2::Const::OK ;
- }
- 1 ;
- sub display_agenda {
- my ($r, $dbh, $id_client) = @_ ;
- my $calendar = '<table>';
- my ($days_of_week_row, $dates_row1, $dates_row2) ;
- my ($background_color, $border_color) ;
- my ( $date_displayed, $mnemo ) ;
- my $content ;
- #recherche des éléments déjà enregistrés;
- #pour les non-admistrateurs, limiter l'affichage aux dossiers autorisés
- #pour les administrateurs : ajouter les alertes contrats
- my $sql = ( $r->pnotes('session')->{administrateur} == 0 ) ?
- 'SELECT t1.id_agenda, t1.id_item, t1.date_expected, t1.date_expected - CURRENT_DATE as diff_date, t2.libelle, coalesce(t1.description, \'\') as description, t1.id_contentieux, t3.ref_dossier, coalesce(t3.notes_contentieux, \'\') as notes_contentieux FROM ( tblcontentieux as t3 INNER JOIN ( marica_dossier_group t5 INNER JOIN marica_user_group t4 using (id_group) ) ON t3.id_contentieux = t5.id_contentieux ) INNER JOIN ( tblcontentieux_agenda as t1 INNER JOIN tblcontentieux_expected as t2 using (id_item) ) on t1.id_contentieux = t3.id_contentieux WHERE t3.id_client = ? AND t4.id_user = \'' . $r->pnotes('session')->{username} . '\'
- UNION SELECT 0 as id_agenda, id_contrat_type as id_item, ( t1.date_fin - ( t1.duree_preavis * interval \'1 month\' ) )::date as date_expected, t1.date_fin - CURRENT_DATE as diff_date, \'' . _( 'Alerte contrat', $r ) . '\' as "libelle", t2.libelle || \' - \' || t1.libelle || \' - \' || t1.police as description, t1.id_contrat_autre as id_contentieux, coalesce(t1.police,\'' . _( 'Contrats', $r ) . '\') as ref_dossier, \'\' as notes_contentieux
- FROM tblcontrat_autre t1 INNER JOIN tblcontrat_type t2 using(id_contrat_type)
- WHERE t1.tacite_reconduction = 0 and t2.id_client = ' . $r->pnotes('session')->{id_client} . '
- AND ( ( CURRENT_DATE + interval \'1 month\' ) - ( t1.date_fin - ( duree_preavis * interval \'1 month\' ) ) ) between interval \'1 day\' and interval \'1 month\'
- ORDER BY 3, 4' :
- 'SELECT t1.id_agenda, t1.id_item, t1.date_expected, t1.date_expected - CURRENT_DATE as diff_date, t2.libelle, coalesce(t1.description, \'\') as description, t1.id_contentieux, t3.ref_dossier, coalesce(t3.notes_contentieux, \'\') as notes_contentieux FROM tblcontentieux as t3 INNER JOIN ( tblcontentieux_agenda as t1 INNER JOIN tblcontentieux_expected as t2 using (id_item) ) using (id_contentieux) WHERE t3.id_client = ?
- UNION SELECT 0 as id_agenda, id_contrat_type as id_item, ( t1.date_fin - ( t1.duree_preavis * interval \'1 month\' ) )::date as date_expected, t1.date_fin - CURRENT_DATE as diff_date, \'' . _( 'Alerte contrat', $r ) . '\' as "libelle", t2.libelle || \' - \' || t1.libelle || \' - \' || t1.police as description, t1.id_contrat_autre as id_contentieux, coalesce(t1.police,\'' . _( 'Contrats', $r ) . '\') as ref_dossier, \'\' as notes_contentieux
- FROM tblcontrat_autre t1 INNER JOIN tblcontrat_type t2 using(id_contrat_type)
- WHERE t1.tacite_reconduction = 0 and t2.id_client = ' . $r->pnotes('session')->{id_client} . '
- AND ( ( CURRENT_DATE + interval \'1 month\' ) - ( t1.date_fin - ( duree_preavis * interval \'1 month\' ) ) ) between interval \'1 day\' and interval \'1 month\'
- ORDER BY 3, 4';
- my $sth = $dbh->prepare($sql) ;
- $sth->execute($id_client) ;
- my @agenda = @{ $sth->fetchall_arrayref( { } ) } ;
- #hash par date
- my %agenda ;
- #liste des éléments enregistrés
- my $items_in_agenda = '
- <li style="list-style: none; width: 90em;"><div class=container><div class=spacer></div>
- <span class=headerspan style="margin: .2em;">
- <span class=headerspan style="width: 10em">' . $r->pnotes('session')->{field_labels}->{tblcontentieux}->{ref_dossier} . '</span>
- <span class=headerspan style="width: 6em">' . _( 'Date prévue', $r ) . '</span>
- <span class=headerspan style="width: 20em">' . _('Élément attendu', $r ) . '</span>
- <span class=headerspan style="width: 50em">' . _ ( 'Description', $r ) . '</span>
- </span>
- <div class=spacer></div></div></li>
- ' ;
- for ( @agenda ) { #si présence de données
- #
- #signaler les éléments en retard en rouge, ceux dans les 14 jours en bleu, les autres normal
- #
- #créer une clé dans %agenda
- $agenda{ $_->{date_expected} }++ ;
- #toujours signaler en rouge les éléments en retard (diff_date < 0)
- #les éléments situés dans le tableau des 14 prochains jours sont affichés sur fond bleu pâle
- #ceux situés au-delà sur fond jaune
- if ( $_->{diff_date} < 0 ) {
- $background_color = '#f63' ;
- $border_color = 'black' ;
- } elsif ( $_->{diff_date} <= 13 ) {
- $background_color = '#eee' ;
- $border_color = 'blue' ;
- } else {
- $background_color = '#ffa' ;
- $border_color = '#000' ;
- } # if ( $_->{diff_date} < 0 )
- #couleur spéciale pour les alertes contrats
- if ( $_->{id_agenda} == 0 ) {
- $background_color = '#fbb' ;
- $border_color = '#000' ;
- }
- #style de la case dossier
- my $style = ' style=" white-space: nowrap; background-color: ' . $background_color . '; border: thin solid ' . $border_color . ';"' ;
- my $dossier = $_->{ref_dossier} || '' ;
- #pour les utilisateurs du compte demo, l'agenda renvoie sur l'onglet etat
- #pour les autres, l'agenda renvoie directement sur l'onglet agenda
- #on crée cette exception pour le compte démo parce que les utilisateurs
- #ne voient pas le passage au dossier sinon
- my $id_onglet = ( $r->pnotes('session')->{username} =~ /^demo_/ ) ? '' : '&id_onglet=5' ;
- #lien de modification de l'item; si id_agenda == 0, c'est une alerte contrat, sinon c'est un dossier contentieux
- my $modify_item_in_agenda_href = ( $_->{id_agenda} == 0 ) ?
- '/base/contrats_autres?id_contrat_autre=' . $_->{id_contentieux} . '&id_contrat_type=' . $_->{id_item} :
- '/base/contentieux_detail?id_contentieux=' . $_->{id_contentieux} . $id_onglet . '&id_agenda=' . $_->{id_agenda} ;
- my $post_it = $_->{notes_contentieux} ;
- #ajouter l'élément à la liste
- $items_in_agenda .= '
- <li style="list-style: none; width: 90em;"><div class=container ' . $style . '><div class=spacer></div>
- <a class=listitem href="' . $modify_item_in_agenda_href . '" title="' . $post_it . '">
- <span class=blockspan style="margin: .2em;">
- <span class=blockspan style="width: 10em">' . $_->{ref_dossier} . '</span>
- <span class=blockspan style="width: 6em">' . $_->{date_expected} . '</span>
- <span class=blockspan style="width: 20em">' . $_->{libelle} . '</span>
- <span class=blockspan style="width: 50em">' . $_->{description} . '</span>
- </span></a>
- <div class=spacer></div></div></li>
- ' ;
- } # for ( @agenda )
- $items_in_agenda = '<ul style="margin: .1em; padding: .1em;">' . $items_in_agenda . '</ul>' ;
- #recherche des noms des jours de la semaine localisés, avec formatage de la date pour affichage dans les cases de l'agenda
- $sql = q { select CURRENT_DATE + i as date_displayed, extract(day from CURRENT_DATE + i) || ' ' || to_char(CURRENT_DATE + i, 'TMMon') as day_of_month, to_char(current_date + i , 'TMDay') as day_of_week from generate_series(0,13) i ORDER by i } ;
- my $days_of_week = $dbh->selectall_arrayref( $sql ) ;
- my @days_of_week = @{$days_of_week} ;
- #construction de la ligne d'en-tête et de la première ligne de l'agenda
- for ( 0 .. 6 ) {
- $date_displayed = $days_of_week->[$_]->[0] ;
- $mnemo = $days_of_week->[$_]->[1] ;
- #en-tête de la table : afficher les noms de 7 jours à partir d'aujourd'hui
- $days_of_week_row .= '<th>' . $days_of_week->[$_]->[2] . '</th>' ;
- $background_color = ( defined $agenda{$date_displayed} ) ? ' background-color: #eee;' : '' ;
- $dates_row1 .= '<td style="width: 100px; border: thin groove blue;' . $background_color .'"><sup>' . $mnemo . '</sup><div style="text-align: center; font-size: xx-large;">' . ( '*' x ( $agenda{$date_displayed} || 0 ) || ' ' ) . '</div></td>' ;
- } # for ( 0 .. 6 )
- #construction de la deuxième ligne
- for ( 7 .. 13 ) {
- $date_displayed = $days_of_week->[$_]->[0] ;
- $mnemo = $days_of_week->[$_]->[1] ;
- $background_color = ( $agenda{ $date_displayed } ) ? ' background-color: #eee;' : '' ;
- $dates_row2 .= '<td style="width: 100px; border: thin groove blue;' . $background_color .'"><sup>' . $mnemo . '</sup><div style="text-align: center; font-size: xx-large;">' . ( '*' x ( $agenda{$date_displayed} || 0 ) || ' ' ) . '</div></td>' ;
- } # for ( 7 .. 13 )
- $calendar .= '<tr>' . $days_of_week_row . '</tr>' ;
- $calendar .= '<tr>' . $dates_row1 . '</tr>' ;
- $calendar .= '<tr>' . $dates_row2 . '</tr>' ;
- $calendar .= '</table>' ;
- #afficher le calendrier au-dessus de la liste des éléments déjà enregistréss
- $content .= '<h2>' . _( 'Éléments enregistrés pour les deux semaines à venir', $r ) . '</h2><hr>' ;
- $content .= $calendar ;
- $content .= '<hr>' ;
- $content .= '<table><tr><td><h3>' . _( 'Tous les éléments enregistrés', $r ) . '</h3></td></tr></table>' ;
- if ( @agenda ) { #il existe des éléments à l'agenda
- $content .= $items_in_agenda ;
- } else { # !(@agenda)
- $content .= '<h3 class=warning style="margin: 2.5em; padding: 2.5em;">' . _( 'Aucun élément enregistré', $r ) . '</h3>' ;
- } # if ( @agenda )
- my $legend = '
- <h3>' . _( 'Légende', $r ) . '</h3>
- <table>
- <tr><td style=""><span class=blockspan style="width: 100%; background-color: #f63; color: blue;">' . _( 'En retard', $r ) . '</span></td></tr>
- <tr><td style=""><span class=blockspan style="width: 100%; background-color: #eee; color: blue;">' . _( 'Attendu dans les deux prochaines semaines', $r ) . '</span></td></tr>
- <tr><td style=""><span class=blockspan style="width: 100%; background-color: #ffa; color: blue;">' . _( 'Attendu plus tard', $r ) . '</span></td></tr>
- <tr><td style=""><span class=blockspan style="width: 100%; background-color: #faa; color: blue;">' . _( 'Alerte contrat', $r ) . '</span></td></tr>
- </table>
- ';
- $content .= $legend ;
- return $content ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement