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 require_once("class_iselect.php");
00031 require_once("class_ihidden.php");
00032 require_once 'class_pre_op_ach.php';
00033 require_once 'class_pre_op_ven.php';
00034 require_once 'class_pre_op_advanced.php';
00035 class Pre_operation
00036 {
00037 var $db;
00038 var $nb_item;
00039 var $p_jrn;
00040 var $jrn_type;
00041 var $name;
00042
00043 function Pre_operation($cn,$p_id=0)
00044 {
00045 $this->db=$cn;
00046 $this->od_direct='false';
00047 $this->od_id=$p_id;
00048 }
00049
00050
00051
00052
00053 static function save_propose() {
00054 $r="<h2>Modèle d'opération</h2>";
00055 $r.= '<p class="decale">';
00056 $r.= "Donnez un nom pour sauver cette opération comme modèle <br>";
00057 $opd_name = new IText('opd_name');
00058 $r.= "Nom du modèle " . $opd_name->input();
00059 $opd_description=new ITextarea('od_description');
00060 $opd_description->style=' class="itextarea" style="width:30em;height:4em;vertical-align:top"';
00061 $r.='</p>';
00062 $r.= '<p class="decale">';
00063 $r.= 'Description (max 50 car.)';
00064 $r.='<br>';
00065 $r.=$opd_description->input();
00066 $r.='</p>';
00067 return $r;
00068 }
00069
00070
00071 function get_post()
00072 {
00073 $this->nb_item=$_POST['nb_item'];
00074 $this->p_jrn=$_REQUEST['p_jrn'];
00075 $this->jrn_type=$_POST['jrn_type'];
00076
00077 $this->name=$_POST['opd_name'];
00078
00079 $this->name=(trim($this->name)=='')?$_POST['e_comm']:$this->name;
00080 $this->description= $_POST['od_description'];
00081 if ( $this->name=="")
00082 {
00083 $n=$this->db->get_next_seq('op_def_op_seq');
00084 $this->name=$this->jrn_type.$n;
00085
00086 }
00087 }
00088 function delete ()
00089 {
00090 $sql="delete from op_predef where od_id=".$this->od_id;
00091 $this->db->exec_sql($sql);
00092 }
00093
00094
00095
00096 function save()
00097 {
00098
00099 if ( $this->db->count_sql("select * from op_predef ".
00100 "where upper(od_name)=upper('".Database::escape_string($this->name)."')".
00101 "and jrn_def_id=".$this->p_jrn)
00102 != 0 )
00103 {
00104 echo "<span class=\"notice\"> Ce modèle d' opération a déjà été sauvé</span>";
00105 return false;
00106 }
00107 if ( $this->count() > MAX_PREDEFINED_OPERATION )
00108 {
00109 echo '<span class="notice">Vous avez atteint le max. d\'opération prédéfinie, désolé</span>';
00110 return false;
00111 }
00112 $sql='insert into op_predef (jrn_def_id,od_name,od_item,od_jrn_type,od_direct,od_description)'.
00113 'values'.
00114 "($1,$2,$3,$4,$5 ,$6 )";
00115 $this->db->exec_sql($sql,array($this->p_jrn,
00116 $this->name,
00117 $this->nb_item,
00118 $this->jrn_type,
00119 $this->od_direct,
00120 $this->description,
00121 ));
00122 $this->od_id=$this->db->get_current_seq('op_def_op_seq');
00123 return true;
00124 }
00125
00126
00127
00128 function load()
00129 {
00130 $sql="select od_id,jrn_def_id,od_name,od_item,od_jrn_type,od_description".
00131 " from op_predef where od_id=".$this->od_id.
00132 " order by od_name";
00133 $res=$this->db->exec_sql($sql);
00134 $array=Database::fetch_all($res);
00135 foreach (array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as $field) {
00136 $this->$field=$array[0][$field];
00137 }
00138 switch ($this->od_jrn_type) {
00139 case 'ACH':
00140 $this->detail=new Pre_op_ach($this->db);
00141 break;
00142 case 'VEN':
00143 $this->detail=new Pre_Op_ven($this->db);
00144 break;
00145 case 'ODS':
00146 $this->detail=new Pre_op_advanced($this->db);
00147 break;
00148 default:
00149 throw new Exception('Load PreOperatoin failed'.$this->od_jrn_type);
00150 }
00151 $this->detail->set_od_id($this->od_id);
00152 $this->detail->jrn_def_id=$this->jrn_def_id;
00153
00154 return $array;
00155 }
00156 function compute_array()
00157 {
00158 $p_array=$this->load();
00159 $array=array(
00160 "e_comm"=>$p_array[0]["od_name"],
00161 "nb_item"=>(($p_array[0]["od_item"]<10?10:$p_array[0]["od_item"])) ,
00162 "p_jrn"=>$p_array[0]["jrn_def_id"],
00163 "jrn_type"=>$p_array[0]["od_jrn_type"],
00164 "od_description"=>$p_array['0']['od_description']
00165 );
00166 return $array;
00167
00168 }
00169
00170
00171 function show_button()
00172 {
00173
00174 $select=new ISelect();
00175 $value=$this->db->make_array("select od_id,od_name from op_predef ".
00176 " where jrn_def_id=".$this->p_jrn.
00177 " and od_direct ='".$this->od_direct."'".
00178 " order by od_name");
00179
00180 if ( empty($value)==true) return "";
00181 $select->value=$value;
00182 $r=$select->input("pre_def");
00183
00184 return $r;
00185 }
00186
00187 function count()
00188 {
00189 $a=$this->db->count_sql("select od_id,od_name from op_predef ".
00190 " where jrn_def_id=".$this->p_jrn.
00191 " and od_direct ='".$this->od_direct."'".
00192 " order by od_name");
00193 return $a;
00194 }
00195
00196
00197
00198 function get_list_ledger()
00199 {
00200 $sql="select od_id,od_name,od_description from op_predef ".
00201 " where jrn_def_id=".$this->p_jrn.
00202 " and od_direct ='".$this->od_direct."'".
00203 " order by od_name";
00204 $res=$this->db->exec_sql($sql);
00205 $all=Database::fetch_all($res);
00206 return $all;
00207 }
00208
00209
00210
00211 function set_jrn($p_jrn)
00212 {
00213 $this->p_jrn=$p_jrn;
00214 }
00215
00216
00217
00218
00219
00220
00221 function display()
00222 {
00223 $array=$this->detail->compute_array();
00224 echo $this->detail->display($array);
00225 }
00226 }
00227
00228
00229
00230
00231
00232 class Pre_operation_detail
00233 {
00234 var $operation;
00235 function __construct($p_cn,$p_id=0)
00236 {
00237 $this->db=$p_cn;
00238 $this->operation=new Pre_operation($this->db);
00239 $this->valid=array('ledger'=>'jrn_def_id','ledger_type'=>'jrn_type','direct'=>'od_direct');
00240 $this->jrn_def_id=-1;
00241 }
00242
00243
00244
00245
00246 function form_get ($p_url)
00247 {
00248 $r=HtmlInput::button_action("Modèle d'opérations", ' $(\'modele_op_div\').style.display=\'block\';$(\'lk_modele_op_tab\').focus();');
00249 $r.='<div id="modele_op_div" class="noprint">';
00250 $r.=HtmlInput::title_box("Modèle d'opérations ", 'modele_op_div', 'hide');
00251 $hid=new IHidden();
00252 $r.=$hid->input("action","use_opd");
00253 $r.=$hid->input("jrn_type",$this->get("ledger_type"));
00254 $r.= $this->show_button($p_url);
00255 $r.='</div>';
00256 return $r;
00257
00258 }
00259
00260 function count()
00261 {
00262 $a=$this->db->count_sql("select od_id,od_name from op_predef ".
00263 " where jrn_def_id=".$this->jrn_def_id.
00264 " and od_direct ='".$this->od_direct."'".
00265 " order by od_name");
00266 return $a;
00267 }
00268
00269 function show_button($p_url)
00270 {
00271
00272
00273 $value=$this->db->get_array("select od_id,od_name,od_description from op_predef ".
00274 " where jrn_def_id=$1".
00275 " and od_direct =$2".
00276 " order by od_name",array($this->jrn_def_id,$this->od_direct ));
00277
00278 if ( $this->jrn_def_id=='') $value=array();
00279
00280 $r="";
00281 $r.='<h2>Choississez un modèle</h2>';
00282 $r.='Filtrer '.HtmlInput::filter_table('modele_op_tab', '0', '0');
00283 $r.='<table style="width:100%" id="modele_op_tab">';
00284 for ($i=0;$i<count($value);$i++) {
00285 $r.='<tr class="'.(($i%2==0)?"even":"odd").'">';
00286 $r.='<td style="font-weight:bold;vertical-align:top;text-decoration:underline">';
00287 $r.=sprintf('<a href="%s&pre_def=%s" onclick="waiting_box()">%s</a> ',$p_url,$value[$i]['od_id'],$value[$i]['od_name']);
00288 $r.='</td>';
00289 $r.='<td>'.h($value[$i]['od_description']).'</td>';
00290 $r.='</tr>';
00291 }
00292 $r.='</table>';
00293 return $r;
00294 }
00295 public function get_operation()
00296 {
00297 if ( $this->jrn_def_id=='') return array();
00298 $value=$this->db->make_array("select od_id,od_name from op_predef ".
00299 " where jrn_def_id=".sql_string($this->jrn_def_id).
00300 " and od_direct ='".sql_string($this->od_direct)."'".
00301 " order by od_name",1);
00302 return $value;
00303 }
00304 function set($p_param,$value)
00305 {
00306 if ( ! isset ($this->valid[$p_param] ) )
00307 {
00308 echo(" le parametre $p_param n'existe pas ".__FILE__.':'.__LINE__);
00309 exit();
00310 }
00311 $attr=$this->valid[$p_param];
00312 $this->$attr=$value;
00313 }
00314 function get($p_param)
00315 {
00316
00317 if ( ! isset ($this->valid[$p_param] ) )
00318 {
00319 echo(" le parametre $p_param n'existe pas ".__FILE__.':'.__LINE__);
00320 exit();
00321 }
00322 $attr=$this->valid[$p_param];
00323 return $this->$attr;
00324 }
00325
00326 function get_post()
00327 {
00328 $this->operation->get_post();
00329 }
00330
00331 }