From 868098e20f42f91ddb37d7cfa888b3000b33391a Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Wed, 13 Sep 2017 00:06:43 +0200 Subject: [PATCH] =?UTF-8?q?Task=20#0001462:=20CA=20-=20apostrophe=20non=20?= =?UTF-8?q?affich=C3=A9e=20Use=20of=20ManageTableSQL=20for=20improving=20a?= =?UTF-8?q?dding=20,=20update=20and=20delete=20analytic=20accounting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/ajax_misc.php | 4 +- include/anc_pa.inc.php | 158 +++++------------- include/class/anc_account.class.php | 3 +- include/class/anc_account_table.class.php | 93 +++++++++++ .../database/poste_analytique_sql.class.php | 70 ++++++++ 5 files changed, 206 insertions(+), 122 deletions(-) create mode 100644 include/class/anc_account_table.class.php create mode 100644 include/database/poste_analytique_sql.class.php diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 4172dc077..1f8bf7420 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -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)) { diff --git a/include/anc_pa.inc.php b/include/anc_pa.inc.php index 335a6867c..3cc09cd37 100644 --- a/include/anc_pa.inc.php +++ b/include/anc_pa.inc.php @@ -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.= '
'; - $ret.=HtmlInput::title_box(_('Nouveau plan'), '', 'none'); + $ret.= '
'; + $ret.=HtmlInput::title_box(_('Nouveau plan'), 'anc_div_add', 'hide'); $ret.= '
'; $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.= '
'; $ret.= '
'; } @@ -98,85 +101,21 @@ if ($sa=="pa_update") $ret.="
"; $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.='
'; - $ret.=h2(_("Ajout d'un poste analytique")); - $ret.='
'; - $ret.=dossier::hidden(); - $ret.=$po->form(); - $ret.=$wSa; - $ret.=HtmlInput::submit("add", _("Ajout")); - $ret.="
"; - $ret.="
"; -} -// 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.='
'; - $ret.='
'; - $ret.=dossier::hidden(); - $ret.=$po->form(); - $ret.=HtmlInput::hidden('sa', 'po_update'); - $ret.=HtmlInput::submit('Correction', 'Correction'); - $ret.=sprintf('id, $_REQUEST['pa_id'] - ); - - $ret.='
'; - $ret.='
'; - $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.= ''; - /** - * 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.='
'; - $ret.=''; - $ret.=""; - $ret.=""; - $ret.=""; - $class=""; - foreach ($array as $obj) - { - $count++; - if ($count%2==0) - $class="even"; - else - $class="odd"; - - $ret.=""; - $ret.="" - ; - $ret.=""; - $ret.=""; - $ret.=""; - $ret.=""; - $ret.=""; - } - $ret.="
"._("Nom")." "; - $ret.=""._("Montant")." "; - $ret.=""._("Description")." "; - $ret.=""._("Groupe").""._("Plan A")." "; - $ret.="
". - ''. - h($obj->name). - ''; - "".$obj->amount."".h($obj->description)."".$obj->ga_id."".h($new->name)."
"; - // ---> 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.= ''._('Retour').''; + $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.= '
'; } @@ -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 '
'; echo ''; echo ''; echo '
'; - echo ''._("Ajout d'un plan comptable").''; + echo ''._("Ajout d'un plan comptable").''; echo '
'; @@ -274,23 +188,27 @@ if ($sa=='anc_menu') } else { + $url=http_build_query(array("sa"=>"add_pa","ac"=>$ac, + "gDossier"=>Dossier::id())); echo '
'; echo ''; if ($obj->isAppend()==true) { echo ''; } foreach ($list as $line) { + $url=http_build_query(array("sa"=>"pa_detail","ac"=>$ac,"pa_id"=>$line['id'], + "gDossier"=>Dossier::id())); echo ''; echo '"; echo "\n"; } diff --git a/include/class/anc_account.class.php b/include/class/anc_account.class.php index 7327f490e..a070cfb69 100644 --- a/include/class/anc_account.class.php +++ b/include/class/anc_account.class.php @@ -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"); diff --git a/include/class/anc_account_table.class.php b/include/class/anc_account_table.class.php new file mode 100644 index 000000000..97f9e673c --- /dev/null +++ b/include/class/anc_account_table.class.php @@ -0,0 +1,93 @@ + + +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; + } +} \ No newline at end of file diff --git a/include/database/poste_analytique_sql.class.php b/include/database/poste_analytique_sql.class.php new file mode 100644 index 000000000..ba9ab3078 --- /dev/null +++ b/include/database/poste_analytique_sql.class.php @@ -0,0 +1,70 @@ + + +/** + * 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); + } + +}
'; - echo ''._("Ajout d'un plan comptable").''; + echo ''._("Ajout d'un plan comptable").''; echo '
'. - ''. + ''. h($line['name']); - echo $line['description'].""; + echo h($line['description']).""; echo "