Multi comment
related operation
related action
This commit is contained in:
Dany De Bontridder 2012-05-31 02:51:49 +00:00
parent 697ea8467e
commit bf13768b51
13 changed files with 1733 additions and 1207 deletions

View file

@ -240,7 +240,7 @@ function errorFid(request,json)
}
function update_value(text,li)
{
ajaxFid(ctl);
ajaxFid(text);
}
/**
*@brief is called when something change in ICard

View file

@ -33,17 +33,17 @@
*/
function remove_document(p_dossier,p_id)
{
queryString="gDossier="+p_dossier+"&a=rm&d_id="+p_id;
var action=new Ajax.Request (
"show_document.php",
{
method:'get',
parameters:queryString,
onFailure:errorRemoveDoc,
onSuccess:successRemoveDoc
}
queryString="gDossier="+p_dossier+"&a=rm&d_id="+p_id;
var action=new Ajax.Request (
"show_document.php",
{
method:'get',
parameters:queryString,
onFailure:errorRemoveDoc,
onSuccess:successRemoveDoc
}
);
);
}
/**
@ -53,30 +53,62 @@ function remove_document(p_dossier,p_id)
*/
function remove_operation(p_dossier,p_id)
{
queryString="gDossier="+p_dossier+"&a=rmop&id="+p_id;
var action=new Ajax.Request (
"show_document.php",
{
method:'get',
parameters:queryString,
onFailure:errorRemoveDoc,
onSuccess:successRemoveOp
}
queryString="gDossier="+p_dossier+"&a=rmop&id="+p_id;
var action=new Ajax.Request (
"show_document.php",
{
method:'get',
parameters:queryString,
onFailure:errorRemoveDoc,
onSuccess:successRemoveOp
}
);
);
}
function successRemoveOp(request,json)
{
try{
var answer=request.responseText.evalJSON(true);
var action="acop"+answer.ago_id;
$(action).innerHTML="";
var doc="op"+answer.ago_id;
$(doc).style.color="red";
$(doc).href="javascript:alert('Commentaire Effacé')";
$(doc).style.textDecoration="line-through";
}catch(e){alert(e.message);}
var answer=request.responseText.evalJSON(true);
var action="acop"+answer.ago_id;
$(action).innerHTML="";
var doc="op"+answer.ago_id;
$(doc).style.color="red";
$(doc).href="javascript:alert('Commentaire Effacé')";
$(doc).style.textDecoration="line-through";
}catch(e){
alert(e.message);
}
}
/**
*@brief remove the concerned operation of an action
*@param dossier
*@param p_id id pk action_comment_operation
*/
function remove_action(p_dossier,p_id,ag_id)
{
queryString="gDossier="+p_dossier+"&a=rmaction&id="+p_id+"&ag_id="+ag_id;
var action=new Ajax.Request (
"show_document.php",
{
method:'get',
parameters:queryString,
onFailure:ajax_misc_failure,
onSuccess:function(request,json) {
try{
var answer=request.responseText.evalJSON(true);
var action="acact"+answer.act_id;
$(action).innerHTML="";
var doc="act"+answer.act_id;
$(doc).style.color="red";
$(doc).href="javascript:alert('Action Effacée')";
$(doc).style.textDecoration="line-through";
} catch (e){ alert(e.message);}
}
}
);
}
/**
*@brief remove comment of an action
@ -85,28 +117,28 @@ function successRemoveOp(request,json)
*/
function remove_comment(p_dossier,p_id)
{
queryString="gDossier="+p_dossier+"&a=rmcomment&id="+p_id;
var action=new Ajax.Request (
"show_document.php",
{
method:'get',
parameters:queryString,
onFailure:errorRemoveDoc,
onSuccess:successRemoveComment
}
queryString="gDossier="+p_dossier+"&a=rmcomment&id="+p_id;
var action=new Ajax.Request (
"show_document.php",
{
method:'get',
parameters:queryString,
onFailure:errorRemoveDoc,
onSuccess:successRemoveComment
}
);
);
}
function successRemoveComment(request,json)
{
var answer=request.responseText.evalJSON(true);
var action="accom"+answer.agc_id;
$(action).innerHTML="";
var doc="com"+answer.agc_id;
$(doc).style.color="red";
$(doc).href="javascript:alert('Commentaire Effacé')";
$(doc).style.textDecoration="line-through";
var answer=request.responseText.evalJSON(true);
var action="accom"+answer.agc_id;
$(action).innerHTML="";
var doc="com"+answer.agc_id;
$(doc).style.color="red";
$(doc).href="javascript:alert('Commentaire Effacé')";
$(doc).style.textDecoration="line-through";
}
/**
@ -114,20 +146,20 @@ function successRemoveComment(request,json)
*/
function errorRemoveDoc()
{
alert('Impossible d\'effacer ce document');
alert('Impossible d\'effacer ce document');
}
/**
*@brief success when removing a document
*/
function successRemoveDoc(request,json)
{
var answer=request.responseText.evalJSON(true);
var action="ac"+answer.d_id;
$(action).innerHTML="";
var doc="doc"+answer.d_id;
$(doc).style.color="red";
$(doc).href="javascript:alert('Document Effacé')";
$(doc).style.textDecoration="line-through";
var answer=request.responseText.evalJSON(true);
var action="ac"+answer.d_id;
$(action).innerHTML="";
var doc="doc"+answer.d_id;
$(doc).style.color="red";
$(doc).href="javascript:alert('Document Effacé')";
$(doc).style.textDecoration="line-through";
}
/**
@ -136,17 +168,17 @@ function successRemoveDoc(request,json)
*/
function check_hour(p_ctl)
{
try
{
var h=document.getElementById(p_ctl);
var re = /^\d{1,2}:\d{2}$/;
if ( trim(h.value) !='' && ! h.value.match(re))
alert("Format de l'heure est HH:MM ")
}
catch (erreur)
{
alert('fct : check_hour '+erreur);
}
try
{
var h=document.getElementById(p_ctl);
var re = /^\d{1,2}:\d{2}$/;
if ( trim(h.value) !='' && ! h.value.match(re))
alert("Format de l'heure est HH:MM ")
}
catch (erreur)
{
alert('fct : check_hour '+erreur);
}
}
/**
@ -157,21 +189,21 @@ function check_hour(p_ctl)
function removeStock(s_id,p_dossier)
{
if ( ! confirm("Confirmez-vous l'effacement de cette entrée dans le stock?") )
{
return;
}
queryString="gDossier="+p_dossier+"&op=rm_stock&s_id="+s_id;
var action=new Ajax.Request (
"ajax_misc.php",
{
method:'get',
parameters:queryString,
onFailure:errorRemoveStock,
onSuccess:successRemoveStock
}
if ( ! confirm("Confirmez-vous l'effacement de cette entrée dans le stock?") )
{
return;
}
queryString="gDossier="+p_dossier+"&op=rm_stock&s_id="+s_id;
var action=new Ajax.Request (
"ajax_misc.php",
{
method:'get',
parameters:queryString,
onFailure:errorRemoveStock,
onSuccess:successRemoveStock
}
);
);
}
/**
@ -179,25 +211,25 @@ function removeStock(s_id,p_dossier)
*/
function errorRemoveStock()
{
alert('Impossible d\'effacer ');
alert('Impossible d\'effacer ');
}
/**
*@brief success when removing a document
*/
function successRemoveStock(request,json)
{
try
{
var answer=request.responseText.evalJSON(true);
var doc="stock"+answer.d_id;
var href="href"+answer.d_id;
$(href).innerHTML='';
try
{
var answer=request.responseText.evalJSON(true);
var doc="stock"+answer.d_id;
var href="href"+answer.d_id;
$(href).innerHTML='';
$(doc).style.color="red";
// $(doc).href="javascript:alert('Stock Effacé')";
$(doc).style.textDecoration="line-through";
} catch (e)
{
alert("success_box"+e.message);
}
$(doc).style.color="red";
// $(doc).href="javascript:alert('Stock Effacé')";
$(doc).style.textDecoration="line-through";
} catch (e)
{
alert("success_box"+e.message);
}
}

