Task #0001462: CA - apostrophe non affichée

Use of ManageTableSQL for improving adding , update and delete
analytic accounting
This commit is contained in:
Dany De Bontridder 2017-09-13 00:06:43 +02:00
parent 0e95617873
commit 868098e20f
5 changed files with 206 additions and 122 deletions

View file

@ -181,7 +181,9 @@ $path = array(
// Save a event given in the short form
"action_save"=>"ajax_gestion",
/* display the lettering , callebd from acc_ledger : dsp_letter*/
"dl"=>"ajax_display_letter"
"dl"=>"ajax_display_letter",
// Add , delete update anc accounting
"anc_accounting"=>"ajax_anc_accounting"
) ;
if (array_key_exists($op, $path)) {

View file

@ -28,7 +28,9 @@
if (!defined('ALLOWED'))
die('Appel direct ne sont pas permis');
require_once NOALYSS_INCLUDE.'/class/anc_plan.class.php';
require_once NOALYSS_INCLUDE.'/class/anc_account.class.php';
require_once NOALYSS_INCLUDE.'/class/anc_account_table.class.php';
require_once NOALYSS_INCLUDE.'/database/poste_analytique_sql.class.php';
$ret="";
$str_dossier=Dossier::get();
@ -45,13 +47,14 @@ if ($sa=="add_pa")
$new=new Anc_Plan($cn);
if ($new->isAppend()==true)
{
$ret.= '<div style="position:absolute;top:25%" class="inner_box">';
$ret.=HtmlInput::title_box(_('Nouveau plan'), '', 'none');
$ret.= '<div style="position:absolute;top:25%" id="anc_div_add" class="inner_box">';
$ret.=HtmlInput::title_box(_('Nouveau plan'), 'anc_div_add', 'hide');
$ret.= '<form method="post">';
$ret.=dossier::hidden();
$ret.= $new->form();
$ret.= HtmlInput::hidden("sa", "pa_write");
$ret.=HtmlInput::submit("submit", _("Enregistre"));
$ret.=HtmlInput::button_hide("anc_div_add");
$ret.= '</form>';
$ret.= '</div>';
}
@ -98,85 +101,21 @@ if ($sa=="pa_update")
$ret.="</div>";
$sa="anc_menu";
}
// show the form for add a poste
if ($sa=='po_add')
{
$po=new Anc_Account($cn);
$po->pa_id=$_REQUEST['pa_id'];
$wSa=HtmlInput::hidden("sa", "po_write");
$ret.='<div class="content">';
$ret.=h2(_("Ajout d'un poste analytique"));
$ret.='<form method="post">';
$ret.=dossier::hidden();
$ret.=$po->form();
$ret.=$wSa;
$ret.=HtmlInput::submit("add", _("Ajout"));
$ret.="</form>";
$ret.="</div>";
}
// record the poste
if ($sa=="po_write")
{
// var_dump($_POST);
$po=new Anc_Account($cn);
$po->get_from_array($_POST);
$po->add();
$sa="pa_detail";
}
/* delete pa */
if ($sa=="pa_delete")
{
$delete=new Anc_Plan($cn, $_GET['pa_id']);
$delete=new Anc_Plan($cn, $pa_id);
$delete->delete();
$sa="anc_menu";
}
/* po detail
* ---> in ajax : montre detail d'un poste analytique
*
*/
if ($sa=="po_detail")
{
$ret.=h2(_('Modification'));
$po=new Anc_Account($cn, $_GET['po_id']);
$po->get_by_id();
$ret.='<div class="content">';
$ret.='<form method="post">';
$ret.=dossier::hidden();
$ret.=$po->form();
$ret.=HtmlInput::hidden('sa', 'po_update');
$ret.=HtmlInput::submit('Correction', 'Correction');
$ret.=sprintf('<input type="button" class="smallbutton" value="Efface" onClick="return confirm_box(\'anchor_del\',\' Voulez-vous vraiment effacer cette activité\','
.'function () { window.location=\'do.php?ac='.$_REQUEST['ac'].'&sa=po_delete&po_id=%s&pa_id=%s&'.$str_dossier.'\'}) ;"',
$po->id, $_REQUEST['pa_id']
);
$ret.='</form>';
$ret.='</div>';
$sa="";
}
/**
* mise à jour po
*/
if ($sa=="po_update")
{
$po=new Anc_Account($cn);
$po->get_from_array($_POST);
$po->update();
$sa="pa_detail";
}
/**
* Efface po
*/
if ($sa=="po_delete")
{
$po=new Anc_Account($cn, $_REQUEST['po_id']);
$po->delete();
$sa="pa_detail";
}
// show the detail
if ($sa=="pa_detail")
{
$pa_id=$http->get("pa_id","numeric");
$new=new Anc_Plan($cn, $_GET['pa_id']);
$wSa=HtmlInput::hidden("sa", "pa_update");
@ -194,53 +133,26 @@ if ($sa=="pa_detail")
'onclick="return confirm_box(\'remove_analytic_plan\',\'Effacer ?\',function () {window.location=\'do.php?ac='.$_REQUEST['ac'].'&pa_id='.$_GET['pa_id'].'&sa=pa_delete&'.$str_dossier.'\';})"',
'smallbutton');
$ret.= '</form>';
/**
* Detail now
*/
//---------------------------------------------------------------------
// Detail now
// Use Manage_Table
//---------------------------------------------------------------------
$count=0;
$new=new Anc_Plan($cn, $_REQUEST['pa_id']);
$new=new Anc_Plan($cn, $pa_id);
$new->get();
$array=$new->get_poste_analytique(" order by po_name");
$ret.='<div class="content">';
$ret.='<table class="table_large">';
$ret.="<tr>";
$ret.="<th>"._("Nom")." </td>";
$ret.="<th>"._("Montant")." </td>";
$ret.="<th>"._("Description")." </td>";
$ret.="<th>"._("Groupe")."</th>";
$ret.="<th>"._("Plan A")." </td>";
$ret.="</tr>";
$class="";
foreach ($array as $obj)
{
$count++;
if ($count%2==0)
$class="even";
else
$class="odd";
$ret.="<TR class=\"$class\">";
$ret.="<TD class=\"vert_mtitle\">".
'<a style="text-decoration:underline;" href="?ac='.$_REQUEST['ac'].'&sa=po_detail&po_id='.$obj->id.'&pa_id='.$_REQUEST['pa_id'].'&'.
$str_dossier.'">'.
h($obj->name).
'</a>';
"</td>"
;
$ret.="<TD align=\"right\">".$obj->amount."</td>";
$ret.="<TD>".h($obj->description)."</td>";
$ret.="<td>".$obj->ga_id."</td>";
$ret.="<TD>".h($new->name)."</td>";
$ret.="</tr>";
}
$ret.="</table>";
// ---> montre form pour ajouter po
$ret.=HtmlInput::button_anchor(_('Ajout'),
"?ac=".$_REQUEST['ac']."&sa=po_add&pa_id=".$_GET['pa_id']."&".$str_dossier,
'', '', 'smallbutton');
$href=http_build_query(array('ac'=>$_REQUEST['ac'], 'gDossier'=>$_REQUEST['gDossier']));
$ret.= '<a style="display:inline" class="smallbutton" href="do.php?'.$href.'">'._('Retour').'</a>';
$anc=new Poste_analytique_SQL($cn);
$anc->pa_id=$pa_id;
$accounting=new Anc_Account_Table($anc);
$accounting->set_callback("ajax_misc.php");
$accounting->add_json_param("op", "anc_accounting");
$accounting->add_json_param("pa_id", $pa_id);
ob_start();
$accounting->display_table(" where pa_id = $1 order by po_name ",array($pa_id));
$accounting->create_js_script();
$ret.=ob_get_clean();
$ret.= '</div>';
}
@ -255,14 +167,16 @@ if ($sa=='anc_menu')
$list=$obj->get_list();
$ac=$http->request("ac");
if (empty($list))
{
$url=http_build_query(array("sa"=>"add_pa","ac"=>$ac,
"gDossier"=>Dossier::id()));
echo '<div class="content">';
echo '<TABLE>';
echo '<TR><TD class="vert_mtitle">';
echo '<a href="?ac='.$_REQUEST['ac'].'&sa=add_pa&'.$str_dossier.'">'._("Ajout d'un plan comptable").'</a>';
echo '<a href="?'.$url.'">'._("Ajout d'un plan comptable").'</a>';
echo '</TD></TR>';
echo '</TABLE>';
@ -274,23 +188,27 @@ if ($sa=='anc_menu')
}
else
{
$url=http_build_query(array("sa"=>"add_pa","ac"=>$ac,
"gDossier"=>Dossier::id()));
echo '<div class="content">';
echo '<table class="vert_mtitle">';
if ($obj->isAppend()==true)
{
echo '<TR><TD class="first">';
echo '<a href="?ac='.$_REQUEST['ac'].'&sa=add_pa&'.$str_dossier.'">'._("Ajout d'un plan comptable").'</a>';
echo '<a href="?'.$url.'">'._("Ajout d'un plan comptable").'</a>';
echo '</TD></TR>';
}
foreach ($list as $line)
{
$url=http_build_query(array("sa"=>"pa_detail","ac"=>$ac,"pa_id"=>$line['id'],
"gDossier"=>Dossier::id()));
echo '<TR>';
echo '<TD>'.
'<a href="?ac='.$_REQUEST['ac'].'&sa=pa_detail&pa_id='.$line['id'].'&'.$str_dossier.'">'.
'<a href="?'.$url.'">'.
h($line['name']);
echo $line['description']."</a>";
echo h($line['description'])."</a>";
echo "</td>";
echo "</TR>\n";
}

View file

@ -239,7 +239,8 @@ class Anc_Account
$wName=new IText("po_name",$this->name);
$wAmount=new INum("po_amount",$this->amount);
$wDescription=new IText("po_description",$this->description);
$aGroup_analytic=$this->db->make_array("select ga_id,ga_id from groupe_analytique where pa_id=".$this->pa_id,1);
//@bug
$aGroup_analytic=$this->db->make_array("select ga_id,ga_id from groupe_analytique where pa_id=$1",1,array($this->pa_id));
if ( count($aGroup_analytic) > 1 )
{
$wGa_id=new ISelect("ga_id");

View file

@ -0,0 +1,93 @@
<?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 Add , delete and update Poste_Analytic
*
*/
/**
* @class
* @brief derived from Manage_Table_SQL ,
*/
require_once NOALYSS_INCLUDE."/lib/manage_table_sql.class.php";
require_once NOALYSS_INCLUDE.'/database/poste_analytique_sql.class.php';
class Anc_Account_Table extends Manage_Table_SQL
{
function __construct(Data_SQL $p_table)
{
parent::__construct($p_table);
$cn=Dossier::connect();
$this->set_property_updatable("po_id", FALSE);
$this->set_property_updatable("pa_id", FALSE);
$this->set_property_visible("pa_id", FALSE);
$this->set_property_visible("po_id", FALSE);
$this->set_property_visible("po_amount", FALSE);
$this->set_col_label("po_name", _("Label"));
$this->set_col_label("po_description", _("Description"));
$this->set_col_label("ga_id", _("Groupe"));
$this->set_col_type("ga_id", "select");
$this->set_object_name("Oanc_accounting");
$this->set_col_sort(1);
$this->a_select["ga_id"]=$cn->make_array("select ga_id,ga_description
from groupe_analytique
where
pa_id=$1
order by 2",0,array($p_table->pa_id));
}
/**
* Check and change po_name values
* @return boolean
*/
function check()
{
$cn=Dossier::connect();
$table=$this->get_table();
$is_error=0;
$table->po_amount=0;
// po_name must contains only valid letter (remove < > and ')
$table->po_name=str_replace("'", '', $table->po_name);
$table->po_name=str_replace("<", '', $table->po_name);
$table->po_name=str_replace(">", '', $table->po_name);
// po_name must be uniq in the Analytic Plan
if ( $cn->get_value("select count(*) from poste_analytique where pa_id=$1 and po_name=$2",
array($table->pa_id,$table->po_name)) > 0 && $table->po_id==-1)
{
$is_error++;
$this->set_error("po_name", _("Le nom doit être unique dans un plan analytique"));
}
// po_name cannot be empty
if (trim($table->po_name)=="") {
$is_error++;
$this->set_error("po_name", _("Le nom ne peut être vide"));
}
$table->ga_id=($table->ga_id=="")?null:$table->ga_id;
if ($is_error==0)return TRUE;
return FALSE;
}
}

View file

@ -0,0 +1,70 @@
<?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>
/**
* class_poste_analytique_sql.php
*
* @file
* @brief abstract of the table public.poste_analytique
*
*
* @class
* @brief abstract of the table public.poste_analytique */
class Poste_analytique_SQL extends Noalyss_SQL
{
function __construct(Database $p_cn, $p_id=-1)
{
$this->table="public.poste_analytique";
$this->primary_key="po_id";
/*
* List of columns
*/
$this->name=array(
"po_id"=>"po_id"
, "po_name"=>"po_name"
, "pa_id"=>"pa_id"
, "po_amount"=>"po_amount"
, "po_description"=>"po_description"
, "ga_id"=>"ga_id"
);
/*
* Type of columns
*/
$this->type=array(
"po_id"=>"numeric"
, "po_name"=>"text"
, "pa_id"=>"numeric"
, "po_amount"=>"numeric"
, "po_description"=>"text"
, "ga_id"=>"text"
);
$this->default=array(
"po_id"=>"auto"
);
$this->date_format="DD.MM.YYYY";
parent::__construct($p_cn, $p_id);
}
}