diff --git a/html/ajax_misc.php b/html/ajax_misc.php index beea21874..704d58c19 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -195,7 +195,9 @@ $path = array( // Add , delete update anc accounting "anc_accounting"=>"ajax_anc_accounting", // Update name and description - "anc_updatedescription"=>"ajax_anc_plan" + "anc_updatedescription"=>"ajax_anc_plan", + // Update, insert or delete accounting frmo CFGPCMN + "accounting"=>"ajax_accounting" ) ; if (array_key_exists($op, $path)) { diff --git a/html/js/managetable.js b/html/js/managetable.js index 7a88bb61b..a7d8b9c78 100644 --- a/html/js/managetable.js +++ b/html/js/managetable.js @@ -267,7 +267,7 @@ var ManageTable = function (p_table_name) $(x).remove(); alternate_row_color("tb"+answer['ctl']); }else { - smoke.alert("Effacement impossible"); + smoke.alert(answer['html']); } } }); diff --git a/include/ajax/ajax_accounting.php b/include/ajax/ajax_accounting.php new file mode 100644 index 000000000..932a2f5cc --- /dev/null +++ b/include/ajax/ajax_accounting.php @@ -0,0 +1,69 @@ + + +if (!defined('ALLOWED')) die('Appel direct ne sont pas permis'); + +/** + * @file + * @brief + */ +$http=new HttpInput(); +try { + $table=$http->request('table'); + $action=$http->request('action'); + $p_id=$http->request('p_id', "numeric"); + $ctl_id=$http->request('ctl'); + +} catch(Exception $e) { + echo $e->getMessage(); + return; +} +if ( $g_user->check_module("CFGPCMN") == 0) die(); + +require_once NOALYSS_INCLUDE."/lib/manage_table_sql.class.php"; +require_once NOALYSS_INCLUDE."/class/acc_plan_mtable.class.php"; + +$obj=new Acc_Plan_SQL($cn); +$obj->set_limit_fiche_qcode(5); +$obj->set_pk_value($p_id); +$obj->load(); +$manage_table=new Acc_Plan_MTable($obj); +$manage_table->add_json_param("op","accounting"); +$manage_table->set_object_name($ctl_id); +$manage_table->set_callback("ajax_misc.php"); +if ($action=="input") +{ + header('Content-type: text/xml; charset=UTF-8'); + echo $manage_table->ajax_input()->saveXML(); + return; +} +elseif ($action == "save") +{ + $xml=$manage_table->ajax_save(); + header('Content-type: text/xml; charset=UTF-8'); + echo $xml->saveXML(); +} +elseif ($action == "delete") +{ + $xml=$manage_table->ajax_delete(); + header('Content-type: text/xml; charset=UTF-8'); + echo $xml->saveXML(); +} \ No newline at end of file diff --git a/include/class/acc_plan_mtable.class.php b/include/class/acc_plan_mtable.class.php index ef1af2723..23377fa71 100644 --- a/include/class/acc_plan_mtable.class.php +++ b/include/class/acc_plan_mtable.class.php @@ -55,6 +55,7 @@ class Acc_Plan_MTable extends Manage_Table_SQL ["label"=>_("Produit inversé"),"value"=>"PROINV"], ["label"=>_("Contexte"),"value"=>"CON"] ]); + $this->a_order=["pcm_val","pcm_lib","parent_accounting","pcm_type","fiche_qcode"]; } /** * Display a row @@ -112,9 +113,18 @@ class Acc_Plan_MTable extends Manage_Table_SQL if ( trim($this->table->parent_accounting) == "") { $this->set_error("parent_accounting", _("Poste comptable dépendant ne peut pas être vide")); } + /** + * Check that the parent accounting does exist + */ + $exist_parent=$cn->get_value("select count(*) from tmp_pcmn where pcm_val = $1 ", + array($this->table->parent_accounting)); + if ($exist_parent == 0) { + $this->set_error("parent_accounting", _("Compte parent n'existe pas")); + } if ( count($this->aerror) > 0 ) return false; return true; } + } diff --git a/include/database/acc_plan_sql.class.php b/include/database/acc_plan_sql.class.php index 40d93b04a..ddf8dc5b2 100644 --- a/include/database/acc_plan_sql.class.php +++ b/include/database/acc_plan_sql.class.php @@ -83,6 +83,14 @@ class Acc_Plan_SQL extends Data_SQL public function delete() { $obj=new Tmp_Pcmn_SQL($this->cn,$this->id); + if ( $this->cn->get_value("select count(*) from jrnx where j_poste=$1",[$obj->pcm_val]) > 0) + { + throw new Exception(_("Impossible d'effacer : ce poste est utilisé")); + } + if ( $this->cn->get_value("select count(*) from tmp_pcmn where pcm_val_parent=$1",[$obj->pcm_val]) > 0) + { + throw new Exception(_("Impossible d'effacer : ce poste est utilisé")); + } return $obj->delete(); } @@ -103,7 +111,10 @@ class Acc_Plan_SQL extends Data_SQL $obj->insert(); $this->id=$obj->id; } - + public function get_pk_value() + { + return $this->id; + } public function load() { $pk=$this->primary_key; diff --git a/include/lib/manage_table_sql.class.php b/include/lib/manage_table_sql.class.php index 4ba114216..15a787fe1 100644 --- a/include/lib/manage_table_sql.class.php +++ b/include/lib/manage_table_sql.class.php @@ -579,12 +579,15 @@ function check() } $nb_order=count($this->a_order); $virg=""; $result=""; + // filter only on visible column + $visible=0; for ($e=0; $e<$nb_order; $e++) { if ($this->get_property_visible($this->a_order[$e])==TRUE) { - $result.=$virg."$e"; + $result.=$virg."$visible"; $virg=","; + $visible++; } } echo _('Cherche')." ".HtmlInput::filter_table("tb".$this->object_name, $result, 1); @@ -1001,7 +1004,7 @@ function check() $s1=$xml->createElement("status", "NOK"); $s2=$xml->createElement("ctl", $this->object_name."_".$this->table->get_pk_value()); - $s3=$xml->createElement("html", $ex->getTraceAsString()); + $s3=$xml->createElement("html", $ex->getMessage()); $s4=$xml->createElement("ctl", $this->object_name); $root=$xml->createElement("data"); diff --git a/include/lib/noalyss_sql.class.php b/include/lib/noalyss_sql.class.php index 043d659ea..9f2e8ca81 100644 --- a/include/lib/noalyss_sql.class.php +++ b/include/lib/noalyss_sql.class.php @@ -201,7 +201,8 @@ abstract class Noalyss_SQL extends Data_SQL } $sql.=") values (".$par.") returning ".$this->primary_key; $pk=$this->primary_key; - $this->$pk=$this->cn->get_value($sql, $array); + $returning=$this->cn->get_value($sql, $array); + $this->$pk=$returning; } public function delete() diff --git a/include/param_pcmn.inc.php b/include/param_pcmn.inc.php index d967f5c82..1c233e948 100644 --- a/include/param_pcmn.inc.php +++ b/include/param_pcmn.inc.php @@ -41,7 +41,7 @@ echo '