View file

@ -1175,7 +1175,7 @@ function fixed_position(p_sx,p_sy)
var sx=p_sx;
var sy=calcy(p_sy);
var str_style="top:"+sy+";left:"+sx+"position:absolute";
var str_style="top:"+sy+";left:"+sx+";position:absolute";
return str_style;
}
@ -1384,8 +1384,10 @@ function rapport_add_row(p_dossier)
*/
function search_action(dossier,ctl_concern)
{
try
{
var dossier=g('gDossier').value;
var target="search_action_div";
removeDiv(target);
var str_style=fixed_position(77, 99);
@ -1408,10 +1410,76 @@ function search_action(dossier,ctl_concern)
parameters:qs,
onFailure:null,
onSuccess:function (req){
try {
remove_waiting_box();
$('search_action').innerHTML=req.responseText;
$('search_action_div').innerHTML=req.responseText;
req.responseText.evalScripts();
}catch( e){alert(e.message);}
}
}
);
}
}catch( e){alert(e.message);}
}
function result_search_action(obj)
{
try
{
var queryString=$(obj).serialize()+"&op=search_action";
alert (queryString);
var action = new Ajax.Request(
"ajax_misc.php" ,
{method:'get',
parameters:queryString,
onFailure:ajax_misc_failure,
onSuccess:function (req){
try {
remove_waiting_box();
$('search_action_div').innerHTML=req.responseText;
req.responseText.evalScripts();
}catch( e){alert(e.message);}
}
}
)
}
catch (e)
{
alert("display_periode "+e.message);
}
return false;
}
function set_action_related(p_obj)
{
try
{
var obj=$(p_obj);
var ctlc=obj.elements['ctlc'];
for (var e=0;e<obj.elements.length;e++)
{
var elmt=obj.elements[e];
if ( elmt.type == "checkbox")
{
if (elmt.checked==true )
{
var str_name=elmt.name;
var nValue=elmt.value;
if ( $(ctlc.value).value != '') {$(ctlc.value).value+=',';}
$(ctlc.value).value+=nValue;
}
}
}
removeDiv('search_action_div');
return false;
}
catch(e)
{
alert(e.message);
return false;
}
}

