diff --git a/html/js/infobulle.js b/html/js/infobulle.js index b9677c654..91114aa3d 100644 --- a/html/js/infobulle.js +++ b/html/js/infobulle.js @@ -42,6 +42,7 @@ content[11]="ATTENTION si le poste comptable est vide, il sera créé automatiq content[12]="Document généré uniquement si le mode de paiement est utilisé"; content[13]="Vous pouvez utiliser le % pour indiquer le poste parent"; content[14]="Attention, le poste comptable doit exister, il ne sera pas vérifié"; +content[15]="Laissez à 0 pour ne rien changer"; function showBulle(p_ctl) { diff --git a/include/cat_document.inc.php b/include/cat_document.inc.php index 08a39be48..8f5c62e74 100644 --- a/include/cat_document.inc.php +++ b/include/cat_document.inc.php @@ -33,6 +33,20 @@ if ( isset($_POST['add']) ) $catDoc=new Document_Type($cn); $catDoc->insert($_POST['cat'],$_POST['prefix']); } +if ( isset($_POST['save'])) { + $catDoc=new Document_Type($cn,$_POST['dt_id']); + $catDoc->get(); + $catDoc->dt_value=trim($_POST['dt_name']); + $catDoc->dt_prefix=trim($_POST['dt_prefix']); + if ( $catDoc->dt_value=="") { + alert(_("Le nom ne peut pas être vide")); + } else { + $catDoc->update(); + } + if ($_POST['seq'] != 0 && isNumber($_POST['seq'])==1){ + $catDoc->set_number($_POST['seq']); + } +} $aList=Document_Type::get_list($cn); $addCat=new IText('cat'); $addPrefix=new IText('prefix'); diff --git a/include/class_document_type.php b/include/class_document_type.php index a4055456a..8d0289a7f 100644 --- a/include/class_document_type.php +++ b/include/class_document_type.php @@ -1,4 +1,5 @@ db=$p_cn; - $this->dt_id=-1; - } - /*! - * \brief Get all the data for this dt_id - */ - function get() - { - $sql="select * from document_type where dt_id=$1"; - $R=$this->db->exec_sql($sql,array($this->dt_id)); - $r=Database::fetch_array($R,0); - $this->dt_id=$r['dt_id']; - $this->dt_value=$r['dt_value']; - } - /** - *@brief get a list - *@parameter $p_cn database connection - *@return array of data from document_type - */ - static function get_list($p_cn) - { - $sql="select * from document_type order by dt_value"; - $r=$p_cn->get_array($sql); - $array=array(); - for ($i=0;$ilabel=_('Modifier'); - $bt->javascript="cat_doc_change('".$r[$i]['dt_id']."','".Dossier::id()."');"; + function document_type($p_cn, $p_id = -1) + { + $this->db = $p_cn; + $this->dt_id = $p_id; + } - $tmp['js_mod']=$bt->input(); - $tmp['dt_id']=$r[$i]['dt_id']; + /* ! + * \brief Get all the data for this dt_id + */ - $bt=new IButton('X'.$r[$i]['dt_id']); - $bt->label=_('Effacer'); - $bt->javascript="if (confirm('"._('Vous confirmez')."')==true) {"; - $bt->javascript.="cat_doc_remove('".$r[$i]['dt_id']."','".Dossier::id()."');"; - $bt->javascript.='}'; - - $tmp['js_remove']=$bt->input(); + function get() + { + $sql = "select * from document_type where dt_id=$1"; + $R = $this->db->exec_sql($sql, array($this->dt_id)); + if (count($R) == 0) return 1; + $r = Database::fetch_array($R, 0); + $this->dt_id = $r['dt_id']; + $this->dt_value = $r['dt_value']; + $this->dt_prefix = $r['dt_prefix']; + return 0; + } + + /** + * @brief get a list + * @parameter $p_cn database connection + * @return array of data from document_type + */ + static function get_list($p_cn) + { + $sql = "select * from document_type order by dt_value"; + $r = $p_cn->get_array($sql); + $array = array(); + for ($i = 0; $i < count($r); $i++) + { + $tmp['dt_value'] = $r[$i]['dt_value']; + $tmp['dt_prefix'] = $r[$i]['dt_prefix']; + + $bt = new IButton('X' . $r[$i]['dt_id']); + $bt->label = _('Modifier'); + $bt->javascript = "cat_doc_change('" . $r[$i]['dt_id'] . "','" . Dossier::id() . "');"; + + $tmp['js_mod'] = $bt->input(); + $tmp['dt_id'] = $r[$i]['dt_id']; + + $bt = new IButton('X' . $r[$i]['dt_id']); + $bt->label = _('Effacer'); + $bt->javascript = "if (confirm('" . _('Vous confirmez') . "')==true) {"; + $bt->javascript.="cat_doc_remove('" . $r[$i]['dt_id'] . "','" . Dossier::id() . "');"; + $bt->javascript.='}'; + + $tmp['js_remove'] = $bt->input(); - $array[$i]=$tmp; - } - return $array; - } - function insert($p_value,$p_prefix) - { - $sql="insert into document_type(dt_value,dt_prefix) values ($1,$2)"; - try - { - if( $this->db->count_sql('select * from document_type where upper(dt_value)=upper(trim($1))',array($p_value))>0) - throw new Exception('Nom en double'); - if ( strlen(trim($p_value))>0) - $this->db->exec_sql($sql,array($p_value,$p_prefix)); - } - catch (Exception $e) - { - alert(j(_("Impossible d'ajouter [$p_value] ").$e->getMessage())); - } - } + $array[$i] = $tmp; + } + return $array; + } + + function insert($p_value, $p_prefix) + { + $sql = "insert into document_type(dt_value,dt_prefix) values ($1,$2)"; + try + { + if ($this->db->count_sql('select * from document_type where upper(dt_value)=upper(trim($1))', array($p_value)) > 0) + throw new Exception('Nom en double'); + if (strlen(trim($p_value)) > 0) + $this->db->exec_sql($sql, array($p_value, $p_prefix)); + } + catch (Exception $e) + { + alert(j(_("Impossible d'ajouter [$p_value] ") . $e->getMessage())); + } + } + + /** + * Update + */ + function update() + { + try + { + $this->db->exec_sql("update document_type set dt_value=$1,dt_prefix=$2 where dt_id=$3", array($this->dt_value, + $this->dt_prefix, $this->dt_id)); + } + catch (Exception $e) + { + alert(" Erreur " . $e->getMessage()); + } + } + + function set_number($p_int) + { + try + { + $this->db->exec_sql("alter sequence seq_doc_type_" . $this->dt_id . " restart " . $p_int); + } + catch (Exception $e) + { + alert("Erreur " . $e->getMessage()); + } + } } diff --git a/include/template/document_mod_change.php b/include/template/document_mod_change.php index 9aaf60b01..2faa263f0 100644 --- a/include/template/document_mod_change.php +++ b/include/template/document_mod_change.php @@ -23,13 +23,21 @@ */ require_once 'class_document_type.php'; echo HtmlInput::title_box(_('Type de document'),'change_doc_div'); + +$doc_type=new Document_type($cn,$dt_id); +$doc_type->get(); ?> -
+ + @@ -37,13 +45,39 @@ echo HtmlInput::title_box(_('Type de document'),'change_doc_div'); - + + +
+ dt_value); + echo $name->input(); + ?>
+ dt_prefix); + echo $prefix->input(); + ?>
+ + get_array("select last_value,is_called from seq_doc_type_".$doc_type->dt_id) ; + + $last=$ret[0]['last_value']; + /*! + *\note With PSQL sequence , the last_value column is 1 when before AND after the first call, to make the difference between them + * I have to check whether the sequence has been already called or not */ + if ($ret[0]['is_called']=='f' ) $last--; + echo $last; + ?> +
+ + + input(); + ?>