noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 16/323: Bug 1516 : réécriture du module péri


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 16/323: Bug 1516 : réécriture du module période
Date: Wed, 14 Mar 2018 17:38:10 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit ce011fb18853700d2f07ca2c6e5e825de881493d
Author: Dany De Bontridder <address@hidden>
Date:   Sat Jan 6 18:05:35 2018 +0100

    Bug 1516 : réécriture du module période
---
 html/ajax_misc.php                           |   4 +-
 html/js/scripts.js                           | 337 +++++++++-
 html/style-r692.css                          |  28 +
 include/ajax/ajax_mod_periode.php            | 105 ---
 include/ajax/ajax_periode.php                | 297 +++++++++
 include/class/periode.class.php              | 917 ++++++++++++++++-----------
 include/class/periode_ledger.class.php       |  76 +++
 include/class/periode_ledger_table.class.php | 162 +++++
 include/database/jrn_periode_sql.class.php   |  69 ++
 include/database/parm_periode_sql.class.php  |  75 +++
 include/periode.inc.php                      | 195 +++---
 include/template/periode_add_exercice.php    | 118 +++-
 sql/upgrade.sql                              |  11 +
 13 files changed, 1779 insertions(+), 615 deletions(-)

diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 1eb27c9..438ce8a 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -122,8 +122,8 @@ $path = array(
     "todo_list"=>"ajax_todo_list",
     "history"=>"ajax_history",
     "mod_doc"=>"ajax_mod_document",
-    "input_per"=>"ajax_mod_periode",
-    "save_per"=>"ajax_mod_periode",
+    // Periode menu: PERIODE
+    'periode'=>"ajax_periode",
     "mod_predf"=>"ajax_mod_predf_op",
     "save_predf"=>"ajax_save_predf_op",
     "search_action"=>"ajax_search_action",
diff --git a/html/js/scripts.js b/html/js/scripts.js
index 3f08724..7667920 100644
--- a/html/js/scripts.js
+++ b/html/js/scripts.js
@@ -3032,4 +3032,339 @@ function show_all_row(p_table_id)
             mRow.show();
     }
     