View file

@ -82,3 +82,17 @@ if ( $action == 'rmcomment' )
print $json;
}
}
/* remove the action*/
if ( $action == 'rmaction' )
{
if ($User->check_action(RMDOC)==1)
{
$cn->exec_sql("delete from action_gestion_related where aga_least=$1 and aga_greatest=$2",
array($_REQUEST['id'],$_REQUEST['ag_id']));
$cn->exec_sql("delete from action_gestion_related where aga_least=$2 and aga_greatest=$1",
array($_REQUEST['id'],$_REQUEST['ag_id']));
$json=sprintf('{"act_id":"%s"}',$_REQUEST['id']);
header("Content-type: text/html; charset: utf8",true);
print $json;
}
}

View file

@ -23,10 +23,13 @@
*/
require_once('class_dossier.php');
include_once("ac_common.php");
require_once('class_action.php');
$ac=$_REQUEST['ac'];
$base='ac='.$ac;
require_once('class_follow_up.php');
$_REQUEST['ac']='FOLLOW';
Action::ShowActionList($cn,"");
echo Follow_Up::display_search($cn,true);
$sql= "true ".Follow_Up::create_query($cn);
var_dump($_GET);
echo $sql;
echo Follow_Up::short_list($cn, $sql);
?>

File diff suppressed because it is too large Load diff

View file

@ -425,7 +425,7 @@ class HtmlInput
{
$r='';
$r.='<div style="float:right;right;margin:2;">';
$r.= '<A id="close_div" HREF="javascript:void(0)" onclick="'.$javascript.'");">'.$action.'</A>';
$r.= '<A id="close_div" HREF="javascript:void(0)" onclick="'.$javascript.'"">'.$action.'</A>';
$r.='</div>';
return $r;
}

View file

