Bug 1516 : réécriture du module période
This commit is contained in:
parent
b298db0b30
commit
ce011fb188
13 changed files with 1780 additions and 616 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -3032,4 +3032,339 @@ function show_all_row(p_table_id)
|
|||
mRow.show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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 danydb@aevalys.eu
|
||||
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>';
|
||||
297
include/ajax/ajax_periode.php
Normal file
297
include/ajax/ajax_periode.php
Normal file
|
|
@ -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 <dany@alchimerys.be>
|
||||
|
||||
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;
|
||||
File diff suppressed because it is too large
Load diff
76
include/class/periode_ledger.class.php
Normal file
76
include/class/periode_ledger.class.php
Normal file
|
|
@ -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 <dany@alchimerys.be>
|
||||
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
||||
162
include/class/periode_ledger_table.class.php
Normal file
162
include/class/periode_ledger_table.class.php
Normal file
|
|
@ -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 <dany@alchimerys.be>
|
||||
|
||||
|
||||
/**
|
||||
* @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>";
|
||||
}
|
||||
|
||||
}
|
||||
69
include/database/jrn_periode_sql.class.php
Normal file
69
include/database/jrn_periode_sql.class.php
Normal file
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
75
include/database/parm_periode_sql.class.php
Normal file
75
include/database/parm_periode_sql.class.php
Normal file
|
|
@ -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
|
||||
*
|
||||
*@file
|
||||
*@brief Manage the table public.parm_periode
|
||||
*/
|
||||
|
||||
/**
|
||||
* *@brief 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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 danydb@aevalys.eu
|
||||
/*! \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 )
|
||||
try
|
||||
{
|
||||
alert(_('Valeurs invalides'));
|
||||
$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);
|
||||
}
|
||||
|
||||
$choose="yes";
|
||||
}
|
||||
catch (Exception $ex)
|
||||
{
|
||||
echo_warning($ex->getMessage());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Close selected periode
|
||||
*/
|
||||
if ( isset($_POST['close_per']) )
|
||||
* Display all the periode for all ledgers
|
||||
*/
|
||||
if ($p_ledger_id==0)
|
||||
{
|
||||
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";
|
||||
}
|
||||
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>';
|
||||
|
||||
|
||||
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 )
|
||||
{
|
||||
alert(_(' Désolé mais cette période est utilisée'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$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'));
|
||||
}
|
||||
}
|
||||
$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" )
|
||||
{
|
||||
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);
|
||||
|
||||
$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é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>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue