noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_pre_operation.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief definition of Pre_operation
00024  */
00025 
00026 /*! \brief manage the predefined operation, link to the table op_def
00027  * and op_def_detail
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;                                            /*!< $db database connection */
00038     var $nb_item;                                       /*!< $nb_item nb of item */
00039     var $p_jrn;                                 /*!< $p_jrn jrn_def_id */
00040     var $jrn_type;                                      /*!< $jrn_type */
00041     var $name;                                          /*!< $name name of the predef. operation */
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      * @brief Propose to save the operation into a predefined operation
00051      * @return HTML  string
00052      */
00053     static function save_propose() {
00054         $r="";
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     /*!\brief fill the object with the $_POST variable */
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             // common value
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     /*!\brief save the predef check first is the name is unique
00094      * \return true op.success otherwise false
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             $this->name="copy_".$this->name."_".microtime(true);
00105         }
00106         if ( $this->count()  > MAX_PREDEFINED_OPERATION )
00107         {
00108             echo '<span class="notice">Vous avez atteint le max. d\'op&eacute;ration pr&eacute;d&eacute;finie, d&eacute;sol&eacute;</span>';
00109             return false;
00110         }
00111         $sql='insert into op_predef (jrn_def_id,od_name,od_item,od_jrn_type,od_direct,od_description)'.
00112                      'values'.
00113                      "($1,$2,$3,$4,$5  ,$6               )";
00114         $this->db->exec_sql($sql,array($this->p_jrn,
00115                      $this->name,
00116                      $this->nb_item,
00117                      $this->jrn_type,
00118                      $this->od_direct,
00119                      $this->description,
00120             ));
00121         $this->od_id=$this->db->get_current_seq('op_def_op_seq');
00122         return true;
00123     }
00124     /*!\brief load the data from the database and return an array
00125      * \return an array
00126      */
00127     function load()
00128     {
00129         $sql="select od_id,jrn_def_id,od_name,od_item,od_jrn_type,od_description".
00130              " from op_predef where od_id=".$this->od_id.
00131              " order by od_name";
00132         $res=$this->db->exec_sql($sql);
00133         $array=Database::fetch_all($res);
00134         foreach (array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as $field) {
00135             $this->$field=$array[0][$field];
00136         }
00137         switch ($this->od_jrn_type) {
00138             case 'ACH':
00139                 $this->detail=new Pre_op_ach($this->db);
00140                 break;
00141             case 'VEN':
00142                 $this->detail=new Pre_Op_ven($this->db);
00143                 break;
00144             case 'ODS':
00145                 $this->detail=new Pre_op_advanced($this->db);
00146                 break;
00147             default:
00148                 throw new Exception('Load PreOperatoin failed'.$this->od_jrn_type);
00149           }
00150         $this->detail->set_od_id($this->od_id);
00151         $this->detail->jrn_def_id=$this->jrn_def_id;
00152         
00153         return $array;
00154     }
00155     function compute_array()
00156     {
00157         $p_array=$this->load();
00158         $array=array(
00159                    "e_comm"=>$p_array[0]["od_name"],
00160                    "nb_item"=>(($p_array[0]["od_item"]<10?10:$p_array[0]["od_item"]))   ,
00161                    "p_jrn"=>$p_array[0]["jrn_def_id"],
00162                    "jrn_type"=>$p_array[0]["od_jrn_type"],
00163                    "od_description"=>$p_array['0']['od_description']
00164                );
00165         return $array;
00166 
00167     }
00168 
00169     /*!\brief show the button for selecting a predefined operation */
00170     function show_button()
00171     {
00172 
00173         $select=new ISelect();
00174         $value=$this->db->make_array("select od_id,od_name from op_predef ".
00175                                      " where jrn_def_id=".$this->p_jrn.
00176                                      " and od_direct ='".$this->od_direct."'".
00177                                      " order by od_name");
00178 
00179         if ( empty($value)==true) return "";
00180         $select->value=$value;
00181         $r=$select->input("pre_def");
00182 
00183         return $r;
00184     }
00185     /*!\brief count the number of pred operation for a ledger */
00186     function count()
00187     {
00188         $a=$this->db->count_sql("select od_id,od_name from op_predef ".
00189                                 " where jrn_def_id=".$this->p_jrn.
00190                                 " and od_direct ='".$this->od_direct."'".
00191                                 " order by od_name");
00192         return $a;
00193     }
00194     /*!\brief get the list of the predef. operation of a ledger
00195      * \return string
00196      */
00197     function get_list_ledger()
00198     {
00199         $sql="select od_id,od_name,od_description from op_predef ".
00200              " where jrn_def_id=".$this->p_jrn.
00201              " and od_direct ='".$this->od_direct."'".
00202              " order by od_name";
00203         $res=$this->db->exec_sql($sql);
00204         $all=Database::fetch_all($res);
00205         return $all;
00206     }
00207     /*!\brief set the ledger
00208      * \param $p_jrn is the ledger (jrn_id)
00209      */
00210     function set_jrn($p_jrn)
00211     {
00212         $this->p_jrn=$p_jrn;
00213     }
00214    
00215     /**
00216      * 
00217      * @brief display the detail of predefined operation, normally everything 
00218      * is loaded
00219      */
00220     function display() 
00221     {
00222         $array=$this->detail->compute_array();
00223         echo $this->detail->display($array);
00224     }
00225 }
00226 
00227 /*!\brief mother of the pre_op_XXX, it contains only one data : an
00228  * object Pre_Operation. The child class contains an array of
00229  * Pre_Operation object
00230  */
00231 class Pre_operation_detail
00232 {
00233     var $operation;
00234     function __construct($p_cn,$p_id=0)
00235     {
00236         $this->db=$p_cn;
00237         $this->operation=new Pre_operation($this->db);
00238         $this->valid=array('ledger'=>'jrn_def_id','ledger_type'=>'jrn_type','direct'=>'od_direct');
00239                 $this->jrn_def_id=-1;
00240     }
00241 
00242 
00243     /*!\brief show a form to use pre_op
00244      */
00245     function form_get ($p_url)
00246     {
00247         $r=HtmlInput::button_action("Modèle d'opérations", ' $(\'modele_op_div\').style.display=\'block\';$(\'lk_modele_op_tab\').focus();');
00248         $r.='<div id="modele_op_div" class="noprint">';
00249         $r.=HtmlInput::title_box("Modèle d'opérations ", 'modele_op_div', 'hide');
00250         $hid=new IHidden();
00251         $r.=$hid->input("action","use_opd");
00252         $r.=$hid->input("jrn_type",$this->get("ledger_type"));
00253         $r.= $this->show_button($p_url);
00254         $r.='</div>';
00255         return $r;
00256 
00257     }
00258     /*!\brief count the number of pred operation for a ledger */
00259     function count()
00260     {
00261         $a=$this->db->count_sql("select od_id,od_name from op_predef ".
00262                                 " where jrn_def_id=".$this->jrn_def_id.
00263                                 " and od_direct ='".$this->od_direct."'".
00264                                 " order by od_name");
00265         return $a;
00266     }
00267     /*!\brief show the button for selecting a predefined operation */
00268     function show_button($p_url)
00269     {
00270         
00271         
00272         $value=$this->db->get_array("select od_id,od_name,od_description from op_predef ".
00273                                      " where jrn_def_id=$1".
00274                                      " and od_direct =$2".
00275                                      " order by od_name",array($this->jrn_def_id,$this->od_direct ));
00276         
00277         if ( $this->jrn_def_id=='') $value=array();
00278         
00279         $r="";
00280         $r.='<h2>Choisissez un modèle</h2>';
00281         $r.='Filtrer '.HtmlInput::filter_table('modele_op_tab', '0', '0');
00282         $r.='<table style="width:100%" id="modele_op_tab">';
00283         for ($i=0;$i<count($value);$i++) {
00284             $r.='<tr class="'.(($i%2==0)?"even":"odd").'">';
00285             $r.='<td style="font-weight:bold;vertical-align:top;text-decoration:underline">';
00286             $r.=sprintf('<a href="%s&pre_def=%s" onclick="waiting_box()">%s</a> ',$p_url,$value[$i]['od_id'],$value[$i]['od_name']);
00287             $r.='</td>';
00288             $r.='<td>'.h($value[$i]['od_description']).'</td>';
00289             $r.='</tr>';
00290         }
00291         $r.='</table>';
00292         return $r;
00293     }
00294     public function   get_operation()
00295     {
00296                 if ( $this->jrn_def_id=='') return array();
00297         $value=$this->db->make_array("select od_id,od_name from op_predef ".
00298                                      " where jrn_def_id=".sql_string($this->jrn_def_id).
00299                                      " and od_direct ='".sql_string($this->od_direct)."'".
00300                                      " order by od_name",1);
00301         return $value;
00302     }
00303     function set($p_param,$value)
00304     {
00305         if ( ! isset ($this->valid[$p_param] ) )
00306         {
00307             $msg=_(" le parametre $p_param n'existe pas ".__FILE__.':'.__LINE__);
00308             throw new Exception($msg);
00309         }
00310         $attr=$this->valid[$p_param];
00311         $this->$attr=$value;
00312     }
00313     function get($p_param)
00314     {
00315 
00316         if ( ! isset ($this->valid[$p_param] ) )
00317         {
00318             $msg=_(" le parametre $p_param n'existe pas ".__FILE__.':'.__LINE__);
00319             throw new Exception($msg);
00320         }
00321         $attr=$this->valid[$p_param];
00322         return $this->$attr;
00323     }
00324 
00325     function get_post()
00326     {
00327         $this->operation->get_post();
00328     }
00329 
00330 }
 All Data Structures Namespaces Files Functions Variables Enumerations