@ -0,0 +1,71 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*!\file
* \brief Html Input
* - name is the name and id of the input
*/
require_once('class_html_input.php');
class IRelated_Action extends HtmlInput
{
public function __construct($p_name='',$p_value='')
{
$this->name=$p_name;
$this->value=$p_value;
$this->amount_id=null;
$this->paid='';
}
/*!\brief show the html input of the widget*/
public function input($p_name=null,$p_value=null)
{
$this->name=($p_name==null)?$this->name:$p_name;
$this->value=($p_value==null)?$this->value:$p_value;
if ( $this->readOnly==true) return $this->display();
$r=sprintf("
<INPUT TYPE=\"button\" onClick=\"search_action(".dossier::id().",'%s')\" value=\"?\">
<INPUT TYPE=\"text\" style=\"color:black;background:lightyellow;border:solid 1px grey;\" NAME=\"%s\" ID=\"%s\" VALUE=\"%s\" SIZE=\"8\" readonly>
<INPUT TYPE=\"button\" onClick=\"$('%s').value=''\" value=\"X\">
",
$this->name,
$this->name,
$this->name,
$this->value,
$this->name
);
return $r;
}
/*!\brief print in html the readonly value of the widget*/
public function display()
{
$r=sprintf("<span><b>%s</b></span>",$this->value);
$r.=sprintf('<input type="hidden" name="%s" value="%s">', $this->name,$this->value);
return $r;
}
static public function test_me()
{
}
}

View file

@ -0,0 +1,44 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/**
* @file
* @brief show button in the list of actions
*
*/
?>
<div class="content" >
<div>
<form method="get" action="do.php">
<?php echo dossier::hidden();
?>
<input type="submit" class="button" name="submit_query" value="<?= _("Ajout Action")?>">
<input type="hidden" name="ac" value="<?= $_REQUEST['ac']?>">
<input type="hidden" name="sa" value="add_action">
<?= $supl_hidden?>
<input id="bt_search" type="button" class="button" onclick="$('search_action').style.display='block'" value="<?= _('Recherche')?>">
</form>
</div>

View file

@ -0,0 +1,107 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/**
* @file
* @brief display the form for searching action
*
*/
?>
<? if (! $inner ) : ?>
<div id="search_action" class="op_detail_frame" style="position:absolute;display:none;margin-left:120px;width:70%;clear:both;z-index:2;height:auto;border:1px #000080 solid">
<? echo HtmlInput::anchor_hide('Fermer', "$('search_action').style.display='none';");?>
<? endif; ?>
<? if ( $inner ) : ?>
<div id="search_action" class="op_detail_frame">
<? echo HtmlInput::anchor_hide('Fermer', "removeDiv('search_action_div');");?>
<? endif; ?>
<h2 class="info">
<?= _('Recherche avancée')?>
</h2>
<? if (! $inner ) : ?>
<form method="get" action="do.php" style="padding:10px">
<? endif; ?>
<? if ( $inner ) : ?>
<form method="get" id="fsearchaction" style="padding:10px" onsubmit="result_search_action('fsearchaction');return false;">
<?=HtmlInput::hidden('ctlc',$_GET['ctlc'])?>
<? endif; ?>
<?= dossier::hidden()?>
<table style="width:100%">
<tr>
<td style="width:180px;text-align:right"> Numéro document</td>
<td>
<? $num=new INum('ag_id');echo $num->input();?>
</td>
<tr>
<td style="width:180px;text-align:right"><? echo _('Destinataire')?></td>
<? $label=$w->id."_label";?>
<td ><?= $w->input() . $w->search()?><span id="<?=$label?>"></span></td>
<tr>
<tr>
<td style="text-align:right" ><?= _("Profile")?></td>
<td><?= $str_ag_dest?></td>
</tr>
<td style="text-align:right"><? printf(_('contenant le mot'))?></td>
<td ><input class="input_text" style="width:100%" type="text" name="query" value="<?= $a?>"></td>
</tr>
<tr>
<td style="text-align:right"><?= _('Type de document')?></td>
<td><? echo $type_doc->input();?></td>
</tr>
<tr>
<td style="text-align:right">
<? printf(_("Après le "))?>
</td>
<td >
<?= $start->input()?>
</td>
</tr>
<tr>
<td style="text-align:right"><?= _('Avant le')?></td>
<td>
<?= $end->input()?>
</td>
</tr>
</tr>
<tr>
<td style="text-align:right">
<?= _('inclure les actions fermées ')?>
</td>
<td>
<?= $see_all->input()?>
</td>
</tr>
<tr>
<td style="text-align:right"><?= _('les actions affectées à d\'autres')?></td>
<td><?= $my_action->input()?>
</td>
</tr>
</table>
<input type="submit" class="button" name="submit_query" value="<?= _('recherche')?>">
<input type="hidden" name="sa" value="list">
<?= $supl_hidden?>
<? echo HtmlInput::button_anchor(_('Fermer'), 'javascript:void(0)', 'fsearch_form', 'onclick="$(\'search_action\').style.display=\'none\';"');?>
</form>
</div>

