00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 require_once("class_iselect.php");
00032 require_once("class_ihidden.php");
00033 class Pre_operation
00034 {
00035 var $db;
00036 var $nb_item;
00037 var $p_jrn;
00038 var $jrn_type;
00039 var $name;
00040
00041 function Pre_operation($cn)
00042 {
00043 $this->db=$cn;
00044 $this->od_direct='false';
00045 }
00046
00047 function get_post()
00048 {
00049 $this->nb_item=$_POST['nb_item'];
00050 $this->p_jrn=$_REQUEST['p_jrn'];
00051 $this->jrn_type=$_POST['jrn_type'];
00052
00053 $this->name=$_POST['opd_name'];
00054
00055 $this->name=(trim($this->name)=='')?$_POST['e_comm']:$this->name;
00056
00057 if ( $this->name=="")
00058 {
00059 $n=$this->db->get_next_seq('op_def_op_seq');
00060 $this->name=$this->jrn_type.$n;
00061
00062 }
00063 }
00064 function delete ()
00065 {
00066 $sql="delete from op_predef where od_id=".$this->od_id;
00067 $this->db->exec_sql($sql);
00068 }
00069
00070
00071
00072 function save()
00073 {
00074
00075 if ( $this->db->count_sql("select * from op_predef ".
00076 "where upper(od_name)=upper('".Database::escape_string($this->name)."')".
00077 "and jrn_def_id=".$this->p_jrn)
00078 != 0 )
00079 {
00080 echo "<span class=\"notice\"> Ce modèle d' opération a déjà été sauvé</span>";
00081 return false;
00082 }
00083 if ( $this->count() > MAX_PREDEFINED_OPERATION )
00084 {
00085 echo '<span class="notice">Vous avez atteint le max. d\'opération prédéfinie, désolé</span>';
00086 return false;
00087 }
00088 $sql=sprintf('insert into op_predef (jrn_def_id,od_name,od_item,od_jrn_type,od_direct)'.
00089 'values'.
00090 "(%d,'%s',%d,'%s','%s')",
00091 $this->p_jrn,
00092 Database::escape_string($this->name),
00093 $this->nb_item,
00094 $this->jrn_type,
00095 $this->od_direct);
00096 $this->db->exec_sql($sql);
00097 $this->od_id=$this->db->get_current_seq('op_def_op_seq');
00098 return true;
00099 }
00100
00101
00102
00103 function load()
00104 {
00105 $sql="select od_id,jrn_def_id,od_name,od_item,od_jrn_type".
00106 " from op_predef where od_id=".$this->od_id.
00107 " and od_direct='".$this->od_direct."'".
00108 " order by od_name";
00109 $res=$this->db->exec_sql($sql);
00110 $array=Database::fetch_all($res);
00111
00112 return $array;
00113 }
00114 function compute_array()
00115 {
00116 $p_array=$this->load();
00117 $array=array(
00118 "e_comm"=>$p_array[0]["od_name"],
00119 "nb_item"=>(($p_array[0]["od_item"]<10?10:$p_array[0]["od_item"])) ,
00120 "p_jrn"=>$p_array[0]["jrn_def_id"],
00121 "jrn_type"=>$p_array[0]["od_jrn_type"]
00122 );
00123 return $array;
00124
00125 }
00126
00127
00128 function show_button()
00129 {
00130
00131 $select=new ISelect();
00132 $value=$this->db->make_array("select od_id,od_name from op_predef ".
00133 " where jrn_def_id=".$this->p_jrn.
00134 " and od_direct ='".$this->od_direct."'".
00135 " order by od_name");
00136
00137 if ( empty($value)==true) return "";
00138 $select->value=$value;
00139 $r=$select->input("pre_def");
00140
00141 return $r;
00142 }
00143
00144 function count()
00145 {
00146 $a=$this->db->count_sql("select od_id,od_name from op_predef ".
00147 " where jrn_def_id=".$this->p_jrn.
00148 " and od_direct ='".$this->od_direct."'".
00149 " order by od_name");
00150 return $a;
00151 }
00152
00153
00154
00155 function get_list_ledger()
00156 {
00157 $sql="select od_id,od_name from op_predef ".
00158 " where jrn_def_id=".$this->p_jrn.
00159 " and od_direct ='".$this->od_direct."'".
00160 " order by od_name";
00161 $res=$this->db->exec_sql($sql);
00162 $all=Database::fetch_all($res);
00163 return $all;
00164 }
00165
00166
00167
00168 function set_jrn($p_jrn)
00169 {
00170 $this->p_jrn=$p_jrn;
00171 }
00172 }
00173
00174
00175
00176
00177
00178 class Pre_operation_detail
00179 {
00180 var $operation;
00181 function __construct($p_cn)
00182 {
00183 $this->db=$p_cn;
00184 $this->operation=new Pre_operation($this->db);
00185 $this->valid=array('ledger'=>'jrn_def_id','ledger_type'=>'jrn_type','direct'=>'od_direct');
00186 $this->jrn_def_id=-1;
00187 }
00188
00189
00190
00191
00192 function form_get ()
00193 {
00194
00195 $hid=new IHidden();
00196 $r=$hid->input("action","use_opd");
00197 $r.=$hid->input("jrn_type",$this->get("ledger_type"));
00198 $r.= HtmlInput::submit('use_opd','Utilisez une opération prédéfinie');
00199 $r.= $this->show_button();
00200 return $r;
00201
00202 }
00203
00204 function count()
00205 {
00206 $a=$this->db->count_sql("select od_id,od_name from op_predef ".
00207 " where jrn_def_id=".$this->jrn_def_id.
00208 " and od_direct ='".$this->od_direct."'".
00209 " order by od_name");
00210 return $a;
00211 }
00212
00213 function show_button()
00214 {
00215
00216 $select=new ISelect();
00217
00218 $value=$this->get_operation();
00219
00220 $select->value=$value;
00221 $r=$select->input("pre_def");
00222 return $r;
00223 }
00224 public function get_operation()
00225 {
00226 if ( $this->jrn_def_id=='') return array();
00227 $value=$this->db->make_array("select od_id,od_name from op_predef ".
00228 " where jrn_def_id=".sql_string($this->jrn_def_id).
00229 " and od_direct ='".sql_string($this->od_direct)."'".
00230 " order by od_name",1);
00231 return $value;
00232 }
00233 function set($p_param,$value)
00234 {
00235 if ( ! isset ($this->valid[$p_param] ) )
00236 {
00237 echo(" le parametre $p_param n'existe pas ".__FILE__.':'.__LINE__);
00238 exit();
00239 }
00240 $attr=$this->valid[$p_param];
00241 $this->$attr=$value;
00242 }
00243 function get($p_param)
00244 {
00245
00246 if ( ! isset ($this->valid[$p_param] ) )
00247 {
00248 echo(" le parametre $p_param n'existe pas ".__FILE__.':'.__LINE__);
00249 exit();
00250 }
00251 $attr=$this->valid[$p_param];
00252 return $this->$attr;
00253 }
00254
00255 function get_post()
00256 {
00257 $this->operation->get_post();
00258 }
00259
00260 }