-}
\ No newline at end of file
+}
+/**
+ * @class
+ * Periode handling
+ * Variables :
+ *   - id of the row of the periode row_per_(p_periode_id) , attribute 
exercice =per_exercice,periode_id=p_id
+ *   - (this.dialog)
+ *   - id of the table with the rows : periode_tbl
+ * 
+ * Members :
+ *   - periode_id the concerned Periode , 0 none
+ *   - p_ledger : the id of ledger (jrn_def.jrn_def_id), 0 for global
+ *   - pcallback : default ajax_misc.php (this.callback) with the parameter { 
op:'periode',gDossier,[action:display,remove,save],p_id:p_periode_id}
+ *   - dossier 
+ *   - js_obj_name : name of the js object (this.js_obj_name)
+ *   - ajax_test : file to include for debugging 
+ *   - dialog : id of the dialog box (update / add ) periode_box 
+ * 
+ */
+var Periode=function (p_ledger)  {
+    this.periode_id=0;
+    this.p_ledger=p_ledger;
+    this.dialog='periode_box';
+    this.pcallback='ajax_misc.php';
+    this.dossier=0;
+    this.js_obj_name="";
+    this.ajax_test="";
+    this.set_callback=function (p_phpfile) { this.pcallback=p_phpfile;};
+    this.set_dossier=function (p_dosid) { this.dossier=p_dosid;};
+    /**
+     * set_js_obj_name (p_js_obj_name)
+     * We need to know the javascript variable name , to pass it to ajax and
+     * create a HTML containing the right variable
+     * @param  p_js_obj_name name of the variable js we use on caller side
+     */
+    this.set_js_obj_name=function (p_js_obj_name) { 
this.js_obj_name=p_js_obj_name;};
+    
+    /**
+     * Remove the periode , so call new Ajax and hide the row if successful
+     * otherwise show dialog box.
+     * @parameter p_periode_id is the id of periode
+     */
+    this.remove=function(p_periode_id) {
+        
+        var js_param={"gDossier":this.dossier,
+                        "op":"periode",
+                        "act":"remove",
+                        "p_id":p_periode_id,
+                        "ledger_id":0,
+                        "js_var":this.js_obj_name};
+        if ( this.ajax_test !="") {
+            js_param["TestAjaxFile"]=this.ajax_test;
+        }
+        here=this;
+        smoke.confirm("Confirmer  ?",function(e) {
+            if (e ) {
+                    waiting_box();
+                    new Ajax.Request(here.pcallback,
+                        {
+                            method:"POST",
+                            parameters:js_param,
+                            onSuccess:function(req) {
+                                var answer=req.responseText.evalJSON();
+                                remove_waiting_box();
+                                if ( answer.status=="OK" ) 
+                                { 
+                                    $("row_per_"+p_periode_id).remove();
+                                    alternate_row_color("periode_tbl");
+                                } else {
+                                    smoke.alert(answer.content);
+                                }
+                        }
+                    });
+                }
+            });
+    };
+ 
+    /**
+     * display a dialog box to update a periode, call save either display 
+     * an error box or update the row.
+     * the name of variable is requested
+     * to build the right button , javascript in the html of answer
+     * @parameter p_periode_id is the id of periode
+     */
+    this.box_display=function(p_periode_id) {
+         if ( this.js_obj_name == "") {
+            smoke.alert("ERROR BOX_ADD")
+        }
+        
+         var js_param={"gDossier":this.dossier,
+                            "op":"periode",
+                            "act":"show",
+                            "p_id":p_periode_id,
+                            "ledger_id":this.p_ledger,
+                        "js_var":this.js_obj_name};
+        if ( this.ajax_test !="") {
+            js_param["TestAjaxFile"]=this.ajax_test;
+        }
+        var here=this;
+        new Ajax.Request(here.pcallback,
+                        {
+                            method:"POST",
+                            parameters:js_param,
+                            onSuccess:function(req) {
+                                remove_waiting_box();
+                                var json=req.responseText.evalJSON();
+                                var y=calcy(100);
+                                
add_div({"id":"mod_periode","style":"position:fixed;top:"+y+"px;width:50%","cssclass":"inner_box",'html':"wait"});
+                                $('mod_periode').update(json.content);
+                        }
+                    });
+    };
+    /**
+     * close the periode, call ajax and receive a json object with the 
attribute
+     * status, content
+     * @parameter p_periode_id is the id of periode
+     */
+    this.close_periode=function(p_periode_id) {
+         if ( this.js_obj_name == "") {
+            smoke.alert("ERROR BOX_ADD")
+        }
+        
+        if ( this.ajax_test !="") {
+            js_param["TestAjaxFile"]=this.ajax_test;
+        }
+        var here=this;
+        smoke.confirm("Confirmer  ?",function(e) {
+            if (e ) {
+                    here._close(p_periode_id);
+                }
+          });
+    };
+    /**
+     * Internal function to close without confirming
+     * @param {type} p_periode_id
+     * @returns {undefined}
+     */
+     this._close=function(p_periode_id) {
+         if ( this.js_obj_name == "") {
+            smoke.alert("ERROR BOX_ADD")
+        }
+         var js_param={"gDossier":this.dossier,
+                            "op":"periode",
+                            "act":"close",
+                            "ledger_id":this.p_ledger,
+                            "p_id":p_periode_id,
+                        "js_var":this.js_obj_name
+                    };
+        if ( this.ajax_test !="") {
+            js_param["TestAjaxFile"]=this.ajax_test;
+        }
+        var here=this;
+        waiting_box();
+        new Ajax.Request(here.pcallback,
+            {
+                method:"POST",
+                parameters:js_param,
+                onSuccess:function(req) {
+                    remove_waiting_box();
+                    var json=req.responseText.evalJSON();
+                    if ( json.status == 'OK')
+                    {   
+                        $('row_per_'+p_periode_id).update(json.content);
+                        new Effect.Highlight('row_per_'+p_periode_id 
,{startcolor: '#FAD4D4',endcolor: '#F78082' });
+                    } else {
+                        smoke.alert(json.content);
+                    }
+            }
+        });
+    };
+    /**
+     * reopen the periode
+     * @parameter p_periode_id is the SQL id of parm_periode or the id of 
+     * jrn_periode
+     */
+    this.open_periode=function(p_periode_id) {
+         if ( this.js_obj_name == "") {
+            smoke.alert("ERROR BOX_ADD")
+        }
+         var js_param={"gDossier":this.dossier,
+                            "op":"periode",
+                            "act":"reopen",
+                            "ledger_id":this.p_ledger,
+                            "p_id":p_periode_id,
+                        "js_var":this.js_obj_name
+                    };
+        if ( this.ajax_test !="") {
+            js_param["TestAjaxFile"]=this.ajax_test;
+        }
+        var here=this;
+        smoke.confirm("Confirmer  ?",function(e) {
+            if (e ) {
+                    waiting_box();
+                    new Ajax.Request(here.pcallback,
+                        {
+                            method:"POST",
+                            parameters:js_param,
+                            onSuccess:function(req) {
+                              remove_waiting_box();
+                                var json=req.responseText.evalJSON();
+                                if ( json.status == 'OK')
+                                {  
+                                    
$('row_per_'+p_periode_id).update(json.content);
+                                    new 
Effect.Highlight('row_per_'+p_periode_id ,{startcolor: '#FAD4D4',endcolor: 
'#F78082' });
+                                } else {
+                                    smoke.alert(json.content);
+                                }
+                        }
+                    });
+                }      
+            });
+    };
+    /**
+     * This DOMID of the DIV containing the form is mod_periode
+     * @param {type} p_frm
+     * @returns {Boolean}
+     */
+    this.save=function(p_frm) {
+        var js_param=$(p_frm).serialize(true);
+        waiting_box();
+        js_param["js_var"]=this.js_obj_name;
+        js_param["act"]="save";
+        js_param["op"]="periode";
+        var here=this;
+        new Ajax.Request(this.pcallback,{
+           method:"POST",
+           parameters:js_param,
+           onSuccess:function (req) {
+               
+               var answer=req.responseText.evalJSON();
+               remove_waiting_box();
+               if ( answer.status == "OK") {
+                   $('row_per_'+js_param['periode_id']).update(answer.content);
+                   removeDiv('mod_periode');
+                   new Effect.Highlight('row_per_'+js_param['periode_id'] 
,{startcolor: '#FAD4D4',endcolor: '#F78082' });
+               } else {
+                   smoke.alert(answer.content);
+               }
+           }
+        });
+        return false;
+    };
+    /**
+     * Thanks the object DOMID sel_per_closed[] the selected periodes are
+     * closed 
+     * @see Periode._close
+     */
+    this.close_selected = function () {
+        var here = this;
+        var a_selected = document.getElementsByName('sel_per_close[]');
+        var count=0;
+        var i = 0;
+        for (i = 0; i < a_selected.length; i++) {
+            if (a_selected[i].checked == true) {
+                // Close the selected periode
+              count++;
+            }
+        }
+        if ( count==0){
+            smoke.signal("Sélectionner au moins une 
période",function(){},{duration:1500});
+            return;
+        }
+        smoke.confirm("Confirmer fermeture de "+count+" periode", function (e) 
{
+            if (e) {
+                var a_selected = document.getElementsByName('sel_per_close[]');
+                var i = 0;
+                for (i = 0; i < a_selected.length; i++) {
+                    if (a_selected[i].checked == true) {
+                        // Close the selected periode
+                        here._close(a_selected[i].value);
+                    }
+                }
+            }
+        }
+        );
+    };
+    /**
+     * @brief Insert a periode into the list, always at the bottom !
+     * DomId : 
+     *   # FORM id :insert_periode_frm
+     *   # DIV id = periode_add
+     *   # table id = periode_tbl
+     */
+    this.insert_periode=function() {    
+        var p_frm='insert_periode_frm';
+        var js_param=$(p_frm).serialize(true);
+        waiting_box();
+        js_param["js_var"]=this.js_obj_name;
+        js_param["act"]="insert_periode";
+        js_param["op"]="periode";
+        js_param["p_id"]="-1";
+        js_param["ledger_id"]="0";
+        var here=this;
+        new Ajax.Request(this.pcallback,{
+           method:"POST",
+           parameters:js_param,
+           onSuccess:function (req) {
+               var answer=req.responseText.evalJSON();
+               remove_waiting_box();
+               if ( answer.status == "OK") {
+                     var new_row=document.createElement("tr");
+                     $('periode_tbl').append(new_row);
+                     new_row.replace(answer.content);
+                     
+                     // hide the form
+                     $('periode_add').hide();
+                   new Effect.Highlight('row_per_'+answer.p_id ,{startcolor: 
'#FAD4D4',endcolor: '#F78082' });
+                    alternate_row_color('periode_tbl');
+               } else {
+                   smoke.alert(answer.content);
+               }
+           }
+        });
+        return false;   
+}
+    
+}
+/**
+ * Show the periodes from the exercice contained into the id (p_exercice_sel)
+ * @param p_table_id DOM ID of the table
+ */
+Periode.filter_exercice=function (p_table_id) {
+    var rows=$(p_table_id).rows;
+    var selected_value=$('p_exercice_sel').value;
+    for (var i=1;i<rows.length;i++) {
+        var exercice=rows[i].getAttribute("per_exercice");
+        if ( selected_value == -1 ) {
+            rows[i].show();
+        } else if ( selected_value == exercice) {
+            rows[i].show();
+        } else {
+            rows[i].hide();
+        }
+        
+    }
+};
diff --git a/html/style-r692.css b/html/style-r692.css
index 96f5e81..3128239 100644
--- a/html/style-r692.css
+++ b/html/style-r692.css
@@ -1137,12 +1137,27 @@ span.invoice
 a.nav,div.content a.nav {
     display:inline;
     text-decoration:none;
+    cursor:pointer;
 }
 a.nav:hover,div.content a.nav:hover{
     display:inline;
     text-decoration:none;
     background-color:#00008B;
     color:#FFFFFF;
+    cursor:pointer;
+}
+/**
+ * For button image
+ */
+
+div.content a.nav img,a.nav img {
+    cursor:pointer;
+    background: transparent;
+    
+}
+div.content a.nav:hover img,a.nav:hover img {
+    cursor:pointer;
+    background: transparent;
 }
 #dossier {
     display:inline;
@@ -2191,4 +2206,17 @@ div.select_box a {
 div.select_box a:hover,div.select_box ul li:hover {
   background-color : lightgoldenrodyellow;
   color:brown;
+}
+/**
+ * Menu second level
+ */
+div.menu2 td.mtitle, div.menu2 td.mtitle a{
+    background-color: white;
+    color:darkblue;
+    border-style: solid;
+    border-width: 0.1px;
+    border-color:lightgrey;
+}
+div.menu2 td.mtitle a{
+    border-width:0px;
 }
\ No newline at end of file
diff --git a/include/ajax/ajax_mod_periode.php 
b/include/ajax/ajax_mod_periode.php
deleted file mode 100644
index c82f756..0000000
--- a/include/ajax/ajax_mod_periode.php
+++ /dev/null
@@ -1,105 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS 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.
- *
- *   NOALYSS 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 NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class/periode.class.php';
-
-/**\file
- * \brief display or save a periode
- * variable received $op, $cn $g_user
- */
-$err = 0;
-$html = '';
-/* we check the security */
-switch ($op)
-{
-    case 'input_per':
-        $per = new Periode($cn, $_GET['p_id']);
-        $per->load();
-        $limit = $per->get_date_limit($_GET['p_id']);
-
-        $p_start = new IDate('p_start');
-        $p_start->value = $limit['p_start'];
-        $p_end = new IDate('p_end');
-        $p_end->value = $limit['p_end'];
-        $p_exercice = new INum('p_exercice');
-        $p_exercice->value = $per->p_exercice;
-
-        $html = '';
-        $html.=HtmlInput::anchor_close('mod_periode');
-        $html.=h2info(_('Modification période'));
-        $html.='<p> '._('Modifier les dates de début et fin de 
période').'</p>';
-        $html.='<p class="notice">'._('Cela pourrait avoir un impact sur les 
opérations déjà existantes').'</p>';
-        $html.='<form method="post" onsubmit="return save_periode(this)">';
-        $html.=dossier::hidden();
-        $html.='<table>';
-
-        $html.=tr(td(_(' Début période : ')) . td($p_start->input()));
-        $html.=tr(td(_(' Fin période : ')) . td($p_end->input()));
-        $html.=tr(td(_(' Exercice : ')) . td($p_exercice->input()));
-        $html.='</table>';
-        $html.=HtmlInput::submit('sauver', _('sauver'));
-        $html.=HtmlInput::button('close', _('fermer'), 
'onclick="removeDiv(\'mod_periode\')"');
-        $html.=HtmlInput::hidden('p_id', $_GET['p_id']);
-        $html.='</form>';
-        break;
-    case 'save_per':
-        $per = new Periode($cn, $_POST['p_id']);
-        $per->load();
-        if (isDate($_POST['p_start']) == null ||
-                isDate($_POST['p_end'] == null) ||
-                isNumber($_POST['p_exercice']) == 0 ||
-                $_POST['p_exercice'] > 2099 ||
-                $_POST['p_exercice'] < 2000)
-        {
-            $html = '';
-            $html.=HtmlInput::anchor_close('mod_periode');
-            $html.='<h2 class="info">'._('Modifier les dates de début et fin 
de période').'</h2>';
-            $html.="<div class=\"error\">"._('Erreur date invalide')."</div>";
-
-            $html.=HtmlInput::button('close', _('fermer'), 
'onclick="removeDiv(\'mod_periode\')"');
-        }
-        else
-        {
-            $sql = "update parm_periode set 
p_start=to_date($1,'DD.MM.YYYY'),p_end=to_date($2,'DD.MM.YYYY'),p_exercice=$3 
where p_id=$4";
-            try
-            {
-                $cn->exec_sql($sql, array($_POST['p_start'], $_POST['p_end'], 
$_POST['p_exercice'], $_POST['p_id']));
-                $html = '<h2 class="info"> Modifier les dates de début et fin 
de période</h2>';
-                $html.='<h2 class="notice"> Sauvé </h2>';
-
-                $html.=HtmlInput::button('close', _('Fermer'), 'onclick="      
refresh_window();"');
-            }
-            catch (Exception $e)
-            {
-                record_log($e->getTraceAsString());
-                $html = alert($e->getTrace(), true);
-            }
-        }
-        break;
-}
-
-$html = escape_xml($html);
-header('Content-type: text/xml; charset=UTF-8');
-echo '<?xml version="1.0" encoding="UTF-8"?>';
-echo '<xml>';
-echo '<data>' . $html . '</data>';
-echo '</xml>';
diff --git a/include/ajax/ajax_periode.php b/include/ajax/ajax_periode.php
new file mode 100644
index 0000000..d217225
--- /dev/null
+++ b/include/ajax/ajax_periode.php
@@ -0,0 +1,297 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   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 (2016) Author Dany De Bontridder <address@hidden>
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+
+/**
+ * @file
+ * @brief display or save a periode variable received $op, $cn $g_user
+ * variable : 
+ * act 
+ *    # close : close a periode
+ *    # reopen  : reopen a periode
+ *    # show  : display a form for modifying / adding a period    
+ *    # remove : delete a period IF not used 
+ * 
+ * ledger_id is the SQL id of ledger
+ * 
+ * p_id is either the SQL id of parm_periode of jrn_periode, depending if 
+ * ledger_id == 0 or not
+ * The answer must be in JSON
+ */
+require_once NOALYSS_INCLUDE.'/class/periode.class.php';
+require_once NOALYSS_INCLUDE.'/class/periode_ledger.class.php';
+
+$err=0;
+$a_answer=[];
+$a_answer['status']="NOK";
+$http=new HttpInput();
+try
+{
+// action to perform
+    $act=$http->request("act");
+// Periode id 
+    $periode_id=$http->request("p_id", "number");
+// Ledger id
+    $ledger_id=$http->request("ledger_id", "number");
+// Name of the javascript variable
+    $js_var=$http->request("js_var");
+}
+catch (Exception $ex)
+{
+    $a_answer['content']=$ex->getMessage();
+    $jsson=json_encode($a_answer,
+            JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
+    header('Content-Type: application/json;charset=utf-8');
+    echo $jsson;
+    return;
+}
+/* we check the security */
+if ($g_user->check_module("PERIODE")==0)
+{
+    return;
+}
+
+switch ($act)
+{
+// Reopen a periode for specific ledger if ledger_id != 0, or all 
+// the periodes if ledger_id=0
+    case 'reopen':
+        try
+        {
+            if ($ledger_id==0)
+            {
+                $per=new Periode($cn, $periode_id);
+                $per->set_ledger(0);
+                $per->reopen();
+                $parm_periode=new Parm_periode_SQL($cn, $periode_id);
+                ob_start();
+                Periode::display_row_global($parm_periode, 0, $js_var);
+                $a_answer['content']=ob_get_clean();
+            }
+            else
+            {
+                $id=$http->post("p_id", "number");
+                $jrn_periode=new Jrn_periode_SQL($cn, $p_id);
+                $per_led=new Periode_Ledger($jrn_periode);
+                $per_led->reopen();
+                ob_start();
+                $per_led_table=new Periode_Ledger_Table($periode_id);
+                $per_led_table->display_row($per_led_table->get_a_member(), 0,
+                        $js_var);
+                $a_answer['content']=ob_get_clean();
+            }
+            $a_answer["status"]="OK";
+        }
+        catch (Exception $ex)
+        {
+            $a_answer['content']=$ex->getMessage();
+        }
+        break;
+// Close a periode for specific ledger if ledger_id != 0, or all 
+// the periodes if ledger_id=0
+    case 'close':
+        try
+        {
+            if ($ledger_id==0)
+            {
+                $per=new Periode($cn, $periode_id);
+                $per->close();
+                $parm_periode=new Parm_periode_SQL($cn, $periode_id);
+                ob_start();
+                Periode::display_row_global($parm_periode, 0, $js_var);
+                $a_answer['content']=ob_get_clean();
+            }
+            else
+            {
+                $jrn_periode=new Jrn_periode_SQL($cn, $periode_id);
+                $per_led=new Periode_Ledger($jrn_periode);
+                $per_led->close();
+                ob_start();
+                $per_led_table=new Periode_Ledger_Table($periode_id);
+                $per_led_table->display_row($per_led_table->get_a_member(), 0,
+                        $js_var);
+                $a_answer['content']=ob_get_clean();
+            }
+            $a_answer["status"]="OK";
+        }
+        catch (Exception $ex)
+        {
+            $a_answer['content']=$ex->getMessage();
+        }
+        break;
+// Add a new periode , only if ledger_id == 0
+    case 'show':
+        $per=new Periode($cn, $periode_id);
+        $per->load();
+
+        $p_exercice=new INum('p_exercice');
+        $limit=$per->get_date_limit($periode_id);
+        $p_exercice->value=$per->p_exercice;
+        $title=_('Modification période');
+        $title_par="<p>"._('Modifier les dates de début et fin de période').
+                "</p>";
+        $title_par.='<p class="notice">'._('Cela pourrait avoir un impact sur 
les opérations déjà existantes').'</p>';
+
+        $p_start=new IDate('p_start');
+        $p_start->value=$limit['p_start'];
+        $p_end=new IDate('p_end');
+        $p_end->value=$limit['p_end'];
+
+        $html='';
+        $html.=HtmlInput::title_box($title, 'mod_periode');
+        $html.=$title_par;
+        $html.=sprintf('<form method="post" id="mod_periode_frm" 
onsubmit="%s.save(\'mod_periode_frm\');return false;">',
+                $js_var); ;
+        $html.=HtmlInput::hidden("js_var", $js_var);
+        $html.=HtmlInput::hidden("periode_id", $periode_id);
+        $html.=HtmlInput::hidden("ledger_id", $ledger_id);
+        $html.=dossier::hidden();
+        $html.='<table>';
+
+        $html.=tr(td(_(' Début période : ')).td($p_start->input()));
+        $html.=tr(td(_(' Fin période : ')).td($p_end->input()));
+        $html.=tr(td(_(' Exercice : ')).td($p_exercice->input()));
+        $html.='</table>';
+        $html.=HtmlInput::submit('sauver', _('sauver'));
+        $html.=HtmlInput::button('close', _('fermer'),
+                        'onclick="removeDiv(\'mod_periode\')"');
+        $html.=HtmlInput::hidden('p_id', $periode_id);
+        $html.='</form>';
+        $a_answer['content']=$html;
+        break;
+// Save a modification of a periode
+// @todo must be adapted
+    case 'save':
+        $per=new Periode($cn, $periode_id);
+        $per->load();
+        try
+        {
+            $p_start=$http->post("p_start", "date");
+            $p_end=$http->post("p_end", "date");
+            $p_exercice=$http->post("p_exercice", "number");
+            if ($p_exercice>2099||$p_exercice<1980)
+            {
+                $html='';
+                $html.=_('Erreur exercice invalide');
+            }
+            else
+            {
+                $sql="update parm_periode set 
p_start=to_date($1,'DD.MM.YYYY'),p_end=to_date($2,'DD.MM.YYYY'),p_exercice=$3 
where p_id=$4";
+                try
+                {
+                    $cn->exec_sql($sql,
+                            array($p_start, $p_end, $p_exercice, $periode_id));
+                    $a_answer["status"]="OK";
+                }
+                catch (Exception $e)
+                {
+                    record_log($e->getTraceAsString());
+                    $html=$e->getTrace();
+                    throw $e;
+                }
+            }
+            $parm_periode=new Parm_periode_SQL($cn, $periode_id);
+            ob_start();
+            Periode::display_row_global($parm_periode, 0, $js_var);
+            $a_answer['content']=ob_get_clean();
+        }
+        catch (Exception $ex)
+        {
+            $html=$ex->getTrace();
+            $a_answer['content']=$html;
+        }
+        break;
+    case "remove":
+        try
+        {
+            $per=new Periode($cn, $periode_id);
+            $per->verify_delete();
+            $per->delete();
+            $a_answer['status']="OK";
+        }
+        catch (Exception $ex)
+        {
+            $a_answer["content"]=$ex->getMessage();
+        }
+        break;
+//    case "add_per":
+//        $per=new Periode($cn, $periode_id);
+//        $per->load();
+//
+//        $p_exercice=new ISelect('p_exercice');
+//        $p_exercice->value=$cn->make_array("select distinct 
p_exercice,p_exercice from parm_periode order by 1 desc");
+//        $title=_('Ajout période');
+//        $title_par="<p>"._('On ne peut ajouter une période que sur un 
exercice qui existe').
+//                "</p>";
+//
+//        $p_start=new IDate('p_start');
+//        $p_end=new IDate('p_end');
+//
+//        $html='';
+//        $html.=HtmlInput::title_box($title, 'mod_periode');
+//        $html.=$title_par;
+//        $html.='<form method="post">' ;
+//        $html.=HtmlInput::hidden("ac", $http->post("ac"));
+//        $html.=Dossier::hidden();
+//        $html.='<table>';
+//
+//        $html.=tr(td(_(' Début période : ')).td($p_start->input()));
+//        $html.=tr(td(_(' Fin période : ')).td($p_end->input()));
+//        $html.=tr(td(_(' Exercice : ')).td($p_exercice->input()));
+//        $html.='</table>';
+//        $html.=HtmlInput::submit('add_per', _('sauver'));
+//        $html.=HtmlInput::button('close', _('fermer'),
+//                        'onclick="removeDiv(\'mod_periode\')"');
+//        $html.='</form>';
+//        $a_answer['content']=$html;
+//        break;
+    case 'insert_periode':
+        try
+        {
+            $p_start=$http->post("p_start", "date");
+            $p_end=$http->post("p_end", "date");
+            $p_exercice=$http->post("p_exercice", "number");
+            $obj=new Periode($cn);
+            $p_id=$obj->insert($p_start, $p_end, $p_exercice);
+            $parm_periode=new Parm_periode_SQL($cn, $p_id);
+            ob_start();
+            Periode::display_row_global($parm_periode, 0, $js_var);
+            $a_answer['content']=ob_get_clean();
+            $a_answer['status']="OK";
+            $a_answer['p_id']=$p_id;
+        }
+        catch (Exception $e)
+        {
+            $a_answer['content']=$e->getMessage();
+        }
+        break;
+    default:
+        $a_answer['content']=_("Invalid command")."[$act]";
+        break;
+}
+
+$jsson=json_encode($a_answer,
+        JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
+if (!headers_sent())
+    header('Content-Type: application/json;charset=utf-8');
+echo $jsson;
diff --git a/include/class/periode.class.php b/include/class/periode.class.php
index 92315bb..63ad8da 100644
--- a/include/class/periode.class.php
+++ b/include/class/periode.class.php
@@ -1,4 +1,5 @@
 <?php
+
 /*
  *   This file is part of NOALYSS.
  *
@@ -15,169 +16,190 @@
  *   You should have received a copy of the GNU General Public License
  *   along with NOALYSS; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
+ */
 
 // Copyright Author Dany De Bontridder address@hidden
 
-/*!\file
+/* !\file
  * \brief definition of the class periode
  */
-/*!
+/* !
  * \brief For the periode tables parm_periode and jrn_periode
  */
-require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once  NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE."/database/parm_periode_sql.class.php";
+
 class Periode
 {
-    var $cn;                   /*!< database connection */
-    var $jrn_def_id;           /*!< the jr, 0 means all the ledger*/
-    var $p_id;                 /*!< pk of parm_periode */
-    var $status;                       /*!< status is CL for closed, OP for
-                                           open and CE for centralized */
-    var $p_start;                      /*!< start of the periode */
-    var $p_end;                        /*!< end of the periode */
-    function __construct($p_cn,$p_id=0)
+
+    var $cn;   /* !< database connection */
+    var $jrn_def_id;  /* !< the jr, 0 means all the ledger */
+    var $p_id;   /* !< pk of parm_periode */
+    var $status;   /* !< status is CL for closed, OP for
+      open and CE for centralized */
+    var $p_start;   /* !< start of the periode */
+    var $p_end;   /* !< end of the periode */
+
+    function __construct($p_cn, $p_id=0)
     {
         $this->p_id=$p_id;
         $this->cn=$p_cn;
+        $this->jrn_def_id=0;
     }
-    function set_jrn($p_jrn)
+
+    function set_ledger($p_jrn)
     {
         $this->jrn_def_id=$p_jrn;
     }
+
     function set_periode($pp_id)
     {
         $this->p_id=$pp_id;
     }
-    /*!\brief return the p_id of the start and the end of the exercice
-     *into an array
-     *\param $p_exercice
-     *\return array [start]=>,[end]=>
+
+    /* !\brief return the p_id of the start and the end of the exercice
+     * into an array
+     * \param $p_exercice
+     * \return array [start]=>,[end]=>
      */
+
     function limit_year($p_exercice)
     {
         $sql_start="select p_id from parm_periode where p_exercice=$1 order by 
p_start  ASC limit 1";
-        $start=$this->cn->get_value($sql_start,array($p_exercice));
+        $start=$this->cn->get_value($sql_start, array($p_exercice));
         $sql_end="select p_id from parm_periode where p_exercice=$1 order by 
p_end  DESC limit 1";
-        $end=$this->cn->get_value($sql_end,array($p_exercice));
-        return array("start"=>$start,"end"=>$end);
+        $end=$this->cn->get_value($sql_end, array($p_exercice));
+        return array("start"=>$start, "end"=>$end);
     }
-    /*!\brief check if a periode is closed. If jrn_def_id is set to a no zero 
value then check only for this ledger
-     *\return 1 is the periode is closed otherwise return 0
+
+    /* !\brief check if a periode is closed. If jrn_def_id is set to a no zero 
value then check only for this ledger
+     * @see Periode::set_ledger
+     * \return 1 is the periode is closed otherwise return 0
      */
+
     function is_closed()
     {
-        if ( $this->jrn_def_id != 0 )
+        if ($this->jrn_def_id!=0)
             $sql="select status from jrn_periode ".
-                 " where jrn_def_id=".$this->jrn_def_id.
-                 " and p_id =".$this->p_id;
+                    " where jrn_def_id=".$this->jrn_def_id.
+                    " and p_id =".$this->p_id;
         else
             $sql="select p_closed as status from parm_periode ".
-                 " where ".
-                 " p_id =".$this->p_id;
+                    " where ".
+                    " p_id =".$this->p_id;
         $res=$this->cn->exec_sql($sql);
-        $status=Database::fetch_result($res,0,0);
-        if ( $status == 'CL' || $status=='t' ||$status=='CE')
+        $status=Database::fetch_result($res, 0, 0);
+        if ($status=='CL'||$status=='t'||$status=='CE')
             return 1;
         return 0;
     }
+
     ///Return 1 if the periode is open otherwise 0
     //!\note For only a ledger you must set Periode::jrn_def_id to the ledger 
id
+    ///@see Periode::set_ledger
     function is_open()
     {
         /* if jrn_Def_id == 0 then we check the global otherwise we check
-           a ledger */
-        if ( $this->jrn_def_id != 0 )
+          a ledger */
+        if ($this->jrn_def_id!=0)
             $sql="select status from jrn_periode ".
-                 " where jrn_def_id=".$this->jrn_def_id.
-                 " and p_id =".$this->p_id;
+                    " where jrn_def_id=".$this->jrn_def_id.
+                    " and p_id =".$this->p_id;
         else
             $sql="select p_closed as status from parm_periode ".
-                 " where ".
-                 " p_id =".$this->p_id;
+                    " where ".
+                    " p_id =".$this->p_id;
         $res=$this->cn->exec_sql($sql);
-        $status=Database::fetch_result($res,0,0);
-        if ( $status == 'OP' || $status=='f' )
+        $status=Database::fetch_result($res, 0, 0);
+        if ($status=='OP'||$status=='f')
             return 1;
         return 0;
     }
+
     ///Return 1 if periode is centralized
+    ///@deprecated
     //!\note deprecated , centralization not used anymore
     function is_centralized()
     {
-        if ( $this->jrn_def_id != 0 )
+        if ($this->jrn_def_id!=0)
             $sql="select status from jrn_periode ".
-                 " where jrn_def_id=".$this->jrn_def_id.
-                 " and p_id =".$this->p_id;
+                    " where jrn_def_id=".$this->jrn_def_id.
+                    " and p_id =".$this->p_id;
         else
             $sql="select p_centralized as status from parm_periode ".
-                 " where ".
-                 " p_id =".$this->p_id;
+                    " where ".
+                    " p_id =".$this->p_id;
         $res=$this->cn->exec_sql($sql);
-        $status=Database::fetch_result($res,0,0);
-        if ( $status == 'CE' || $status=='t' )
+        $status=Database::fetch_result($res, 0, 0);
+        if ($status=='CE'||$status=='t')
             return 1;
         return 0;
     }
+
     function reopen()
     {
-        if ( $this->jrn_def_id == 0 )
+        if ($this->jrn_def_id==0)
         {
-         $this->cn->exec_sql("update parm_periode set 
p_closed='f',p_central='f' where p_id=$1",
-                           array($_GET['p_per']));
+            $this->cn->exec_sql("update parm_periode set 
p_closed='f',p_central='f' where p_id=$1",
+                    array($this->p_id));
 
-         $this->cn->exec_sql("update jrn_periode set status='OP' ".
-                                " where p_id = ".$this->p_id);
+            $this->cn->exec_sql("update jrn_periode set status='OP' ".
+                    " where p_id = $1", [$this->p_id]);
 
-         return;
+            return;
         }
         else
         {
-            $this->cn->exec_sql("update jrn_periode set status='OP' ".
-                                " where jrn_def_id=".$this->jrn_def_id." and ".
-                                " p_id = ".$this->p_id);
-           /* if one ledger is open then the periode is open */
-           $this->cn->exec_sql("update parm_periode set p_closed=false where 
p_id=".$this->p_id);
+            $this->cn->exec_sql("update jrn_periode set status='OP'
+                                 where jrn_def_id=$1 and 
+                                 p_id = $2 ", [$this->jrn_def_id, 
$this->p_id]);
+            /* if one ledger is open then the periode is open */
+            $this->cn->exec_sql("update parm_periode set p_closed=false where 
p_id=".$this->p_id);
             return;
         }
-
     }
+
     ///Close a periode , if Periode::jrn_def_id is set to a different value
     /// than 0 , it close only for this ledger id ; otherwise close for all 
     /// periode
     function close()
     {
-        if ( $this->jrn_def_id == 0 )
+        if ($this->jrn_def_id==0)
         {
-            $this->cn->exec_sql("update parm_periode set p_closed=true where 
p_id=".
-                                $this->p_id);
-            $this->cn->exec_sql("update jrn_periode set status='CL' ".
-                                " where p_id = ".$this->p_id);
+            $this->cn->exec_sql("update parm_periode set p_closed=true where 
p_id=$1",
+                    [$this->p_id]);
+            $this->cn->exec_sql("update jrn_periode set status='CL' 
+                                 where p_id = $1", [$this->p_id]);
 
             return;
         }
         else
         {
             $this->cn->exec_sql("update jrn_periode set status='CL' ".
-                                " where jrn_def_id=".$this->jrn_def_id." and ".
-                                " p_id = ".$this->p_id);
+                    " where jrn_def_id=$1  and 
+                                 p_id = $2", [$this->jrn_def_id, $this->p_id]);
             /* if all ledgers have this periode closed then synchro with
-            the table parm_periode
-            */
-            $nJrn=$this->cn->count_sql( "select * from jrn_periode where ".
-                                        " p_id=".$this->p_id);
-            $nJrnPeriode=$this->cn->count_sql( "select * from jrn_periode 
where ".
-                                               " p_id=".$this->p_id." and 
status='CL'");
-
-            if ( $nJrnPeriode==$nJrn)
-                $this->cn->exec_sql("update parm_periode set p_closed=true 
where p_id=".$this->p_id);
+              the table parm_periode
+             */
+            $nJrn=$this->cn->count_sql("select * from jrn_periode where ".
+                    " p_id=$1", [$this->p_id]);
+            $nJrnPeriode=$this->cn->count_sql("select * from jrn_periode where 
".
+                    " p_id=$1  and status='CL'", [$this->p_id]);
+
+            if ($nJrnPeriode==$nJrn)
+                $this->cn->exec_sql("update parm_periode set p_closed=true 
where p_id=$1",
+                        [$this->p_id]);
             return;
         }
-
     }
+    /**
+     * @deprecated since version 5
+     * @return type
+     */
     function centralized()
     {
-        if ( $this->jrn_def_id == 0 )
+        if ($this->jrn_def_id==0)
         {
             $this->cn->exec_sql("update parm_periode set p_central=true");
             return;
@@ -185,260 +207,87 @@ class Periode
         else
         {
             $this->cn->exec_sql("update jrn_periode set status='CE' ".
-                                " where ".
-                                " p_id = ".$this->p_id);
+                    " where ".
+                    " p_id = $1", [$this->p_id]);
             return;
         }
-
     }
-    /*!
-     * \brief Display all the periode and their status
-     *
+    /**
+     * Add new periode
+     * @param date $p_date_start
+     * @param date $p_date_end
+     * @param int $p_exercice
+     * @return int p_id of the new periode
+     * @exception Exception 10 Invalide date or exercice
      */
-
-    function display_form_periode()
+    function insert($p_date_start, $p_date_end, $p_exercice)
     {
-        $str_dossier=dossier::get();
-
-        if ( $this->jrn_def_id==0 )
+        try
         {
-            $Res=$this->cn->exec_sql("select 
p_id,to_char(p_start,'DD.MM.YYYY') as date_start,to_char(p_end,'DD.MM.YYYY') as 
date_end,p_central,p_closed,p_exercice,
-                                     (select count(jr_id) as count_op from jrn 
where jr_tech_per = p_id) as count_op
-                                     from parm_periode
-                                     order by p_start,p_end");
-            $Max=Database::num_row($Res);
-            echo '<form id="periode_frm" method="POST" onsubmit="return 
confirm_box(this,\'Confirmez-vous la fermeture des périodes choisies ?\')" >';
-            echo 
HtmlInput::array_to_hidden(array('ac','gDossier','jrn_def_id','choose'), 
$_REQUEST);
-            echo '<TABLE ALIGN="CENTER">';
-            echo "</TR>";
-            echo '<th>'.ICheckBox::toggle_checkbox("per_toggle", 
"periode_frm")."</th>";
-            echo '<TH> Date d&eacute;but </TH>';
-            echo '<TH> Date fin </TH>';
-            echo '<TH> Exercice </TH>';
-            echo "</TR>";
-
-            for ($i=0;$i<$Max;$i++)
-            {
-                $l_line=Database::fetch_array($Res,$i);
-               $class="even";
-               if ( $i % 2 == 0 )
-                 $class="odd";
-               $style='';
-               if ( $l_line['p_closed'] == 't')
-                 $style="color:red";
-                echo '<TR class="'.$class.'" style="'.$style.'">';
-                echo '<td>';
-                if ( $l_line['p_closed'] == 'f') {
-                              $per_to_close=new ICheckBox('sel_per_close[]');
-                              $per_to_close->value=$l_line['p_id'];
-                             echo $per_to_close->input();
-               }
-               echo '</td>';
-
-                echo '<TD ALIGN="CENTER"> '.$l_line['date_start'].'</TD>';
-                echo '<TD  ALIGN="CENTER"> '.$l_line['date_end'].'</TD>';
-                echo '<TD  ALIGN="CENTER"> '.$l_line['p_exercice'].'</TD>';
-
-                if ( $l_line['p_closed'] == 't' )
-                {
-                    
$closed=($l_line['p_central']=='t')?'<TD>Centralis&eacute;e</TD>':'<TD>Ferm&eacute;e</TD>';
-                    $change='<TD></TD>';
-                   $remove=sprintf(_('Nombre opérations 
%d'),$l_line['count_op']);
-                    $remove=td($remove,' class="mtitle" ');
-                    $change=td ('<A class="mtitle" HREF="javascript:void(0)"'
-                            . ' onclick="return 
confirm_box(null,\''._('Confirmez Réouverture').' ?\',function() 
{window.location=\'do.php?ac='.$_REQUEST['ac'].'&action=reopen&p_per='.$l_line['p_id'].'&'.$str_dossier.'\';}
 )"> Réouverture</A>',' class="mtitle"');
-
-                }
-                else
-                {
-                    if ($l_line['count_op'] == 0 )
-                    {
-                     $change=HtmlInput::display_periode($l_line['p_id']);
-                    }
-                    else
-                    {
-                     $change="Non modifiable";
-                    }
-                   $change=td($change,' class="mtitle" ');
-                   $reopen=td("");
-
-
-                    $remove='<TD class="mtitle">';
-
-
-                    if ($l_line['count_op'] == 0 )
-                    {
-                        
$go='do.php?'.http_build_query(array('ac'=>$_REQUEST['ac'],
-                            'action'=>'delete_per',
-                            'p_per'=>$l_line['p_id'],
-                            'gDossier'=>Dossier::id()));
-                        
-                        $remove.='<A class="mtitle" HREF="javascript:void(0)" '
-                                . 'onclick="return confirm_box 
(null,\''._('Confirmez effacement ?').'\',function() { 
window.location=\''.$go.'\'});" >'
-                                . ' Efface</A>';
-                    }
-                    else
-                    {
-                        $remove.=sprintf(_('Nombre opérations 
%d'),$l_line['count_op']);
-                    }
-                    $remove.='</td>';
-                }
-                echo $change;
-
-                echo $remove;
-
-               echo '</TR>';
 
+            if (isDate($p_date_start)==null      ||
+                    isDate($p_date_end)==null    ||
+                    strlen(trim($p_exercice))==0 ||
+                    isNumber($p_exercice) ==0    ||
+                    $p_exercice<COMPTA_MIN_YEAR  ||
+                    $p_exercice>COMPTA_MAX_YEAR)
+            {
+                throw new Exception(_("Paramètre invalide"),10);
             }
-            echo '</table>';
-            echo '<p style="text-align:center">';
-            echo HtmlInput::hidden("close_per", 1);
-            echo HtmlInput::submit('close_per_bt','Fermeture des périodes 
sélectionnées');
-            echo '</p>';
-            echo '</form>';
-            $but=new IButton('show_per_add','Ajout d\'une période');
-            $but->javascript="$('periode_add_div').show();";
-            echo $but->input();
-            echo '<div class="inner_box" style="width:40%;" 
id="periode_add_div">';
-            echo HtmlInput::title_box("Ajout d'une 
période","periode_add_div","hide");
-            echo '<FORM  METHOD="POST">';
-            echo dossier::hidden();
-           $istart=new IDate('p_date_start');
-           $iend=new IDate('p_date_end');
-           $iexercice=new INum('p_exercice');
-           $iexercice->size=5;
-            echo '<table>';
-            echo '<TR> ';
-            echo td('Date de début');
-            echo td($istart->input());
-            echo '</tr><tr>';
-            echo td('Date de fin');
-           echo td($iend->input());
-
-            echo '</tr><tr>';
-            echo td('Exercice');
-           echo td($iexercice->input());
-
-            echo '</TABLE>';
-
-            echo HtmlInput::submit('add_per','Valider');
-            echo '</FORM>';
-            echo '</div>';
-            echo create_script("$('periode_add_div').hide();new 
Draggable('periode_add_div',{starteffect:function()
-                                  {
-                                     new 
Effect.Highlight(obj.id,{scroll:window,queue:'end'});
-                                  }}
-                         );");
-        }
-        else
-        {
-            $Res=$this->cn->exec_sql("select 
p_id,to_char(p_start,'DD.MM.YYYY') as date_start,to_char(p_end,'DD.MM.YYYY') as 
date_end,status,p_exercice
-                                     from parm_periode join jrn_periode using 
(p_id) where jrn_def_id=".$this->jrn_def_id."
-                                     order by p_start,p_end");
-            $Max=Database::num_row($Res);
-            $r=$this->cn->exec_sql('select jrn_Def_name from jrn_Def where 
jrn_Def_id='.
-                                   $this->jrn_def_id);
-            $jrn_name=Database::fetch_result($r,0,0);
-            echo '<h2> Journal '.$jrn_name.'</h2>';
-            echo '<form id="periode_frm" method="POST" onsubmit="return 
confirm_box(this,\'Confirmez-vous la fermeture des périodes choisies ?\')" >';
-            echo 
HtmlInput::array_to_hidden(array('ac','gDossier','jrn_def_id','choose'), 
$_REQUEST);
-
-            echo '<TABLE ALIGN="CENTER">';
-            echo "</TR>";
-            echo '<th>'.ICheckBox::toggle_checkbox("per_toggle", 
"periode_frm")."</th>";
-            echo '<TH> Date d&eacute;but </TH>';
-            echo '<TH> Date fin </TH>';
-            echo '<TH> Exercice </TH>';
-            echo "</TR>";
-
-            for ($i=0;$i<$Max;$i++)
+            $overlap_start=$this->cn->get_value("select count(*) from 
parm_periode 
+                where
+                    p_start <= to_date($1,'DD-MM-YYYY')
+                    and p_end >= to_date($1,'DD-MM-YYYY')
+                        
+                ",[$p_date_start]);
+            $overlap_end=$this->cn->get_value("select count(*) from 
parm_periode 
+                where
+                    p_start <= to_date($1,'DD-MM-YYYY')
+                    and p_end >= to_date($1,'DD-MM-YYYY')
+                        
+                ",[$p_date_end]);
+            if ( $overlap_start > 0 || $overlap_end > 0)
             {
-                $l_line=Database::fetch_array($Res,$i);
-                if ( $l_line['status'] != 'OP' )
-                 echo '<TR style="COLOR:RED">';
-               else
-                 echo '<TR>';
-                echo '<td>';
-                if ( $l_line['status'] == 'OP') {
-                              $per_to_close=new ICheckBox('sel_per_close[]');
-                              $per_to_close->value=$l_line['p_id'];
-                             echo $per_to_close->input();
-               }
-                echo '</td>';
-                echo '<TD ALIGN="CENTER"> '.$l_line['date_start'].'</TD>';
-                echo '<TD  ALIGN="CENTER"> '.$l_line['date_end'].'</TD>';
-                echo '<TD  ALIGN="CENTER"> '.$l_line['p_exercice'].'</TD>';
-                $closed="";
-                if ( $l_line['status'] != 'OP' )
-                {
-                    $go='do.php?'.http_build_query(array('ac'=>$_REQUEST['ac'],
-                        'action'=>'reopen',
-                        'p_per'=>$l_line['p_id'],
-                        'gDossier'=>Dossier::id(),
-                        'jrn_def_id'=>$this->jrn_def_id));
-                    
-                 $closed=td ('<A class="mtitle" HREF="javascript:void(0)" '
-                          . 'onclick="return confirm_box(null,\''._('Confirmez 
Réouverture').' ?\',function() {window.location=\''.$go.'\';} );"> 
Réouverture</A>',' class="mtitle"');
-                }
-               
-                echo "$closed";
-
-                echo '</TR>';
-
+                throw new Exception (_("Période chevauchant une autre"));
             }
-            echo '</TABLE>';
-            echo '<p style="text-align:center">';
-            echo HtmlInput::submit('close_per','Fermeture des périodes 
sélectionnées');
-            echo '</p>';
-            echo '</form>';
-
-        }
-    }
-    function insert($p_date_start,$p_date_end,$p_exercice)
-    {
-        try
-        {
-
-        if (isDate($p_date_start) == null ||
-                isDate($p_date_end) == null ||
-                strlen (trim($p_exercice)) == 0 ||
-                (string) $p_exercice != (string)(int) $p_exercice
-         ||$p_exercice < COMPTA_MIN_YEAR || $p_exercice > COMPTA_MAX_YEAR)
-
-        {
-         throw new Exception ("Paramètre invalide");
-        }
-        $p_id=$this->cn->get_next_seq('s_periode');
-        $sql=sprintf(" insert into 
parm_periode(p_id,p_start,p_end,p_closed,p_exercice)".
-                     "values 
(%d,to_date('%s','DD.MM.YYYY'),to_date('%s','DD.MM.YYYY')".
-                     ",'f','%s')",
-                     $p_id,
-                     $p_date_start,
-                     $p_date_end,
-                     $p_exercice);
+            $p_id=$this->cn->get_next_seq('s_periode');
+            $sql=" insert into 
parm_periode(p_id,p_start,p_end,p_closed,p_exercice)
+                    values 
+                        ($1,
+                        to_date($2,'DD.MM.YYYY'),
+                        to_date($3,'DD.MM.YYYY'),
+                        'f',
+                        $4)";
+            
             $this->cn->start();
-            $Res=$this->cn->exec_sql($sql);
+            $Res=$this->cn->exec_sql($sql,[$p_id, $p_date_start, $p_date_end, 
$p_exercice]);
             $Res=$this->cn->exec_sql("insert into jrn_periode 
(jrn_def_id,p_id,status) ".
-                                     "select jrn_def_id,$p_id,'OP' from 
jrn_def");
+                    "select jrn_def_id,$p_id,'OP' from jrn_def");
             $this->cn->commit();
+            return $p_id;
         }
         catch (Exception $e)
         {
             record_log($e->getTraceAsString());
             $this->cn->rollback();
+            throw $e;
             return 1;
         }
         return 0;
     }
-    /*!\brief load data from database
-     *\return 0 on success and -1 on error
+
+    /* !\brief load data from database
+     * \return 0 on success and -1 on error
      */
+
     function load()
     {
-        if ($this->p_id == '') $this->p_id=-1;
+        if ($this->p_id=='')
+            $this->p_id=-1;
         $row=$this->cn->get_array("select 
p_start,p_end,p_exercice,p_closed,p_central from parm_periode where p_id=$1",
-                                  array($this->p_id));
-        if ($row == null ) return -1;
+                array($this->p_id));
+        if ($row==null)
+            return -1;
 
         $this->p_start=$row[0]['p_start'];
         $this->p_end=$row[0]['p_end'];
@@ -448,138 +297,436 @@ class Periode
         return 0;
     }
 
-    /*!\brief return the max and the min periode of the exercice given
-     *in parameter
-     *\param $p_exercice is the exercice
-     *\return an array of Periode object
+    /* !\brief return the max and the min periode of the exercice given
+     * in parameter
+     * \param $p_exercice is the exercice
+     * \return an array of Periode object
      */
+
     function get_limit($p_exercice)
     {
 
-        $max=$this->cn->get_value("select p_id from parm_periode where 
p_exercice=$1 order by p_start asc limit 1",array($p_exercice));
-        $min=$this->cn->get_value("select p_id from parm_periode where 
p_exercice=$1 order by p_start desc limit 1",array($p_exercice));
+        $max=$this->cn->get_value("select p_id from parm_periode where 
p_exercice=$1 order by p_start asc limit 1",
+                array($p_exercice));
+        $min=$this->cn->get_value("select p_id from parm_periode where 
p_exercice=$1 order by p_start desc limit 1",
+                array($p_exercice));
         $rMax=new Periode($this->cn);
         $rMax->p_id=$max;
-        if ( $rMax->load() ) throw new Exception('Periode n\'existe pas');
+        if ($rMax->load())
+            throw new Exception('Periode n\'existe pas');
         $rMin=new Periode($this->cn);
         $rMin->p_id=$min;
-        if ( $rMin->load() ) throw new Exception('Periode n\'existe pas');
-        return array($rMax,$rMin);
+        if ($rMin->load())
+            throw new Exception('Periode n\'existe pas');
+        return array($rMax, $rMin);
     }
-    /*!
+
+    /* !
      * \brief Give the start & end date of a periode
      * \param $p_periode is the periode id, if omitted the value is the 
current object
      * \return array containing the start date & the end date, index are 
p_start and p_end or NULL if
      * nothing is found
-    \verbatim
-    $ret['p_start']=>'01.01.2009'
-    $ret['p_end']=>'31.01.2009'
-    \endverbatim
+      \verbatim
+      $ret['p_start']=>'01.01.2009'
+      $ret['p_end']=>'31.01.2009'
+      \endverbatim
      */
-    public function get_date_limit($p_periode = 0)
+
+    public function get_date_limit($p_periode=0)
     {
-        if ( $p_periode == 0 ) $p_periode=$this->p_id;
+        if ($p_periode==0)
+            $p_periode=$this->p_id;
         $sql="select to_char(p_start,'DD.MM.YYYY') as p_start,
              to_char(p_end,'DD.MM.YYYY')   as p_end
              from parm_periode
              where p_id=$1";
-        $Res=$this->cn->exec_sql($sql,array($p_periode));
-        if ( Database::num_row($Res) == 0) return null;
-        return Database::fetch_array($Res,0);
-
+        $Res=$this->cn->exec_sql($sql, array($p_periode));
+        if (Database::num_row($Res)==0)
+            return null;
+        return Database::fetch_array($Res, 0);
     }
-    /*!\brief return the first day of periode
-     *the this->p_id must be set
-     *\return a string with the date (DD.MM.YYYY)
+
+    /* !\brief return the first day of periode
+     * the this->p_id must be set
+     * \return a string with the date (DD.MM.YYYY)
      */
+
     public function first_day($p=0)
     {
-               if ($p==0) $p=$this->p_id;
-        list($p_start,$p_end)=$this->get_date_limit($p);
+        if ($p==0)
+            $p=$this->p_id;
+        list($p_start, $p_end)=$this->get_date_limit($p);
         return $p_start;
     }
-    /*!\brief return the last day of periode
-     *the this->p_id must be set
-     *\return a string with the date (DD.MM.YYYY)
+
+    /* !\brief return the last day of periode
+     * the this->p_id must be set
+     * \return a string with the date (DD.MM.YYYY)
      */
+
     public function last_day($p=0)
     {
-               if ($p==0) $p=$this->p_id;
-        list($p_start,$p_end)=$this->get_date_limit($p);
+        if ($p==0)
+            $p=$this->p_id;
+        list($p_start, $p_end)=$this->get_date_limit($p);
         return $p_end;
     }
 
     function get_exercice($p_id=0)
     {
-        if ( $p_id == 0 )  $p_id=$this->p_id;
+        if ($p_id==0)
+            $p_id=$this->p_id;
         $sql="select p_exercice from parm_periode where p_id=".$p_id;
         $Res=$this->cn->exec_sql($sql);
-        if ( Database::num_row($Res) == 0) return null;
-        return Database::fetch_result($Res,0,0);
-
+        if (Database::num_row($Res)==0)
+            return null;
+        return Database::fetch_result($Res, 0, 0);
     }
-    /*!\brief retrieve the periode thanks the date_end
-    *\param $p_date format DD.MM.YYYY
+
+    /* !\brief retrieve the periode thanks the date_end
+     * \param $p_date format DD.MM.YYYY
      * \return the periode id
-     *\exception if not periode is found or if more than one periode is found
+     * \exception if not periode is found or if more than one periode is found
      */
+
     function find_periode($p_date)
     {
         $sql="select p_id from parm_periode where p_start <= 
to_date($1,'DD.MM.YYYY') and p_end >= to_date($1,'DD.MM.YYYY') ";
-        $ret=$this->cn->exec_sql($sql,array($p_date));
+        $ret=$this->cn->exec_sql($sql, array($p_date));
         $nb_periode=Database::num_row($ret);
-        if (  $nb_periode == 0 )
-            throw  (new Exception('Aucune période trouvée',101));
-        if ( $nb_periode > 1 )
-            throw  (new Exception("Trop de périodes trouvées $nb_periode pour 
$p_date",100));
-        $per=Database::fetch_result($ret,0);
+        if ($nb_periode==0)
+            throw (new Exception('Aucune période trouvée', 101));
+        if ($nb_periode>1)
+            throw (new Exception("Trop de périodes trouvées $nb_periode pour 
$p_date",
+            100));
+        $per=Database::fetch_result($ret, 0);
         $this->p_id=$per;
         return $per;
     }
+
     /**
-     *add a exerice of 13 periode
+     * add a exercice starting in year p_year with p_month month, with a 
starting 
+     * and a closing 
+     * @param $p_exercice the exercice
+     * @param $p_year the starting year
+     * @param $p_from_month starting month
+     * @param $p_month number of month of the exercice
+     * @param $p_opening 1 if we create a one-day periode for opening writings
+     * @param $p_closing  1 if we create a one-day periode for closing writings
      */
-    function insert_exercice($p_exercice,$nb_periode)
+    function insert_exercice($p_exercice, $p_year, $p_from_month, $p_month,
+            $p_opening, $p_closing)
     {
-      try
-       {
-         if ( $nb_periode != 12 && $nb_periode != 13) throw new Exception 
('Nombre de période incorrectes');
-         $this->cn->start();
-         for ($i=1;$i < 12;$i++)
-           {
-             $date_start=sprintf('01.%02d.%d',$i,$p_exercice);
-             $date_end=$this->cn->get_value("select 
to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 
day','DD.MM.YYYY')",array($date_start));
-             if ( $this->insert($date_start,$date_end,$p_exercice) != 0)
-               {
-                 throw new Exception('Erreur insertion période');
-               }
-           }
-         if ( $nb_periode==12 && 
$this->insert('01.12.'.$p_exercice,'31.12.'.$p_exercice,$p_exercice) != 0 )
-           {
-             throw new Exception('Erreur insertion période');
-           }
-         if ( $nb_periode==13)
-           {
-             if 
($this->insert('01.12.'.$p_exercice,'30.12.'.$p_exercice,$p_exercice) != 0 )    
  
-                      throw new Exception('Erreur insertion période');
-             if 
($this->insert('31.12.'.$p_exercice,'31.12.'.$p_exercice,$p_exercice) != 0 )    
    
-                      throw new Exception('Erreur insertion période');
-           }
-
-
-         $this->cn->commit();
-       }
-      catch (Exception $e)
-       {
-          record_log($e->getTraceAsString());
-         $this->cn->rollback();
-       }
+        try
+        {
+            if (isNumber($p_exercice)==0)
+                throw new Exception(_("Exercice n'est pas un nombre"));
+
+            if ($p_exercice>COMPTA_MAX_YEAR||$p_exercice<COMPTA_MIN_YEAR)
+                throw new Exception(sprintf(_("Exercice doit être entre %s et 
%s "), COMPTA_MIN_YEAR,
+                        COMPTA_MAX_YEAR));
+            if (isNumber($p_year)==0)
+                throw new Exception(_("Année n'est pas un nombre"));
+
+            if ($p_year>COMPTA_MAX_YEAR||$p_year<COMPTA_MIN_YEAR)
+                throw new Exception(sprintf(_("Année doit être entre %s et %s 
"), COMPTA_MIN_YEAR,
+                        COMPTA_MAX_YEAR));
+
+            if (isNumber($p_month)==0)
+                throw new Exception(_("Nombre de mois n'est pas un nombre"));
+            if ($p_month<1||$p_month>60)
+                throw new Exception(_("Nombre de mois doit être compris entre 
1 & 60 "));
+            if (isNumber($p_month)==0)
+                throw new Exception(_("Mois de début n'existe pas "));
+            if ($p_from_month>13||$p_from_month<1)
+                throw new Exception(_("Mois de début n'existe pas "));
+            
+            $this->cn->start();
+            $year=$p_year;
+            $month=$p_from_month;
+            for ($i=1; $i<=$p_month; $i++)
+            {
+
+                // create first a periode of day 
+                if ($i==1&&$p_opening==1)
+                {
+                    $fdate_start=sprintf('01.%02d.%d', $month, $year);
+                    $this->insert($fdate_start, $fdate_start, $p_exercice);
+
+                    $date_start=sprintf('02.%02d.%d', $month, $year);
+                    $date_end=$this->cn->get_value("select 
to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 
day','DD.MM.YYYY')",
+                            array($fdate_start));
+
+                    $date_end=sprintf('02.%02d.%d', $month, $year);
+                    $this->insert($date_start, $date_end, $p_exercice);
+                }
+                // The last month, we create a one-day periode for closing
+                elseif ($i==$p_month && $p_closing ==1 )
+                {
+                    $fdate_start=sprintf('01.%02d.%d', $month, $year);
+                    $date_end=$this->cn->get_value("select 
to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '2 
day','DD.MM.YYYY')",
+                            array($fdate_start));
+                    $this->insert($fdate_start, $date_end, $p_exercice);
+
+                    $date_end=$this->cn->get_value("select 
to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 
day','DD.MM.YYYY')",
+                            array($fdate_start));
+
+                    $this->insert($date_end, $date_end, $p_exercice);
+                    
+                }
+                else
+                {
+                    $date_start=sprintf('01.%02d.%d', $month, $year);
+                    $date_end=$this->cn->get_value("select 
to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 
day','DD.MM.YYYY')",
+                            array($date_start));
+                    if ($this->insert($date_start, $date_end, $p_exercice)!=0)
+                    {
+                        throw new Exception('Erreur insertion période');
+                    }
+                }
+                $month++;
+                if ($month == 13 )
+                {
+                        $year++;
+                        $month=1;
+                }
+            }
+        
+        $this->cn->commit();
+        }
+        catch (Exception $e)
+        {
+            record_log($e->getTraceAsString());
+            $this->cn->rollback();
+            throw $e;
+        }
+    }
+
+    /**
+     * Display a table with all the periode
+     * @param $p_js javascript variable
+     * @see scripts.js
+     */
+    static function display_periode_global($p_js)
+    {
+        $cn=Dossier::connect();
+        $periode=new Parm_Periode_SQL($cn);
+        $ret=$periode->seek(" order by   p_start asc");
+        $nb_periode=Database::num_row($ret);
+
+        if ($nb_periode==0)
+            return;
+        echo '<table class="result" id="periode_tbl">';
+        echo "<thead>";
+        echo "<tr>";
+        echo th("");
+        echo th(_("Date Début"));
+        echo th(_("Date Fin"));
+        echo th(_("Exercice"));
+        echo th(_("nb opérations"));
+        echo th(_("Status"));
+        echo "</tr>";
+        echo "</thead>";
+        echo '<tbody>';
+
+        for ($i=0; $i<$nb_periode; $i++)
+        {
+            $obj=$periode->next($ret, $i);
+            Periode::display_row_global($obj, $i, $p_js);
+        }
+        echo '</tbody>';
+        echo '</table>';
+    }
+
+    /**
+     * count the number of operation of a Periode
+     * @return integer
+     */
+    function count_operation()
+    {
+        $count=$this->cn->get_value("
+                select count(*) 
+                from 
+                    jrn 
+                where 
+                    jr_tech_per = $1", [$this->p_id]);
+        return $count;
     }
-    static function test_me()
+
+    /**
+     * @brief Display each row for the global
+     * @param $obj Parm_Periode_SQL
+     * @param $p_nb not used so far
+     * @param $p_js javascript variable
+     */
+    static function display_row_global(Parm_Periode_SQL $obj, $p_nb, $p_js)
+    {
+        $periode=new Periode($obj->cn, $obj->p_id);
+        $class=($p_nb%2==0)?"even":"odd";
+        printf('<tr id="row_per_%d" customkey="%s" per_exercice="%s" p_id="%s" 
class="%s"> ',
+                $obj->getp("p_id"), 
+                $obj->getp("p_start"),
+                $obj->getp("p_exercice"),
+                $obj->getp("p_id"), $class);
+        /**
+         * Display a checkbox to select several month to close
+         */
+        if ($obj->getp("p_closed")=="f")
+        {
+            $checkbox=new ICheckBox("sel_per_close[]");
+            $checkbox->set_attribute("per_id", $obj->getp("p_id"));
+            $checkbox->value=$obj->getp("p_id");
+            echo "<td>".$checkbox->input()."</td>";
+        }
+        else
+        {
+            echo td("");
+        }
+        echo td(format_date($obj->getp("p_start"), "YYYY-MM-DD", 
"DD.MM.YYYY"));
+        echo td(format_date($obj->getp("p_end"), "YYYY-MM-DD", "DD.MM.YYYY"));
+        echo td($obj->getp("p_exercice"));
+        $nb_operation=$periode->count_operation();
+        echo td($nb_operation);
+        $closed=$obj->getp('p_closed');
+        $status=($closed=='t')?_("Fermée"):_("Ouvert");
+        echo td($status);
+
+        // if no operation then this periode can be removed or updated
+        if ($nb_operation==0)
+        {
+            // Updatable 
+            $js=sprintf("%s.box_display('%d')", $p_js, $obj->p_id);
+            echo "<td>";
+            echo HtmlInput::image_click("crayon-mod-b24.png", $js, 
_("Effacer"));
+            echo "</td>";
+            //removable
+            $js=sprintf("%s.remove('%d')", $p_js, $obj->p_id);
+            echo "<td>";
+            echo HtmlInput::image_click("trash-24.gif", $js, _("Effacer"));
+            echo "</td>";
+        }
+        else
+        {
+            echo td(""), td("");
+        }
+
+        /// Can close if open
+        echo "<td>";
+        if ($obj->getp("p_closed")=='f')
+        {
+            $javascript=sprintf("%s.close_periode('%d')", $p_js, $obj->p_id);
+            echo HtmlInput::anchor_action(_("Fermeture"), $javascript, NULL,
+                    "line");
+        }
+        else
+        {
+            $javascript=sprintf("%s.open_periode('%d')", $p_js, $obj->p_id);
+            echo HtmlInput::anchor_action(_("Réouverture"), $javascript, NULL,
+                    "line");
+        }
+        echo "</td>";
+        echo "</tr>";
+    }
+
+    /**
+     * @brief display a form (method POST) to input a new exercice 
+     * variable in the FORM 
+     *  - p_exercice
+     *  - p_year
+     *  - nb_month
+     *  - from_month
+     *  - day_opening
+     *  - day_closing
+     */
+    static function form_exercice_add()
+    {
+        $cn=Dossier::connect();
+        $exercice=new INum('p_exercice');
+        $exercice->prec=0;
+        $exercice->value=$cn->get_value('select max(p_exercice::float)+1 from 
parm_periode');
+        $year=new INum('p_year');
+        $year->prec=0;
+        $year->value=$exercice->value;
+        $nb_month=new INum('nb_month');
+        $nb_month->prec=0;
+        $nb_month->value=12;
+        $from=new ISelect('from_month');
+        $amonth=array();
+        $month=[_('Janvier'), _('Février'), _('Mars'), _('Avril'),
+            _('Mai'), _('Juin'), _('Juillet'), _('Août'), _('Septembre'),
+            _('Octobre'), _('Novembre'), _('Décembre')];
+        for ($i=1; $i<13; $i++)
+        {
+            $strMonth=$month[($i-1)];
+            $amonth[]=array("value"=>$i, "label"=>$strMonth);
+        }
+        $from->value=$amonth;
+        $day_opening=new ICheckBox("day_opening");
+        $day_closing=new ICheckBox("day_closing");
+        $day_closing->value=1;
+        $day_opening->value=1;
+        $day_closing->set_check(1);
+        require_once NOALYSS_TEMPLATE.'/periode_add_exercice.php';
+    }
+    function delete() {
+        $this->cn->exec_sql("delete from parm_periode where 
p_id=$1",[$this->p_id]);
+    }
+    /**
+     * Verify before delete that the month is not used
+     * @exception Exception code 1 if periode used
+     */
+    function verify_delete() {
+        try {
+            if ( $this->cn->get_value("select count(*) from jrn where 
jr_tech_per =$1 ",[$this->p_id]) > 0) {
+                throw new Exception(_("Effacement impossible"), 1);
+            }
+        } catch (Exception $ex) {
+            throw $ex;
+        }
+    }
+    /**
+     * @brief Display a form for the input of a new periode
+     */
+    static  function form_periode_add($p_js_var)
+    {
+        $cn=Dossier::connect();
+        $p_exercice=new ISelect('p_exercice');
+        $p_exercice->value=$cn->make_array("select distinct 
p_exercice,p_exercice from parm_periode order by 1 desc");
+        $title=_('Ajout période');
+        $title_par="<p>"._('On ne peut ajouter une période que sur un exercice 
qui existe déjà').
+                "</p>";
+
+        $p_start=new IDate('p_start');
+        $p_end=new IDate('p_end');
+
+        $html='';
+        $html.=HtmlInput::title_box($title, 'periode_add','hide');
+        $html.=$title_par;
+        $html.='<form method="post" id="insert_periode_frm" 
onsubmit="'.$p_js_var.'.insert_periode();return false;">' ;
+        $html.=HtmlInput::hidden("ac", $_REQUEST['ac']);
+        $html.=Dossier::hidden();
+        $html.='<table>';
+
+        $html.=tr(td(_(' Début période : ')).td($p_start->input()));
+        $html.=tr(td(_(' Fin période : ')).td($p_end->input()));
+        $html.=tr(td(_(' Exercice : ')).td($p_exercice->input()));
+        $html.='</table>';
+        $html.=HtmlInput::submit('add_per', _('sauver'));
+        $html.=HtmlInput::button('close', _('fermer'),
+                        'onclick="$(\'periode_add\').hide()"');
+        $html.='</form>';
+        echo $html;
+    }
+    /**
+     address@hidden 
+     */
+    static function filter_exercice($p_sel) 
     {
         $cn=Dossier::connect();
-        $obj=new Periode($cn);
-        $obj->set_jrn(1);
-        $obj->display_form_periode();
+        $i_exercice=new ISelect("p_exercice_sel");
+        $i_exercice->value=$cn->make_array("select distinct 
p_exercice,p_exercice from parm_periode order by 1 desc", 1);
+        
$i_exercice->javascript="onchange=\"Periode.filter_exercice('periode_tbl')\"";
+        $i_exercice->selected=$p_sel;
+        echo $i_exercice->input();
     }
 }
diff --git a/include/class/periode_ledger.class.php 
b/include/class/periode_ledger.class.php
new file mode 100644
index 0000000..f172df5
--- /dev/null
+++ b/include/class/periode_ledger.class.php
@@ -0,0 +1,76 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   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 (2016) Author Dany De Bontridder <address@hidden>
+
+/**
+ * @file
+ * @brief Manage the periode of a specific ledger 
+ */
+require_once NOALYSS_INCLUDE."/class/periode_ledger_table.class.php";
+require_once NOALYSS_INCLUDE."/class/periode.class.php";
+/**
+ * @brief Manage the periode of a specif ledger, wrap the SQL Class 
Jrn_Periode_SQL
+ * @see Periode
+ * @see Periode_Ledger_Table
+ * 
+ */
+class Periode_Ledger
+{
+    private $m_jrn_periode_sql;
+    function __construct(Jrn_periode_SQL $p_jrn_periode_sql)
+    {
+        $this->m_jrn_periode_sql=$p_jrn_periode_sql;
+    }
+    public function get_jrn_periode_sql()
+    {
+        return $this->m_jrn_periode_sql;
+    }
+
+    public function set_jrn_periode_sql($m_jrn_periode_sql)
+    {
+        $this->m_jrn_periode_sql=$m_jrn_periode_sql;
+    }
+    /**
+     * Close the month / periode for the ledger , 
+     * Call Periode->close()
+     * @see Periode::close
+     */
+    function close() 
+    {
+        $cn=Dossier::connect();
+        $jrn_periode_sql=$this->m_jrn_periode_sql;
+        $periode=new Periode($cn,$jrn_periode_sql->getp("p_id"));
+        $periode->set_ledger($this->m_jrn_periode_sql->getp("jrn_def_id"));
+        $periode->close();
+    }
+     /**
+     * Reopen the month / periode for the ledger , 
+     * Call Periode->reopen()
+     * @see Periode::reopen
+     */
+    function reopen() 
+    {
+        $cn=Dossier::connect();
+        $periode=new Periode($cn,$this->m_jrn_periode_sql->getp("p_id"));
+        $periode->jrn_def_id=$this->m_jrn_periode_sql->getp("jrn_def_id");
+        $periode->reopen();
+    }
+}
+
diff --git a/include/class/periode_ledger_table.class.php 
b/include/class/periode_ledger_table.class.php
new file mode 100644
index 0000000..d4c4da5
--- /dev/null
+++ b/include/class/periode_ledger_table.class.php
@@ -0,0 +1,162 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   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 (2016) Author Dany De Bontridder <address@hidden>
+
+
+/**
+ * @file
+ * @brief Manage the periode per ledger, used the table jrn_periode
+ * @example periode-ledger-test.php
+ */
+require_once NOALYSS_INCLUDE.'/database/jrn_periode_sql.class.php';
+
+/**
+ * @brief Display the periode per ledger: close : reopen ...
+ * the close , open must be done thanks Periode
+ * @see Periode
+ */
+class Periode_Ledger_Table
+{
+
+    private $sql;
+    private $a_member;
+    private $cn;
+    
+    function __construct($p_id)
+    {
+        $this->a_member["id"]=$p_id;
+        $this->sql="select 
id,p_id,status,p_id,p_start,p_end,p_closed,p_exercice,jrn_def_id
+                from 
+                 jrn_periode 
+                 join parm_periode using (p_id)";
+        $this->cn=Dossier::connect();
+        $this->a_member=$this->cn->get_row($this->sql." where id = $1",
+                [$this->a_member["id"]]);
+        
+    }
+    public function get_a_member()
+    {
+        return $this->a_member;
+    }
+
+
+    function set_id($p_id)
+    {
+        $a_member['id']=$p_id;
+    }
+    /**
+     * Load a row and return it as an array
+     * @return type
+     */
+    function load()
+    {
+        $this->a_member=$this->cn->get_row($this->sql." where id = $1",
+                [$this->a_member["id"]]);
+        return $this->a_member;
+    }
+    function get_resource_periode_ledger($p_ledger_id) 
+    {
+        $ret=$this->cn->exec_sql($this->sql." where jrn_def_id = $1 order by 
p_start desc",[$p_ledger_id]);
+        return  $ret;
+    }
+    /**
+     * Display all the periode for a specific ledger 
+     * the ledger is in m_jrn_periode_sql
+     * 
+     * @param type $p_resource_psql resource SQL
+     * @param type $p_js
+     * @return type
+     * @see Periode_Ledger_Table::get_resource_periode_ledger
+     */
+    function display_table($p_resource_psql, $p_js)
+    {
+        $nb_periode=Database::num_row($p_resource_psql);
+
+        if ($nb_periode==0)
+            return;
+        echo '<table class="result" id="periode_tbl">';
+        echo "<thead>";
+        echo "<tr>";
+        echo th("");
+        echo th(_("Date Début"));
+        echo th(_("Date Fin"));
+        echo th(_("Exercice"));
+        echo th("");
+        echo "</tr>";
+        echo "</thead>";
+        echo '<tbody>';
+
+        for ($i=0; $i<$nb_periode; $i++)
+        {
+            $obj=Database::fetch_array($p_resource_psql, $i);
+            $this->display_row($obj, $i, $p_js);
+        }
+        echo '</tbody>';
+        echo '</table>';
+    }
+    /**
+     * Display one row from jrn_periode with supplemental info
+     * 
+     * @param type $pa_row is an array corresponding to a_member
+     * @param type $p_num number of rows , for color
+     * @param type $p_js name of the js variable passed to ajax
+     */
+    function display_row($pa_row, $p_num, $p_js)
+    {
+        $class=($p_num%2==0)?"even":"odd";
+        printf('<tr id="row_per_%d" per_ledger="%s" per_exercice="%s" 
jrn_ledger_id="%s" class="%s"> ',
+                $pa_row["id"], $pa_row["jrn_def_id"], $pa_row["p_exercice"],
+                $pa_row["id"], $class
+        );
+        /**
+         * Display a checkbox to select several month to close
+         */
+        if ($pa_row["status"] == "OP") {
+            $checkbox=new ICheckBox("sel_per_close[]");
+            $checkbox->set_attribute("per_id", $pa_row['id']);
+            $checkbox->value=$pa_row['id'];
+            echo "<td>".$checkbox->input()."</td>";
+        }else {
+            echo td("");
+        }
+        echo td(format_date($pa_row["p_start"], "YYYY-MM-DD", "DD.MM.YYYY"));
+        echo td(format_date($pa_row["p_end"], "YYYY-MM-DD", "DD.MM.YYYY"));
+        echo td($pa_row["p_exercice"]);
+        $status=($pa_row['p_closed']=='t')?_("Fermée"):_("Ouvert");
+
+        /// Can close if open
+        echo "<td>";
+        if ($pa_row['status']=='OP')
+        {
+            $javascript=sprintf("%s.close_periode('%d')", $p_js, 
$pa_row['id']);
+            echo HtmlInput::anchor_action(_("Fermeture"), $javascript, NULL,
+                    "line");
+        }
+        elseif ($pa_row['status']=='CL')
+        {
+            $javascript=sprintf("%s.open_periode('%d')", $p_js, $pa_row['id']);
+            echo HtmlInput::anchor_action(_("Réouverture"), $javascript, NULL,
+                    "line");
+        }
+        echo "</td>";
+        echo "</tr>";
+    }
+
+}
diff --git a/include/database/jrn_periode_sql.class.php 
b/include/database/jrn_periode_sql.class.php
new file mode 100644
index 0000000..eb50639
--- /dev/null
+++ b/include/database/jrn_periode_sql.class.php
@@ -0,0 +1,69 @@
+<?php
+
+/**
+ * Autogenerated file 
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS 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.
+ *
+ *   NOALYSS 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 NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
+require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+
+
+/**
+ * class_jrn_periode_sql.php
+ *
+ * @file
+ * @brief abstract of the table public.jrn_periode */
+
+/**
+ * @brief abstract of the table public.jrn_periode 
+ */
+class Jrn_periode_SQL extends Noalyss_SQL
+{
+
+    function __construct(Database $p_cn, $p_id=-1)
+    {
+        $this->table="public.jrn_periode";
+        $this->primary_key="id";
+        /*
+         * List of columns
+         */
+        $this->name=array(
+            "id"=>"id",
+            "jrn_def_id"=>"jrn_def_id"
+            , "p_id"=>"p_id"
+            , "status"=>"status"
+        );
+        /*
+         * Type of columns
+         */
+        $this->type=array(
+            "id"=>"numeric",
+            "jrn_def_id"=>"numeric"
+            , "p_id"=>"numeric"
+            , "status"=>"text"
+        );
+
+
+        $this->default=array(
+            "id"=>"auto"
+        );
+
+        $this->date_format="DD.MM.YYYY";
+        parent::__construct($p_cn, $p_id);
+    }
+
+}
diff --git a/include/database/parm_periode_sql.class.php 
b/include/database/parm_periode_sql.class.php
new file mode 100644
index 0000000..2cbd080
--- /dev/null
+++ b/include/database/parm_periode_sql.class.php
@@ -0,0 +1,75 @@
+<?php 
+
+/**
+ * Autogenerated file 
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS 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.
+ *
+ *   NOALYSS 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 NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
+require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+
+
+/**
+ * class_parm_periode_sql.php
+ *
+ address@hidden
+ address@hidden Manage the table public.parm_periode
+ */
+
+/**
+ * address@hidden Manage the table public.parm_periode
+ */
+class Parm_periode_SQL extends Noalyss_SQL
+{
+
+function __construct(Database $p_cn,$p_id=-1)
+  {
+  $this->table = "public.parm_periode";
+  $this->primary_key = "p_id";
+/*
+ * List of columns
+ */
+  $this->name=array(
+       "p_id"=>"p_id"
+       ,"p_start"=>"p_start"
+       ,"p_end"=>"p_end"
+       ,"p_exercice"=>"p_exercice"
+       ,"p_closed"=>"p_closed"
+       ,"p_central"=>"p_central"
+        );
+/*
+ * Type of columns
+ */
+  $this->type = array(
+       "p_id"=>"numeric"
+       ,"p_start"=>"date"
+       ,"p_end"=>"date"
+       ,"p_exercice"=>"text"
+       ,"p_closed"=>"boolean"
+       ,"p_central"=>"boolean"
+          );
+ 
+
+  $this->default = array(
+  "p_id" => "auto"
+  );
+
+  $this->date_format = "DD.MM.YYYY";
+  parent::__construct($p_cn,$p_id);
+  }
+  
+
+}
\ No newline at end of file
diff --git a/include/periode.inc.php b/include/periode.inc.php
index d938ad3..fb7e62c 100644
--- a/include/periode.inc.php
+++ b/include/periode.inc.php
@@ -15,133 +15,124 @@
  *   You should have received a copy of the GNU General Public License
  *   along with NOALYSS; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
+ */
 // Copyright Author Dany De Bontridder address@hidden
-/*! \file
+/* ! \file
  * \brief add, modify, close or delete a period
  */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
 $gDossier=dossier::id();
 require_once NOALYSS_INCLUDE.'/lib/iselect.class.php';
-require_once  NOALYSS_INCLUDE.'/class/periode.class.php';
+require_once NOALYSS_INCLUDE.'/class/periode.class.php';
 echo '<div class="content">';
 $cn=Dossier::connect();
 //-----------------------------------------------------
 // Periode
 //-----------------------------------------------------
-$action="";
-if ( isset($_REQUEST['action']))
-    $action=$_REQUEST['action'];
-$choose=(isset ($_GET['choose']))?$_GET['choose']:"no";
+require_once NOALYSS_INCLUDE."/class/periode.class.php";
+require_once NOALYSS_INCLUDE."/class/periode_ledger.class.php";
+$http=new HttpInput();
 
-if ($choose=='Valider') $choose='yes';
+$p_ledger_id=$http->request("jrn_def_id", "number", 0);
+?>
+<script>
+    var jsper = new Periode(<?php echo $p_ledger_id; ?>);
+    jsper.set_callback("ajax_misc.php");
+    jsper.set_js_obj_name("jsper");
+    jsper.set_dossier('<?php echo Dossier::id(); ?>');
 
-if ( isset ($_POST["add_per"] ))
-{
-    extract($_POST, EXTR_SKIP);
-    $obj=new Periode($cn);
-    if ( $obj->insert($p_date_start,$p_date_end,$p_exercice) == 1 )
-    {
-        alert(_('Valeurs invalides'));
-    }
-    $choose="yes";
+</script>
+<?php
+//-------------------------------------------------------------------
+// Select a ledger or global
+//-------------------------------------------------------------------
+echo '<form method="GET" >';
+echo dossier::hidden();
+$sel_jrn=$cn->make_array("select jrn_def_id, jrn_def_name from ".
+        " jrn_def order by jrn_def_name");
+$sel_jrn[]=array('value'=>0, 'label'=>_('Global : periode pour tous les 
journaux'));
+$wSel=new ISelect();
+$wSel->value=$sel_jrn;
+$wSel->name='jrn_def_id';
+$wSel->selected=$p_ledger_id;
+echo _("Choisissez global ou uniquement le journal à fermer").$wSel->input();
+echo HtmlInput::submit('choose', 'Valider');
+echo HtmlInput::hidden('ac', $_REQUEST['ac']);
+echo "</form>";
+// display a filter by exercice
+echo _("Montrer l'exercice");
+$max_exercice=$cn->get_value("select max(p_exercice) from parm_periode");
+$p_exercice=$http->request("p_exercice","string",$max_exercice);
+Periode::filter_exercice($p_exercice);
 
-}
+$js_close_selected="jsper.close_selected()";
+echo HtmlInput::button_action(_("Fermer les périodes sélectionnées"),
+        $js_close_selected);
+//--------------------------------------------------------------------
+// Add an exercice 
+// receive nb_exercice
+//--------------------------------------------------------------------
 if (isset($_POST['add_exercice']))
-  {
-    $obj=new Periode($cn);
-    $exercice=$cn->get_value('select max(p_exercice::float)+1 from 
parm_periode');
-    if ( $obj->insert_exercice($exercice,$_POST['nb_exercice']) == 1 )
-    {
-        alert(_('Valeurs invalides'));
-    }
-
-    $choose="yes";
-  }
-/*
- * Close selected periode
- */  
-if ( isset($_POST['close_per']) )
-{
-       if (isset($_POST['sel_per_close'] ) ) {
-               $a_per_to_close=$_POST['sel_per_close'];
-               for ($i=0;$i < count($a_per_to_close);$i++) {
-                       $per=new Periode($cn);
-                        
$jrn_def_id=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0;
-                         $per->jrn_def_id=$jrn_def_id;
-                        $per->set_periode($a_per_to_close[$i]);
-                       $per->close();
-               
-               }
-       }
-       $choose="yes";
-}
-
-
-if ( $action== "delete_per" )
 {
-    $p_per=$_GET["p_per"];
-// Check if the periode is not used
-    if ( $cn->count_sql("select * from jrnx where j_tech_per=$p_per") != 0 )
+    $obj=new Periode($cn);
+    try
     {
-        alert(_(' Désolé mais cette période est utilisée'));
+        $p_exercice=$http->post("p_exercice", "number");
+        $p_year=$http->post("p_year", "number");
+        $nb_month=$http->post("nb_month", "number");
+        $from_month=$http->post("from_month", "number");
+        $day_opening=$http->post("day_opening", "string", 0);
+        $day_closing=$http->post("day_closing", "string", 0);
+        $exercice=new Periode($cn);
+        $exercice->insert_exercice($p_exercice, $p_year, $from_month, 
$nb_month,
+                $day_opening, $day_closing);
     }
-    else
+    catch (Exception $ex)
     {
-        $count=$cn->get_value("select count(*) from parm_periode;");
-        if ( $count > 1 ) {
-            $Res=$cn->exec_sql("delete from parm_periode where p_id=$p_per");
-        } else
-        {
-            alert(_('Désolé mais vous devez avoir au moins une période'));
-        }
+        echo_warning($ex->getMessage());
     }
-    $choose="yes";
 }
-if ( $action == 'reopen')
-  {
-    $jrn_def_id=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0;
-    $per=new Periode($cn);
-    $jrn_def_id=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0;
-    $per->set_jrn($jrn_def_id);
-    $per->set_periode($_GET['p_per']);
-    $per->reopen();
-
-    $choose="yes";
-  }
-if ( $choose=="yes" )
+/*
+ * Display all the periode for all ledgers
+ */
+if ($p_ledger_id==0)
 {
-    echo '<p>';
-    echo HtmlInput::button_anchor(_('Autre Journal 
?'),'?choose=no&ac='.$_REQUEST['ac'].'&gDossier='.dossier::id());
-    echo '</p>';
-    $per=new Periode($cn);
-    $jrn=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0;
-    $per->set_jrn($jrn);
+    echo HtmlInput::button_action(_("Ajout exercice"),
+            "\$('exercice_add').show()");
+//-------------------------------------------------------------------
+// Add a new Exercice
+//-------------------------------------------------------------------
+    echo '<div id="exercice_add" style="display:none" class="inner_box">';
+    Periode::form_exercice_add();
+    echo '</div>';
+//-------------------------------------------------------------------
+// Add a new Periode
+//-------------------------------------------------------------------
+    echo HtmlInput::button_action(_("Ajout période"), 
"\$('periode_add').show()");
+    echo '<div id="periode_add" style="display:none;width:auto" 
class="inner_box">';
+    Periode::form_periode_add("jsper");
+    echo '</div>';
 
-    $per->display_form_periode();
-    $nb_exercice=new ISelect("nb_exercice");
-    $nb_exercice->value=array(
-                             array('value'=>12,'label'=>_("12 périodes)")),
-                             array('value'=>13,'label'=>_("13 périodes"))
-                             );
-
-    require_once NOALYSS_TEMPLATE.'/periode_add_exercice.php';
+//-------------------------------------------------------------------
+// List of Periode
+//-------------------------------------------------------------------
+    $periode=new Parm_Periode_SQL($cn);
+    Periode::display_periode_global("jsper");
 }
 else
 {
-    echo '<form method="GET" >';
-    echo dossier::hidden();
-    $sel_jrn=$cn->make_array("select jrn_def_id, jrn_def_name from ".
-                             " jrn_def order by jrn_def_name");
-    $sel_jrn[]=array('value'=>0,'label'=>_('Global : periode pour tous les 
journaux'));
-    $wSel=new ISelect();
-    $wSel->value=$sel_jrn;
-    $wSel->name='jrn_def_id';
-    echo _("Choisissez global ou uniquement le journal à 
fermer").$wSel->input();
-    echo   HtmlInput::submit('choose','Valider');
-    echo HtmlInput::hidden('ac',$_REQUEST['ac']);
-    echo "</form>";
-    echo '<p class="info">'._("Pour ajouter, effacer ou modifier une 
p&eacute;riode, il faut choisir global").'</p>';
+    echo '<p class="info">'._("Pour ajouter, effacer ou modifier une période, 
il faut choisir global").'</p>';
+    $ledger=new Acc_Ledger($cn, $p_ledger_id);
+    echo h2($ledger->get_name());
+
+    $periode_ledger=new Periode_Ledger_Table(0);
+    $ret=$periode_ledger->get_resource_periode_ledger($p_ledger_id);
+    $periode_ledger->display_table($ret, "jsper");
 }
+
 echo '</div>';
 ?>
+<script>
+    Periode.filter_exercice('periode_tbl');
+</script>
diff --git a/include/template/periode_add_exercice.php 
b/include/template/periode_add_exercice.php
index bab2298..0d139d8 100644
--- a/include/template/periode_add_exercice.php
+++ b/include/template/periode_add_exercice.php
@@ -1,26 +1,104 @@
 <?php
 //This file is part of NOALYSS and is under GPL 
 //see licence.txt
-?><fieldset><legend>Ajout d'un exercice</legend>
-<ul>
-<li>
-Exercice en 12 périodes : Ajout d'un exercice comptable de 12 périodes, 
commençant le 1 janvier et terminant le 31 décembre. </li>
-<li>   Exercice en 13 périodes: Ajout d'une période d'un jour le 31/12. Cette 
période est utilisée
-pour faire toutes les écritures de fin d'exercice: amortissements, régulations 
de compte... Avec une 13ième période, cela simplifie les prévisions, les 
rapports...</li>
-<li>
-       Pour ajouter des années, ne commençant pas en janvier ou comptant un 
nombre de mois supérieur à 12, utilisez le plugin "Outils Comptables"
-</li>
-</ul>
-
-<form method="post" id="exercice_frm" onsubmit="return confirm_box(this,'<?php 
echo _("Confirmez vous l\'ajout d\'un exercice comptable ?")?>')">
-<?php 
-echo HtmlInput::hidden("ac",$_REQUEST['ac']);
-echo $nb_exercice->input();
-echo HtmlInput::hidden("jrn_def_id","0");
-echo HtmlInput::hidden("add_exercice","1");
-echo Dossier::hidden();
-echo HtmlInput::submit("add_exercicebt",_("Ajout d'un exercice comptable"));
 ?>
+<?php echo HtmlInput::title_box(_("Ajout d'un exercice"), "exercice_add",
+        "hide"); ?>
+<p>
+    
+        <?php echo _("Réserver un jour d'ouverture : le premier jour de 
l'exercice sera vue comme une période d'un seul jour pour y placer les 
opérations d'ouverture") ?>
+</p>
+<p>
+      <?php echo _("Réserver un jour de fermeture : le dernier jour de 
l'exercice sera vue comme une période d'un seul jour pour y placer les 
opérations 
+de fin d'exercice: amortissements, régulations de compte... Avec une 13ième 
période, cela simplifie les prévisions, les rapports..."); ?>/p>
 
+<form method="post" style="padding-left: 20%" id="exercice_frm" 
onsubmit="return (validate() && confirm_box($('exercice_frm'), '<?php echo 
_("Confirmez vous l\'ajout d\'un exercice comptable ?") ?>'))">
+    <?php
+    echo HtmlInput::hidden("ac", $_REQUEST['ac']);
+    echo HtmlInput::hidden("jrn_def_id", "0");
+    echo HtmlInput::hidden("add_exercice", "1");
+    echo Dossier::hidden();
+    ?>
+    <table>
+        <tr>
+            <td>
+<?= _("Exercice") ?>
+            </td>
+            <td>
+<?php echo $exercice->input() ?>
+            </td>
+        </tr>
+        <tr>
+            <td>
+<?= _('Année') ?>
+            </td>
+            <td>
+<?php echo $year->input() ?>
+            </td>
+        </tr>
+        <tr>
+            <td>
+<?= _('Nombre de mois') ?>
+            </td>
+            <td>
+<?php echo $nb_month->input() ?>
+            </td>
+        </tr>
+        <tr>
+            <td>
+<?= _("A partir du mois de") ?>
+            </td>
+            <td>
+<?php echo $from->input() ?>
+            </td>
+        </tr>
+        <tr>
+            <td>
+                <?=_("Réservé un jour pour l'ouverture (RAN)")?>
+            </td>
+            <td>
+                <?=$day_opening->input();?>
+            </td>
+        </tr>
+        <tr>
+            <td>
+                <?=_("Réservé un jour pour les opérations de fermeture ")?>
+            </td>
+            <td>
+                <?=$day_closing->input();?>
+            </td>
+        </tr>
+    </table>
+    <?php
+    echo HtmlInput::submit("add_exercicebt", _("Ajout d'un exercice 
comptable"));
+    ?>
 </form>
-</fieldset>
+<script charset="UTF8" lang="javascript">
+    function validate()
+    {
+        if (trim($('<?php echo $exercice->id ?>').value) == '') {
+            $('<?php echo $exercice->id ?>').style.borderColor = 'red';
+            smoke.alert('<?= _("Exercice invalide") ?>');
+            return false;
+        }
+        if (trim($('<?php echo $nb_month->id ?>').value) == '') {
+            $('<?php echo $nb_month->id ?>').style.borderColor = 'red';
+            smoke.alert('<?= _("Nombre de mois invalide") ?>');
+                    return false;
+        }
+        if (trim($('<?php echo $year->id ?>').value) == '') {
+            $('<?php echo $year->id ?>').style.borderColor = 'red';
+            smoke.alert('<?= _("Année invalide") ?>');
+            return false;
+        }
+        if (trim($('<?php echo $nb_month->id ?>').value) > 60 
+            ||trim($('<?php echo $nb_month->id ?>').value) < 1
+           ) {
+            $('<?php echo $nb_month->id ?>').style.borderColor = 'red';
+            smoke.alert('<?= _("Nombre de mois possible entre 1 et 60") ?>');
+                    return false;
+        }
+        return true;
+
+    }
+</script>
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index d8ff69b..217dfc0 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -58,3 +58,14 @@ CREATE TABLE public.user_filter (
        unpaid varchar NULL,
        PRIMARY KEY (id)
 );
+
+
+
+
+alter table jrn_periode drop constraint jrn_periode_pk;
+create sequence jrn_periode_id_seq;
+alter table jrn_periode add id bigint;
+alter table jrn_periode alter column   id set default  
nextval('jrn_periode_id_seq');
+update jrn_periode set id=nextval('jrn_periode_id_seq');
+alter table jrn_periode add  constraint jrn_periode_pk  primary key (id);
+alter table jrn_periode add constraint  jrn_periode_periode_ledger unique 
(jrn_def_id,p_id); 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]