View file

@ -0,0 +1,84 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/**
* @file
* @brief show the result of a search into a inner windows
*
*/
?>
<form onsubmit="set_action_related('fresultaction');return false;" id="fresultaction">
<?=HtmlInput::hidden('ctlc',$_GET['ctlc'])?>
<table class="result">
<tr>
<th>
</th>
<th>
Date
</th>
<th>
Ref
</th>
<th>
Titre
</th>
<th>
Destinataire
</th>
<th>
Type
</th>
</tr>
<? for ($i=0;$i<$limit;$i++):?>
<? $class=($i%2==0)?' class="odd" ':' class="info"'; ?>
<tr <?=$class?>>
<td>
<?
$ck=new ICheckBox('ag_id[]');
$ck->value=$a_row[$i]['ag_id'];
echo $ck->input();
?>
</td>
<td >
<?=h($a_row[$i]['my_date'])?>
</td>
<td>
<?=h($a_row[$i]['ag_ref'])?>
</td>
<td>
<?=h($a_row[$i]['sub_ag_title'])?>
</td>
<td>
<?=h($a_row[$i]['name'])?>
</td>
<td>
<?=h($a_row[$i]['dt_value'])?>
</td>
</tr>
<? endfor;?>
</table>
<?=HtmlInput::submit("save_action", "Mettre à jour")?>
</form>

View file

