From 8f0461092e601feeac01abce4a61fe4e9543c538 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sat, 5 Nov 2011 23:39:54 +0000 Subject: [PATCH] =?UTF-8?q?#419=20:=20r=C3=A9=C3=A9criture=20param=C3=A8tr?= =?UTF-8?q?age=20journaux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/class_acc_ledger.php | 305 ++++++++++++++++++++++++- include/class_jrn_def_sql.php | 380 +++++++++++++++++++++++++++++++ include/param_jrn.inc.php | 46 ---- include/param_jrn_add.inc.php | 198 ---------------- include/param_jrn_detail.inc.php | 256 --------------------- include/template/param_jrn.php | 5 +- include/user_menu.php | 264 --------------------- 7 files changed, 683 insertions(+), 771 deletions(-) create mode 100644 include/class_jrn_def_sql.php delete mode 100644 include/param_jrn.inc.php delete mode 100644 include/param_jrn_add.inc.php delete mode 100644 include/param_jrn_detail.inc.php diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index 37f19be21..c1bfab1c0 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -42,6 +42,7 @@ require_once('ac_common.php'); require_once('class_inum.php'); require_once('class_lettering.php'); require_once 'class_sort_table.php'; +require_once 'class_jrn_def_sql.php'; /*!\file * \brief Class for jrn, class acc_ledger for manipulating the ledger */ @@ -49,7 +50,7 @@ require_once 'class_sort_table.php'; /*!\brief Class for jrn, class acc_ledger for manipulating the ledger * */ -class Acc_Ledger +class Acc_Ledger extends jrn_def_sql { var $id; /*!< jrn_def.jrn_def_id */ var $name; /*!< jrn_def.jrn_def_name */ @@ -66,10 +67,13 @@ class Acc_Ledger function __construct ($p_cn,$p_id) { $this->id=$p_id; + $this->name=&$this->jrn_def_name; + $this->jrn_def_id=&$this->id; $this->db=$p_cn; $this->row=null; $this->nb=10; } + function get_last_pj() { if ( $this->db->exist_sequence("s_jrn_pj".$this->id) ) @@ -313,8 +317,8 @@ class Acc_Ledger } $Res=$this->db->exec_sql("select jrn_def_name from ". - " jrn_def where jrn_def_id=". - $this->id); + " jrn_def where jrn_def_id=$1", + array($this->id)); $Max=Database::num_row($Res); if ($Max==0) return null; $ret=Database::fetch_array($Res,0); @@ -565,7 +569,7 @@ class Acc_Ledger // Build the sql list($sql,$where)=$Ledger->build_search_sql($_GET); // Count nb of line - $max_line=$cn->count_sql($sql); + $max_line=$this->db->count_sql($sql); $step=$_SESSION['g_pagesize']; $page=(isset($_GET['offset']))?$_GET['page']:1; @@ -3038,6 +3042,297 @@ class Acc_Ledger $first_name=$this->db->get_value('select ad_value from fiche_detail where ad_id=32 and f_id=$1',array($tiers)); return $name.' '.$first_name; } + /** + * @brief listing of all ledgers + * @return HTML string + */ + function listing() + { + $str_dossier = dossier::get(); + $base_url="?".dossier::get()."&ac=".$_REQUEST['ac']; + + $r=""; + $r.=''; + $r.=''; + $ret = $this->db->exec_sql("select jrn_def_id,jrn_def_name, + jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc + from jrn_def join jrn_type on jrn_def_type=jrn_type_id order by jrn_def_name"); + $Max = Database::num_row($ret); -} + for ($i = 0; $i < $Max; $i++) + { + $l_line = Database::fetch_array($ret, $i); + $url=$base_url."&sa=detail&p_jrn=".$l_line['jrn_def_id']; + $r.=sprintf('', $url, h($l_line['jrn_def_name'])); + } + $r.= "
' . _('Création') . '
%s
"; + return $r; + } + /** + * display detail of a ledger + * + */ + function display_ledger() + { + if ( $this->load() == -1 ) { + throw new Exception(_("Journal n'existe pas"),-1); + } + $type=$this->jrn_def_type; + $name=$this->jrn_def_name; + $code=$this->jrn_def_code; + + /* widget for searching an account */ + $wSearch=new IPoste(); + $wSearch->set_attribute('ipopup','ipop_account'); + $wSearch->set_attribute('account','p_jrn_class_deb'); + $wSearch->set_attribute('no_overwrite','1'); + $wSearch->set_attribute('noquery','1'); + $wSearch->table=3; + $wSearch->name="p_jrn_class_deb"; + $wSearch->size=20; + $wSearch->value=$this->jrn_def_class_deb; + $search=$wSearch->input(); + + $wPjPref=new IText(); + $wPjPref->name='jrn_def_pj_pref'; + $wPjPref->value=$this->jrn_def_pj_pref; + $pj_pref=$wPjPref->input(); + + $wPjSeq=new INum(); + $wPjSeq->value=0; + $wPjSeq->name='jrn_def_pj_seq'; + $pj_seq=$wPjSeq->input(); + $last_seq=$this->get_last_pj(); + $name=$this->jrn_def_name; + + $hidden= HtmlInput::hidden('p_jrn',$this->id); + $hidden.= HtmlInput::hidden('sa','detail'); + $hidden.= dossier::hidden(); + $hidden.=HtmlInput::hidden('p_jrn_deb_max_line',10); + $hidden.=HtmlInput::hidden('p_ech_lib','echeance'); + $hidden.=HtmlInput::hidden('p_jrn_type',$type); + + /* Load the card */ + $card=$this->get_fiche_def(); + $rdeb=explode(',',$card['deb']); + $rcred=explode(',',$card['cred']); + /* Numbering (only FIN) */ + $num_op=new ICheckBox('numb_operation'); + if ( $this->jrn_def_num_op==1) $num_op->selected=true; + /* bank card */ + $qcode_bank=''; + if ( $type=='FIN') + { + $f_id=$this->jrn_def_bank; + if ( isNumber($f_id)==1) + { + $fBank=new Fiche($this->db,$f_id); + $qcode_bank=$fBank->get_quick_code(); + } + } + $new=false; + $cn=$this->db; + echo $hidden; + require_once('template/param_jrn.php'); + + } + /** + * Verify before update + * + * @param type $array + * 'p_jrn' => string '3' (length=1) + 'sa' => string 'detail' (length=6) + 'gDossier' => string '82' (length=2) + 'p_jrn_deb_max_line' => string '10' (length=2) + 'p_ech_lib' => string 'echeance' (length=8) + 'p_jrn_type' => string 'ACH' (length=3) + 'p_jrn_name' => string 'Achat' (length=5) + 'jrn_def_pj_pref' => string 'ACH' (length=3) + 'jrn_def_pj_seq' => string '0' (length=1) + 'FICHECRED' => + array + 0 => string '4' (length=1) + 'FICHEDEB' => + array + 0 => string '7' (length=1) + 1 => string '5' (length=1) + 2 => string '13' (length=2) + 'update' => string 'Sauve' (length=5 + *@exception is throw is test are not valid + */ + function verify_ledger($array) + { + extract ($array); + try + { + if (isNumber($p_jrn ) == 0) throw new Exception("Id invalide"); + if (isNumber($p_jrn_deb_max_line) == 0) throw new Exception ("Nombre de ligne incorrect"); + if (trim($p_jrn_name) == "") throw new Exception ("Nom de journal invalide"); + if ($this->db->get_value("select count(*) from jrn_def where jrn_def_name=$1 and jrn_Def_id<>$2", + array($p_jrn_name,$p_jrn)) > 0) throw new Exception ("Un journal avec ce nom existe déjà"); + if ($p_jrn_type=='FIN') + { + $a=new Fiche($this->db); + $result=$a->get_by_qcode(trim(strtoupper($_POST['bank'])),false); + if ( $result==1)throw new Exception ("Aucun compte en banque n'est donné"); + } + + } catch(Exception $e) + { + throw $e; + } + } + /** + * update a ledger + * @param type $array normally post + * @see verify_ledger + */ + function update($array) + { + extract ($array); + $this->jrn_def_id=$p_jrn; + $this->jrn_def_name=$p_jrn_name; + $this->jrn_def_ech_lib=$p_ech_lib; + $this->jrn_def_max_line_deb=$p_jrn_deb_max_line; + $this->jrn_def_type=$p_jrn_type; + $this->jrn_def_pj_pref=$jrn_def_pj_pref; + $this->jrn_def_fiche_deb=(isset($FICHEDEB))?join($FICHEDEB,','):""; + switch($this->jrn_def_type) + { + case 'ACH': + case 'VEN': + $this->jrn_def_fiche_cred=(isset($FICHECRED))?join($FICHECRED,','):''; + break; + case 'ODS': + $this->jrn_def_class_deb=$p_jrn_class_deb; + break; + case 'FIN': + $a=new Fiche($this->db); + $result=$a->get_by_qcode(trim(strtoupper($_POST['bank'])),false); + $bank=$a->id; + $this->jrn_def_bank=$bank; + if ( $result==-1)throw new Exception ("Aucun compte en banque n'est donné"); + $this->jrn_def_num_op=(isset($numb_operation))?1:0; + break; + } + + parent::update(); + //Reset sequence if needed + if ($jrn_def_pj_seq != 0) + { + $Res=$this->db->alter_seq("s_jrn_pj".$p_jrn,$jrn_def_pj_seq); + } + } + /** + * display screen to enter a new ledger + */ + function input_new() + { + $wSearch=new IPoste(); + $wSearch->table=3; + $wSearch->set_attribute('ipopup','ipop_account'); + $wSearch->set_attribute('account','p_jrn_class_deb'); + $wSearch->set_attribute('no_overwrite','1'); + $wSearch->set_attribute('noquery','1'); + + $wSearch->name="p_jrn_class_deb"; + $wSearch->size=20; + + $search=$wSearch->input(); + + /* construct all the hidden */ + $hidden= HtmlInput::hidden('p_jrn',-1); + $hidden.= HtmlInput::hidden('p_action','jrn'); + $hidden.= HtmlInput::hidden('sa','add'); + $hidden.= dossier::hidden(); + $hidden.=HtmlInput::hidden('p_jrn_deb_max_line',10); + $hidden.=HtmlInput::hidden('p_ech_lib','echeance'); + + /* properties of the ledger */ + $name=""; + $code=""; + $wType=new ISelect(); + $wType->value=$this->db->make_array('select jrn_type_id,jrn_desc from jrn_type'); + $wType->name="p_jrn_type"; + $type=$wType->input(); + $rcred=$rdeb=array(); + $wPjPref=new IText(); + $wPjPref->name='jrn_def_pj_pref'; + $pj_pref=$wPjPref->input(); + $pj_seq=''; + $last_seq=0; + $new=true; + /* bank card */ + $qcode_bank=''; + /* Numbering (only FIN) */ + $num_op=new ICheckBox('numb_operation'); + echo dossier::hidden(); + echo HtmlInput::hidden('ac',$_REQUEST['ac']); + echo HtmlInput::hidden('p_jrn',-1); + echo HtmlInput::hidden('sa','add'); + + $cn=$this->db; + + require_once('template/param_jrn.php'); + + } + /** + * Insert a new ledger + * @param type $array normally $_POST + * @see verify_ledger + */ + function save_new($array) + { + $this->load(); + extract ($array); + $this->jrn_def_id=-1; + $this->jrn_def_name=$p_jrn_name; + $this->jrn_def_ech_lib=$p_ech_lib; + $this->jrn_def_max_line_deb=$p_jrn_deb_max_line; + $this->jrn_def_type=$p_jrn_type; + $this->jrn_def_pj_pref=$jrn_def_pj_pref; + $this->jrn_def_fiche_deb=(isset($FICHEDEB))?join($FICHEDEB,','):""; + $this->jrn_def_code=sprintf("%s%02d",trim(substr($this->jrn_def_type,0,1)),Acc_Ledger::next_number($this->db,$this->jrn_def_type)); + + switch($this->jrn_def_type) + { + case 'ACH': + case 'VEN': + $this->jrn_def_fiche_cred=(isset($FICHECRED))?join($FICHECRED,','):''; + + break; + case 'ODS': + $this->jrn_def_class_deb=$p_jrn_class_deb; + break; + case 'FIN': + $a=new Fiche($this->db); + $result=$a->get_by_qcode(trim(strtoupper($_POST['bank'])),false); + $bank=$a->id; + $this->jrn_def_bank=$bank; + if ( $result==-1)throw new Exception ("Aucun compte en banque n'est donné"); + $this->jrn_def_num_op=(isset($numb_operation))?1:0; + break; + } + + parent::insert(); + } + /** + * delete a ledger IF is not already used + * @exeption : cannot delete + */ + function delete_ledger() + { + try + { + if ( $this->db->get_value("select count(jr_id) from jrn where jr_def_id=$1",array($this->jrn_def_id))>0) + throw new Exception("Impossible d'effacer un journal qui contient des opérations"); + parent::delete(); + } + catch(Exception $e) + { + throw $e; + } + } + + } diff --git a/include/class_jrn_def_sql.php b/include/class_jrn_def_sql.php new file mode 100644 index 000000000..ae9866b1b --- /dev/null +++ b/include/class_jrn_def_sql.php @@ -0,0 +1,380 @@ +column_name,"email"=>"column_name_email","val3"=>0); */ + + protected $variable = array( + "jrn_def_id" => "jrn_def_id", + "jrn_def_name" => "jrn_def_name" + , "jrn_def_class_deb" => "jrn_def_class_deb" + , "jrn_def_class_cred" => "jrn_def_class_cred" + , "jrn_def_fiche_deb" => "jrn_def_fiche_deb" + , "jrn_def_fiche_cred" => "jrn_def_fiche_cred" + , "jrn_deb_max_line" => "jrn_deb_max_line" + , "jrn_cred_max_line" => "jrn_cred_max_line" + , "jrn_def_ech" => "jrn_def_ech" + , "jrn_def_ech_lib" => "jrn_def_ech_lib" + , "jrn_def_type" => "jrn_def_type" + , "jrn_def_code" => "jrn_def_code" + , "jrn_def_pj_pref" => "jrn_def_pj_pref" + , "jrn_def_bank" => "jrn_def_bank" + , "jrn_def_num_op" => "jrn_def_num_op" + ); + + function __construct(& $p_cn, $p_id=-1) + { + $this->db = $p_cn; + $this->jrn_def_id = $p_id; + + if ($p_id == -1) + { + /* Initialize an empty object */ + foreach ($this->variable as $key => $value) + $this->$value = null; + $this->jrn_def_id = $p_id; + } + else + { + /* load it */ + + $this->load(); + } + } + + public function get_parameter($p_string) + { + if (array_key_exists($p_string, $this->variable)) + { + $idx = $this->variable[$p_string]; + return $this->$idx; + } + else + throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant'); + } + + public function set_parameter($p_string, $p_value) + { + if (array_key_exists($p_string, $this->variable)) + { + $idx = $this->variable[$p_string]; + $this->$idx = $p_value; + } + else + throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant'); + } + + public function get_info() + { + return var_export($this, true); + } + + public function verify_sql() + { + // Verify that the elt we want to add is correct + /* verify only the datatype */ + if (trim($this->jrn_def_name) == '') + $this->jrn_def_name = null; + if (trim($this->jrn_def_class_deb) == '') + $this->jrn_def_class_deb = null; + if (trim($this->jrn_def_class_cred) == '') + $this->jrn_def_class_cred = null; + if (trim($this->jrn_def_fiche_deb) == '') + $this->jrn_def_fiche_deb = null; + if (trim($this->jrn_def_fiche_cred) == '') + $this->jrn_def_fiche_cred = null; + if (trim($this->jrn_deb_max_line) == '') + $this->jrn_deb_max_line = null; + if ($this->jrn_deb_max_line !== null && settype($this->jrn_deb_max_line, 'float') == false) + throw new Exception('DATATYPE jrn_deb_max_line $this->jrn_deb_max_line non numerique'); + if (trim($this->jrn_cred_max_line) == '') + $this->jrn_cred_max_line = null; + if ($this->jrn_cred_max_line !== null && settype($this->jrn_cred_max_line, 'float') == false) + throw new Exception('DATATYPE jrn_cred_max_line $this->jrn_cred_max_line non numerique'); + if (trim($this->jrn_def_ech) == '') + $this->jrn_def_ech = null; + if (trim($this->jrn_def_ech_lib) == '') + $this->jrn_def_ech_lib = null; + if (trim($this->jrn_def_type) == '') + $this->jrn_def_type = null; + if (trim($this->jrn_def_code) == '') + $this->jrn_def_code = null; + if (trim($this->jrn_def_pj_pref) == '') + $this->jrn_def_pj_pref = null; + if (trim($this->jrn_def_bank) == '') + $this->jrn_def_bank = null; + if ($this->jrn_def_bank !== null && settype($this->jrn_def_bank, 'float') == false) + throw new Exception('DATATYPE jrn_def_bank $this->jrn_def_bank non numerique'); + if (trim($this->jrn_def_num_op) == '') + $this->jrn_def_num_op = null; + if ($this->jrn_def_num_op !== null && settype($this->jrn_def_num_op, 'float') == false) + throw new Exception('DATATYPE jrn_def_num_op $this->jrn_def_num_op non numerique'); + } + + public function save() + { + /* please adapt */ + if ($this->jrn_def_id == -1) + $this->insert(); + else + $this->update(); + } + + /** + * @brief retrieve array of object thanks a condition + * @param $cond condition (where clause) (optional by default all the rows are fetched) + * you can use this parameter for the order or subselect + * @param $p_array array for the SQL stmt + * @see Database::exec_sql get_object Database::num_row + * @return the return value of exec_sql + */ + public function seek($cond='', $p_array=null) + { + $sql = "select * from public.jrn_def $cond"; + $aobj = array(); + $ret = $this->db->exec_sql($sql, $p_array); + return $ret; + } + + /** + * get_seek return the next object, the return of the query must have all the column + * of the object + * @param $p_ret is the return value of an exec_sql + * @param $idx is the index + * @see seek + * @return object + */ + public function get_object($p_ret, $idx) + { + // map each row in a object + $oobj = new Jrn_Def_sql($this->db); + $array = Database::fetch_array($p_ret, $idx); + foreach ($array as $idx => $value) + { + $oobj->$idx = $value; + } + return $oobj; + } + + public function insert() + { + if ($this->verify_sql() != 0) + return; + if ($this->jrn_def_id == -1) + { + /* please adapt */ + $sql = "insert into public.jrn_def(jrn_def_name +,jrn_def_class_deb +,jrn_def_class_cred +,jrn_def_fiche_deb +,jrn_def_fiche_cred +,jrn_deb_max_line +,jrn_cred_max_line +,jrn_def_ech +,jrn_def_ech_lib +,jrn_def_type +,jrn_def_code +,jrn_def_pj_pref +,jrn_def_bank +,jrn_def_num_op +) values ($1 +,$2 +,$3 +,$4 +,$5 +,$6 +,$7 +,$8 +,$9 +,$10 +,$11 +,$12 +,$13 +,$14 +) returning jrn_def_id"; + + $this->jrn_def_id = $this->db->get_value( + $sql, array($this->jrn_def_name + , $this->jrn_def_class_deb + , $this->jrn_def_class_cred + , $this->jrn_def_fiche_deb + , $this->jrn_def_fiche_cred + , $this->jrn_deb_max_line + , $this->jrn_cred_max_line + , $this->jrn_def_ech + , $this->jrn_def_ech_lib + , $this->jrn_def_type + , $this->jrn_def_code + , $this->jrn_def_pj_pref + , $this->jrn_def_bank + , $this->jrn_def_num_op + ) + ); + } + else + { + $sql = "insert into public.jrn_def(jrn_def_name +,jrn_def_class_deb +,jrn_def_class_cred +,jrn_def_fiche_deb +,jrn_def_fiche_cred +,jrn_deb_max_line +,jrn_cred_max_line +,jrn_def_ech +,jrn_def_ech_lib +,jrn_def_type +,jrn_def_code +,jrn_def_pj_pref +,jrn_def_bank +,jrn_def_num_op +,jrn_def_id) values ($1 +,$2 +,$3 +,$4 +,$5 +,$6 +,$7 +,$8 +,$9 +,$10 +,$11 +,$12 +,$13 +,$14 +,$15 +) returning jrn_def_id"; + + $this->jrn_def_id = $this->db->get_value( + $sql, array($this->jrn_def_name + , $this->jrn_def_class_deb + , $this->jrn_def_class_cred + , $this->jrn_def_fiche_deb + , $this->jrn_def_fiche_cred + , $this->jrn_deb_max_line + , $this->jrn_cred_max_line + , $this->jrn_def_ech + , $this->jrn_def_ech_lib + , $this->jrn_def_type + , $this->jrn_def_code + , $this->jrn_def_pj_pref + , $this->jrn_def_bank + , $this->jrn_def_num_op + , $this->jrn_def_id) + ); + } + } + + public function update() + { + if ($this->verify_sql() != 0) + return; + /* please adapt */ + $sql = " update public.jrn_def set jrn_def_name = $1 +,jrn_def_class_deb = $2 +,jrn_def_class_cred = $3 +,jrn_def_fiche_deb = $4 +,jrn_def_fiche_cred = $5 +,jrn_deb_max_line = $6 +,jrn_cred_max_line = $7 +,jrn_def_ech = $8 +,jrn_def_ech_lib = $9 +,jrn_def_type = $10 +,jrn_def_code = $11 +,jrn_def_pj_pref = $12 +,jrn_def_bank = $13 +,jrn_def_num_op = $14 + where jrn_def_id= $15"; + $res = $this->db->exec_sql( + $sql, array($this->jrn_def_name + , $this->jrn_def_class_deb + , $this->jrn_def_class_cred + , $this->jrn_def_fiche_deb + , $this->jrn_def_fiche_cred + , $this->jrn_deb_max_line + , $this->jrn_cred_max_line + , $this->jrn_def_ech + , $this->jrn_def_ech_lib + , $this->jrn_def_type + , $this->jrn_def_code + , $this->jrn_def_pj_pref + , $this->jrn_def_bank + , $this->jrn_def_num_op + , $this->jrn_def_id) + ); + } + + /** + * @brief load a object + * @return 0 on success -1 the object is not found + */ + public function load() + { + + $sql = "select jrn_def_name +,jrn_def_class_deb +,jrn_def_class_cred +,jrn_def_fiche_deb +,jrn_def_fiche_cred +,jrn_deb_max_line +,jrn_cred_max_line +,jrn_def_ech +,jrn_def_ech_lib +,jrn_def_type +,jrn_def_code +,jrn_def_pj_pref +,jrn_def_bank +,jrn_def_num_op + from public.jrn_def where jrn_def_id=$1"; + /* please adapt */ + $res = $this->db->get_array( + $sql, array($this->jrn_def_id) + ); + + if (count($res) == 0) + { + /* Initialize an empty object */ + foreach ($this->variable as $key => $value) + $this->$key = ''; + + return -1; + } + foreach ($res[0] as $idx => $value) + { + $this->$idx = $value; + } + return 0; + } + + public function delete() + { + $sql = "delete from public.jrn_def where jrn_def_id=$1"; + $res = $this->db->exec_sql($sql, array($this->jrn_def_id)); + } + + /** + * Unit test for the class + */ + static function test_me() + { + } + +} + +// Jrn_Def_sql::test_me(); +?> diff --git a/include/param_jrn.inc.php b/include/param_jrn.inc.php deleted file mode 100644 index c0b026889..000000000 --- a/include/param_jrn.inc.php +++ /dev/null @@ -1,46 +0,0 @@ -Check(); -$User->check_dossier($gDossier); - -include_once ("user_menu.php"); - - -$User->can_request(PARJRN); - - -echo ''; -html_page_stop(); -?> diff --git a/include/param_jrn_add.inc.php b/include/param_jrn_add.inc.php deleted file mode 100644 index 6489c75bb..000000000 --- a/include/param_jrn_add.inc.php +++ /dev/null @@ -1,198 +0,0 @@ -title=_('Recherche de fiche'); -echo $search_card->input(); - -html_page_start($_SESSION['g_theme']); -require_once('class_dossier.php'); -$gDossier=dossier::id(); - -require_once('class_database.php'); -/* Admin. Dossier */ - -include_once ("class_user.php"); -$cn=new Database($gDossier); -$User=new User($cn); -$User->Check(); -$User->check_dossier($gDossier); -include_once ("user_menu.php"); - -$User->can_request(PARJRN); - -if ( isset ($_POST["add"]) ) -{ - if ( !isset($_POST["p_jrn_name"]) || ! isset($_POST["p_jrn_type"] )) - { - echo '

'._('Un paramètre manque').'

'; - } - else - { - /* if name already use we stop */ - if ( $cn->count_sql("select * from jrn_def where upper(jrn_def_name)=upper($1)",array($_POST['p_jrn_name'])) >0 ) - { - - alert (_('Un journal de ce nom existe déjà')); - } - else - { - - if (strlen(trim($_POST['p_jrn_deb_max_line'])) == 0 || - (string) (int)$_POST['p_jrn_deb_max_line'] != (string)$_POST['p_jrn_deb_max_line'] ) - $l_deb_max_line=1; - else - $l_deb_max_line=$_POST['p_jrn_deb_max_line']; - - - $p_jrn_name=$_POST["p_jrn_name"]; - $p_jrn_class_deb=sql_string($_POST["p_jrn_class_deb"]); - if (strlen(trim($p_jrn_name))==0) return; - // compute the jrn_def.jrn_def_code - $p_code=sprintf("%s%02d",trim(substr($_POST['p_jrn_type'],0,1)),Acc_Ledger::next_number($cn,$_POST['p_jrn_type'])); - $p_jrn_fiche_deb=""; - $p_jrn_fiche_cred=""; - - if ( isset ($_POST["FICHEDEB"])) - { - $p_jrn_fiche_deb=join(",",$_POST["FICHEDEB"]); - } - if ( isset ($_POST["FICHECRED"])) - { - $p_jrn_fiche_cred=join(",",$_POST["FICHECRED"]); - } - $l_cred_max_line=$l_deb_max_line; - $cn->start(); - $bank=null; - if (isset($_POST['bank'])) - { - $a=new Fiche($cn); - $a->get_by_qcode(trim(strtoupper($_POST['bank'])),false); - $bank=$a->id; - if ($bank==0) $bank=null; - } - $nop=0; - if (isset($_POST['numb_operation'])) - { - $nop=1; - } - - if ($_POST['p_jrn_type']=='FIN' && $bank==null) - { - alert("Vous devez donner un compte en banque"); - } - else - { - - $Sql="insert into jrn_def(jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_deb_max_line,jrn_cred_max_line, - jrn_def_type,jrn_def_fiche_deb,jrn_def_fiche_cred,jrn_def_code,jrn_def_pj_pref,jrn_def_bank,jrn_def_num_op) - values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)"; - $sql_array=array( - $p_jrn_name,$p_jrn_class_deb,$p_jrn_class_deb, - $l_deb_max_line,$l_cred_max_line,$_POST['p_jrn_type'], - $p_jrn_fiche_deb,$p_jrn_fiche_cred, - $p_code,$_POST['jrn_def_pj_pref'], - $bank,$nop); - $Res=$cn->exec_sql($Sql,$sql_array); - $ledger_id=$cn->get_current_seq('s_jrn_def'); - $Res=$cn->create_sequence('s_jrn_pj'.$ledger_id); - $cn->commit(); - } - } - } - echo ''; - exit(); -} - -echo ''; - - - -echo '
'; -/* widget for searching an account */ -$wSearch=new IPoste(); -$wSearch->table=3; -$wSearch->set_attribute('ipopup','ipop_account'); -$wSearch->set_attribute('account','p_jrn_class_deb'); -$wSearch->set_attribute('no_overwrite','1'); -$wSearch->set_attribute('noquery','1'); - -$wSearch->name="p_jrn_class_deb"; -$wSearch->size=20; - -$search=$wSearch->input(); - -/* construct all the hidden */ -$hidden= HtmlInput::hidden('p_jrn',0); -$hidden.= HtmlInput::hidden('p_action','jrn'); -$hidden.= HtmlInput::hidden('sa','add'); -$hidden.= dossier::hidden(); -$hidden.=HtmlInput::hidden('p_jrn_deb_max_line',10); -$hidden.=HtmlInput::hidden('p_ech_lib','echeance'); - -/* properties of the ledger */ -$name=""; -$code=""; -$wType=new ISelect(); -$wType->value=$cn->make_array('select jrn_type_id,jrn_desc from jrn_type'); -$wType->name="p_jrn_type"; -$type=$wType->input(); -$rcred=$rdeb=array(); -$wPjPref=new IText(); -$wPjPref->name='jrn_def_pj_pref'; -$pj_pref=$wPjPref->input(); -$pj_seq=''; -$last_seq=0; -$new=true; -/* bank card */ -$qcode_bank=''; -/* Numbering (only FIN) */ -$num_op=new ICheckBox('numb_operation'); - - -echo '
'; -echo dossier::hidden(); -echo HtmlInput::hidden('p_action','jrn'); -echo HtmlInput::hidden('p_jrn',-1); -echo HtmlInput::hidden('sa','add'); -require_once('template/param_jrn.php'); -echo HtmlInput::submit('add','Sauver'); -echo ''; -echo '
'; -echo "
"; -html_page_stop(); -?> diff --git a/include/param_jrn_detail.inc.php b/include/param_jrn_detail.inc.php deleted file mode 100644 index b8073c1e0..000000000 --- a/include/param_jrn_detail.inc.php +++ /dev/null @@ -1,256 +0,0 @@ -title=_('Recherche de fiche'); -echo $search_card->input(); -$gDossier=dossier::id(); - -include_once ("ac_common.php"); -html_page_start($_SESSION['g_theme']); -require_once('class_database.php'); -/* Admin. Dossier */ -$cn=new Database($gDossier); -include_once ("class_user.php"); -$User=new User($cn); -$User->Check(); -$User->check_dossier($gDossier); - - -$User->can_request(PARJRN); - -if ( isset( $_REQUEST['p_jrn'] )) -{ - $p_jrn=$_REQUEST['p_jrn']; -} -else -{ - echo '

'._('Journal inexistant').'

'; - exit(); -} -//-------------------------------------------------- -// remove ledger -//-------------------------------------------------- -if ( isset($_POST["efface"])) -{ - if ( isNumber($_POST['p_jrn'])==0) - { - alert(_("Impossible d\'effacer ce journal.\n Il est utilisé\n")); - } - else if ( $cn->get_value("select count(*) from jrn where jr_def_id=$1",array($_POST['p_jrn'])) == 0 ) - { - $cn->exec_sql("delete from jrn_def where jrn_def_id=$1",array($_POST['p_jrn'])); - } - else - { - alert(_("Impossible d\'effacer ce journal.\n Il est utilisé\n")); - } -} - - -//-------------------------------------------------- -// Update ledger -If ( isset ($_POST["update"] )) -{ - if ( !isset($_POST["p_jrn_name"]) ) - { - echo '

'._('Un paramètre manque').'

'; - } - else - { - if ( isset ($_POST['p_ech']) && $_POST['p_ech'] == 'no' ) - { - $p_ech='false'; - $p_ech_lib='null'; - } - else - { - $p_ech='true'; - $p_ech_lib="'".$_POST['p_ech_lib']."'"; - } - $nop=0; - if (isset($_POST['numb_operation'])) - { - $nop=1; - } - if ( strlen(trim($_POST['p_jrn_deb_max_line'])) == 0 || - (string) (int)$_POST['p_jrn_deb_max_line'] != (string)$_POST['p_jrn_deb_max_line'] || - $_POST['p_jrn_deb_max_line'] <= 0 - ) - $l_deb_max_line=1; - else - $l_deb_max_line=$_POST['p_jrn_deb_max_line']; - - $l_cred_max_line=$l_deb_max_line; - - $p_jrn_name=$_POST['p_jrn_name']; - if (strlen(trim($p_jrn_name))==0) return; - $p_jrn_name=sql_string($p_jrn_name); - $p_jrn_fiche_deb=""; - $p_jrn_fiche_cred=""; - $bank=null; - if (isset($_POST['bank'])) - { - $a=new Fiche($cn); - $a->get_by_qcode(trim(strtoupper($_POST['bank'])),false); - $bank=$a->id; - if ($bank==0) $bank=null; - } - $err=0; - if ($_POST['p_jrn_type']=='FIN' && $bank==null) - { - alert("Vous devez donner un compte en banque"); - $err=1; - } - if ( isset ($_POST["FICHEDEB"])) - { - $p_jrn_fiche_deb=join(",",$_POST["FICHEDEB"]); - } - if ( isset ($_POST["FICHECRED"])) - { - $p_jrn_fiche_cred=join(",",$_POST["FICHECRED"]); - } - if ($err==0) - { - $p_jrn_class_deb=(isset($_POST['p_jrn_class_deb']))?$_POST['p_jrn_class_deb']:''; - $Sql="update jrn_def set jrn_def_name=$1,jrn_def_class_deb=$2,jrn_def_class_cred=$3, - jrn_deb_max_line=$4,jrn_cred_max_line=$5,jrn_def_ech=$6,jrn_def_ech_lib=$7,jrn_def_fiche_deb=$8, - jrn_def_fiche_cred=$9, jrn_def_pj_pref=upper($10), jrn_def_bank=$12,jrn_def_num_op=$13 - where jrn_def_id=$11"; - $sql_array=array( - $p_jrn_name,$p_jrn_class_deb,$p_jrn_class_deb, - $l_deb_max_line,$l_cred_max_line, - $p_ech,$p_ech_lib, - $p_jrn_fiche_deb,$p_jrn_fiche_cred, - $_POST['jrn_def_pj_pref'], - $_GET['p_jrn'], - $bank, - $nop - ); - $Res=$cn->exec_sql($Sql,$sql_array); - if ( isNumber($_POST['jrn_def_pj_seq']) == 1 && $_POST['jrn_def_pj_seq']!=0) - $Res=$cn->alter_seq("s_jrn_pj".$_GET['p_jrn'],$_POST['jrn_def_pj_seq']); - } - } -} -echo ''; -?> - - - exec_sql("select jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,". - "jrn_deb_max_line,jrn_cred_max_line,jrn_def_code". - ",jrn_def_type,jrn_def_ech, jrn_def_ech_lib,jrn_def_fiche_deb,jrn_def_fiche_cred". - ",jrn_def_bank,jrn_def_num_op". - " from jrn_def where". - " jrn_def_id=".$_REQUEST['p_jrn']); -if ( Database::num_row($Res) == 0 ) exit(); - - -$l_line=Database::fetch_array($Res,0); - -/* Load all the properties of the ledger */ -$Ledger=new Acc_Ledger($cn,$_REQUEST['p_jrn']); -$prop=$Ledger->get_propertie(); -$type=$prop['jrn_def_type']; -$name=$prop['jrn_def_name']; -$code=$prop['jrn_def_code']; -/* widget for searching an account */ -$wSearch=new IPoste(); -$wSearch->set_attribute('ipopup','ipop_account'); -$wSearch->set_attribute('account','p_jrn_class_deb'); -$wSearch->set_attribute('no_overwrite','1'); -$wSearch->set_attribute('noquery','1'); -$wSearch->table=3; -$wSearch->name="p_jrn_class_deb"; -$wSearch->size=20; -$wSearch->value=$prop['jrn_def_class_deb']; -$search=$wSearch->input(); -$new=false; - -$wPjPref=new IText(); -$wPjPref->name='jrn_def_pj_pref'; -$wPjPref->value=$prop['jrn_def_pj_pref']; -$pj_pref=$wPjPref->input(); -$wPjSeq=new INum(); -$wPjSeq->value=0; -$wPjSeq->name='jrn_def_pj_seq'; -$pj_seq=$wPjSeq->input(); -$last_seq=$Ledger->get_last_pj(); -$name=$l_line['jrn_def_name']; - -/* construct all the hidden */ -$hidden= HtmlInput::hidden('p_jrn',$_GET['p_jrn']); -$hidden.= HtmlInput::hidden('p_action','jrn'); -$hidden.= HtmlInput::hidden('sa','detail'); -$hidden.= dossier::hidden(); -$hidden.=HtmlInput::hidden('p_jrn_deb_max_line',10); -$hidden.=HtmlInput::hidden('p_ech_lib','echeance'); -$hidden.=HtmlInput::hidden('p_jrn_type',$type); - -/* Load the card */ -$card=$Ledger->get_fiche_def(); -$rdeb=explode(',',$card['deb']); -$rcred=explode(',',$card['cred']); -/* Numbering (only FIN) */ -$num_op=new ICheckBox('numb_operation'); -if ( $l_line['jrn_def_num_op']==1) $num_op->selected=true; -/* bank card */ -$qcode_bank=''; -if ( $type=='FIN') -{ - $f_id=$l_line['jrn_def_bank']; - if ( isNumber($f_id)==1) - { - $fBank=new Fiche($cn,$f_id); - $qcode_bank=$fBank->get_quick_code(); - } -} -echo '
'; -echo '
'; -echo $hidden; -require_once('template/param_jrn.php'); -echo ' - -'; - -echo '
'; -echo "
"; -html_page_stop(); -?> diff --git a/include/template/param_jrn.php b/include/template/param_jrn.php index 9661401df..af72faa96 100644 --- a/include/template/param_jrn.php +++ b/include/template/param_jrn.php @@ -14,7 +14,8 @@ if ($new || $type=='ODS' ): - + input(); -
+
diff --git a/include/user_menu.php b/include/user_menu.php index ea9a4502c..a1d6699f3 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -31,118 +31,6 @@ require_once("class_ispan.php"); -/*! - * \brief show the top menu for the user profile - * and highight the selected one - * \param p_high what to hightlight, by default it is autodetected - * but sometimes it must be given. Default value="" - * - * \return string - * - */ -function ShowMenuCompta_deprecated($p_high="") -{ - require_once('class_database.php'); - - // find our current menu - $default=basename($_SERVER['PHP_SELF']); - - switch ($default) -{ - case "user_jrn.php": - $default.="?show&".dossier::get(); - break; - } - - if ( $p_high !== "" ) $default=$p_high; - $default=-1; - if ( isset($_REQUEST['p_action'])) - { - switch ($_REQUEST['p_action'] ) - { - case 'impress': - $default=5; - break; - case 'fiche': - $default=6; - break; - case 'quick_writing': - $default=4; - break; - case 'gl': - $default=0; - break; - case 'ven': - $default=1; - break; - case 'client': - $default=1; - break; - case 'ach': - case 'fournisseur': - $default=2; - break; - case 'fin': - $default=3; - break; - case 'let': - $default=10; - break; - } - } - - $str_dossier=dossier::get(); - $p_array=array( - array("compta.php?p_action=gl&".$str_dossier ,_("Historique"),_("Historique : toutes les opérations"),0), - array("compta.php?p_action=ven&".$str_dossier ,_("Recette"),_("Journal de vente, produit et recette"),1), - array("compta.php?p_action=ach&".$str_dossier,_("Dépense"),_("Journaux de dépense, d'achat"),2 ), - array("compta.php?p_action=fin&".$str_dossier,_("Financier"),_("Journaux financiers: les banques, la caisse"),3), - array('compta.php?p_action=quick_writing&'.$str_dossier,_('Opération Diverses'),_('Journaux d\'OD: salaires, déclarations TVA,...'),4), - - array("compta.php?p_action=impress&".$str_dossier,_("Impression"),_("Impression"),5), - array("compta.php?p_action=fiche&".$str_dossier,_("Fiche"),_("Ajouter, modifier ou effacer des fiches"),6), - array("compta.php?p_action=let&".$str_dossier,_("Lettrage"),_("Ajouter, modifier ou effacer des lettrage"),10), - array("user_advanced.php?".$str_dossier,_("Avancé"),_("Opérations délicates"),7), - ); - - $result=ShowItem($p_array,'H',"mtitle","mtitle",$default,' style="width:100%;"'); - $str_dossier=dossier::get(); - $r=""; - $r.=menu_tool("compta.php"); - $r.='
'; - $r.=$result; - $r.='
'; - - return $r; -} - - -/*! - ************************************************** - * \brief build the menu of user_advanced.php - * - * \param $default - * - * \return the menu - */ -function ShowMenuAdvanced_deprecated($default="") -{ - $str_dossier=dossier::get(); - // Show the left menu - $left_menu=ShowItem(array( - //('rapprt.php','Rapprochement'), - - array('user_advanced.php?'.$str_dossier.'&p_action=preod',_('Ecritures definies'),"",9), - - array('compta.php?p_action=stock&'.$str_dossier,'Stock',_("Gestion des stocks"),5), - array('user_advanced.php?p_action=defreport&'.$str_dossier,_('Rapport'),_("Rapport"),6), - array('user_advanced.php?p_action=ouv&'.$str_dossier,_('Ecriture ouverture'),"",8), - array('user_advanced.php?p_action=verif&'.$str_dossier,_('Vérification'),"",10) - ), - 'H',"mtitle","mtitle",$default); - $r='
'.$left_menu."
"; - return $r; -} /*! * \brief Show the menu for the card management * @@ -229,66 +117,7 @@ function MenuAdmin() $menu=ShowItem($item,'H',"mtitle","mtitle",$def,' style="width:80%;margin-left:10%" '); return $menu; } -/*! - * \brief Show the parameter menu - * - * \param $p_action the last action choosed - * - * - * - * \return HTML Code - * - * - */ -function ShowMenuParam($p_action="") -{ - $s=dossier::get(); - $sub_menu=ShowItem(array( - array('parametre.php?p_action=company&'.$s,_('Sociétés'),_('Parametre societe'),1), - array('parametre.php?p_action=periode&'.$s,_('Periode'),_("Gestion des periodes"),25), - array('parametre.php?p_action=divers&'.$s,_('Divers'),_('Devise, moyen de paiement'),2), - array('parametre.php?p_action=pcmn&'.$s,_('Plan Comptable'),_('Modification du plan comptable'),11), - array('parametre.php?p_action=ext&'.$s,_('Extension'),_('Extension'),3), - array('parametre.php?p_action=sec&'.$s,_('Sécurité'),_('securite'),8), - array('parametre.php?p_action=preod&'.$s,_('Ecritures définies'),_('Ecritures définies'),12), - array('parametre.php?p_action=document&'.$s,_('Document'),_('Facture, lettre de rappel, proposition...'),7), - array('parametre.php?p_action=jrn&'.$s,_('Journaux'),_('Creation et modification de journaux'),10) - - ), - 'H',"mtitle","mtitle",$p_action,' width="100%"'); - return $sub_menu; - -} -/*! - * \brief display the html the menu in the jrn page - * - * \return nothing - * - * - */ - -function MenuJrn() -{ - $str_dossier=dossier::get(); - echo ''; - echo ''; - require_once('class_database.php'); - $Cn=new Database(dossier::id()); - $Ret=$Cn->exec_sql("select jrn_def_id,jrn_def_name, - jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc - from jrn_def join jrn_type on jrn_def_type=jrn_type_id order by jrn_def_name"); - $Max=Database::num_row($Ret); - - for ($i=0;$i<$Max;$i++) - { - $l_line=Database::fetch_array($Ret,$i); - printf ('', - $l_line['jrn_def_id'],$l_line['jrn_def_name']); - - } - echo "
'._('Création').'
%s
"; -} /*! * \brief Show the menu from the pcmn page * @@ -319,96 +148,3 @@ function menu_acc_plan($p_start=1) echo ""; } - -/*! - * \brief Show the menu for importing, verify and transfert Bank CSV - * - * \return nothing - */ -function ShowMenuImport() -{ - $str_dossier=dossier::get(); - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - - echo "
'._('Importer CSV').'
'._('Verif CSV').'
'._('Transfert CSV').'
'._('Purge CSV').'
"; -} -/*!\brief show the top menu to access the different modules in top - * \param $p_from from which module this function is called - * \note must include javascript : acc_ledger.js - * \return string -*/ -function menu_tool_deprecated($p_from) -{ - - if ( ! isset ($_REQUEST['gDossier'])) - return "" ; - $r=""; - - $r.= '
'; - $r.= '
'; - $r.= "

Dossier : ".h(dossier::name())."

"; - $r.=IButton::show_calc(); - - $r.= '
'; - $r.= '
'; - if ( $p_from == 'compta') $view='E'; - else $view='S'; - $agent=$_SERVER['HTTP_USER_AGENT']; - - $amodule=array( - array('value'=>'access.php','label'=>_('Tableau de bord')), - array('value'=>'user_pref.php','label'=>_('Preference')), - array('value'=>'parametre.php','label'=>_('Paramètre')), - array('value'=>'user_login.php','label'=>_('Autre Dossier')), - array('value'=>'logout.php','label'=>_('Deconnexion')), - array('value'=>'new_line'), - array('value'=>'compta.php','label'=>_('Compta Générale')), - array('value'=>'commercial.php','label'=>_('Gestion')), - array('value'=>'comptanalytic.php','label'=>_('Compt. Analytique')), - array('value'=>'extension.php','label'=>_('Extension')) - ) ; - - $gDossier=dossier::id(); - - $r.= ''; - $r.=''; - foreach($amodule as $col ) - { - $url=$col['value'].'?'.dossier::get(); - if ( $p_from==$col['value']) - { - $r.= ''; - - } - else - { - if ( $col['value']=='new_line') - { - $r.=''; - continue; - } - $r.= ''; - } - - } - $r.=''; - $r.=''; - - $r.= '
'. - ''.$col['label'].''. - '
'. - ''.$col['label'].''. - ''; - $r.= ''. - _('Recherche').'
'; - $r.= '
'; - $r.= '
'; - - $r.= ''; - return $r; -}