@ -8,7 +8,7 @@
?>
</div>
<h2 class="gest_name"><?php echo $sp->input(); ?></h2>
<div style="float:left;width:30%">
<div style="float:left;width: 45%">
<table >
@ -86,7 +86,7 @@
<?echo $str_add_button;?>
</div>
<div style="float:left;width:30%">
<div style="float:left;width:45%">
<table>
<tr>
@ -140,8 +140,9 @@
</table>
</div>
<div style="float:left;width:40%">
<h4 style="display:inline">Opérations</h3>
<div style="float:right;clear:both"></div>
<div style="float:left;width:45%">
<h4 style="display:inline">Opérations</h4>
<ol>
<?
@ -159,6 +160,26 @@
</ol>
<?=$iconcerned->input()?>
</div>
<div style="float:left;width:45%">
<h4 style="display:inline">Actions concernées</h4>
<ol>
<?
for ($o=0;$o<count($action);$o++)
{
$rmAction=sprintf("javascript:if ( confirm('"._('Voulez-vous effacer cette action ')."')==true ) {remove_action('%s','%s','%s');}",
dossier::id(),
$action[$o]['ag_id'],$_REQUEST['ag_id']);
$js= '<a class="mtitle" style="color:orange" id="acact'.$action[$o]['ag_id'].'" href="'.$rmAction.'">Effacer</a>';
echo '<li id="act'.$action[$o]['ag_id'].'">'.$action[$o]['str_date']." ".h($action[$o]['sub_title'])." "
.$js.'</li>';
}
?>
</ol>
<?=$iaction->input()?>
</div>
</fieldset>
<fieldset>
<legend>
@ -187,16 +208,19 @@ function small(p_id_textarea){
<h4 class="info"> <?=_('Commentaire')?></h4>
<div style="margin-left:100">
<?php
$style_enl='style="display:inline"';$style_small='style="display:none"';
for( $c=0;$c<count($acomment);$c++){
$rmComment=sprintf("javascript:if ( confirm('"._('Voulez-vous effacer ce commentaire ')."')==true ) {remove_comment('%s','%s');}",
dossier::id(),
$acomment[$c]['agc_id']);
$js= '<a class="mtitle" style="color:orange" id="accom'.$acomment[$c]['agc_id'].'" href="'.$rmComment.'">Effacer</a>';
echo '<p id="com'.$acomment[$c]['agc_id'].'"> n°'.$acomment[$c]['agc_id']." ".h($acomment[$c]['agc_comment']).'('.h($acomment[$c]['tech_user'])." ".smaller_date($acomment[$c]['str_agc_date']).')'.
$js.'</p>';
echo 'n°'.$acomment[$c]['agc_id'].'('.h($acomment[$c]['tech_user'])." ".smaller_date($acomment[$c]['str_agc_date']).')'.$js.
'<pre style="white-space: -moz-pre-wrap;white-space: pre-wrap;border:1px solid blue;width:70%;" id="com'.$acomment[$c]['agc_id'].'"> '.
" ".h($acomment[$c]['agc_comment']).'</pre>'
;
}
echo $desc->input();
$style_enl='style="display:inline"';$style_small='style="display:none"';
?>
<input type="button" id="bt_enlarge" <?=$style_enl?> value="+" onclick="enlarge('ag_comment');return false;">
<input type="button" id="bt_small" <?=$style_small?> value="-" style="display:none" onclick="small('ag_comment');return false;">

View file

@ -104,4 +104,59 @@ CREATE TABLE action_gestion_operation
);
COMMENT ON COLUMN action_comment_operation.ago_id IS 'pk';
COMMENT ON COLUMN action_comment_operation.ag_id IS 'fk to action_gestion';
COMMENT ON COLUMN action_comment_operation.jr_id IS 'fk to jrn';
COMMENT ON COLUMN action_comment_operation.jr_id IS 'fk to jrn';
CREATE TABLE action_gestion_related
(
aga_id bigserial NOT NULL, -- pk
aga_least bigint NOT NULL, -- fk to action_gestion
aga_greatest bigint NOT NULL,
CONSTRAINT action_gestion_related_pkey PRIMARY KEY (aga_id ),
CONSTRAINT action_gestion_related_aga_greatest_fkey FOREIGN KEY (aga_greatest)
REFERENCES action_gestion (ag_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT action_gestion_related_aga_least_fkey FOREIGN KEY (aga_least)
REFERENCES action_gestion (ag_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT ux_aga_least_aga_greatest UNIQUE (aga_least , aga_greatest )
);
COMMENT ON COLUMN action_gestion_related.aga_id IS 'pk';
COMMENT ON COLUMN action_gestion_related.aga_least IS 'fk to action_gestion, smallest ag_id';
COMMENT ON COLUMN action_gestion_related.aga_greatest IS 'fk to action_gestion greatest ag_id';
-- Trigger: trg_action_gestion_related on action_gestion_related
CREATE OR REPLACE FUNCTION comptaproc.action_gestion_related_ins_up()
RETURNS trigger AS
$BODY$
declare
nTmp bigint;
begin
if NEW.aga_least > NEW.aga_greatest then
nTmp := NEW.aga_least;
NEW.aga_least := NEW.aga_greatest;
NEW.aga_greatest := nTmp;
end if;
if NEW.aga_least = NEW.aga_greatest then
return NULL;
end if;
return NEW;
end;
$BODY$
LANGUAGE plpgsql ;
-- DROP TRIGGER trg_action_gestion_related ON action_gestion_related;
CREATE TRIGGER trg_action_gestion_related
BEFORE INSERT OR UPDATE
ON action_gestion_related
FOR EACH ROW
EXECUTE PROCEDURE comptaproc.action_gestion_related_ins_up();