noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_pre_operation.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 // Copyright Author Dany De Bontridder danydb@aevalys.eu
21 
22 /*!\file
23  * \brief definition of Pre_operation
24  */
25 
26 /*! \brief manage the predefined operation, link to the table op_def
27  * and op_def_detail
28  *
29  */
30 require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
31 require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
32 require_once NOALYSS_INCLUDE.'/class/class_pre_op_ach.php';
33 require_once NOALYSS_INCLUDE.'/class/class_pre_op_ven.php';
34 require_once NOALYSS_INCLUDE.'/class/class_pre_op_advanced.php';
36 {
37  var $db; /*!< $db database connection */
38  var $nb_item; /*!< $nb_item nb of item */
39  var $p_jrn; /*!< $p_jrn jrn_def_id */
40  var $jrn_type; /*!< $jrn_type */
41  var $name; /*!< $name name of the predef. operation */
42 
43  function __construct($cn,$p_id=0)
44  {
45  $this->db=$cn;
46  $this->od_direct='false';
47  $this->od_id=$p_id;
48  }
49  /**
50  * @brief Propose to save the operation into a predefined operation
51  * @return HTML string
52  */
53  static function save_propose() {
54  $r="";
55  $r.= '<p class="decale">';
56  $r.= _("Donnez un nom pour sauver cette opération comme modèle")." <br>";
57  $opd_name = new IText('opd_name');
58  $r.= "Nom du modèle " . $opd_name->input();
59  $opd_description=new ITextarea('od_description');
60  $opd_description->style=' class="itextarea" style="width:30em;height:4em;vertical-align:top"';
61  $r.='</p>';
62  $r.= '<p class="decale">';
63  $r.= _('Description (max 50 car.)');
64  $r.='<br>';
65  $r.=$opd_description->input();
66  $r.='</p>';
67  return $r;
68  }
69 
70  /*!\brief fill the object with the $_POST variable */
71  function get_post()
72  {
73  $this->nb_item=$_POST['nb_item'];
74  $this->p_jrn=$_REQUEST['p_jrn'];
75  $this->jrn_type=$_POST['jrn_type'];
76 
77  $this->name=$_POST['opd_name'];
78 
79  $this->name=(trim($this->name)=='')?$_POST['e_comm']:$this->name;
80  $this->description= $_POST['od_description'];
81  if ( $this->name=="")
82  {
83  $n=$this->db->get_next_seq('op_def_op_seq');
84  $this->name=$this->jrn_type.$n;
85  // common value
86  }
87  }
88  function delete ()
89  {
90  $sql="delete from op_predef where od_id=".$this->od_id;
91  $this->db->exec_sql($sql);
92  }
93  /*!\brief save the predef check first is the name is unique
94  * \return true op.success otherwise false
95  */
96  function save()
97  {
98 
99  if ( $this->db->count_sql("select * from op_predef ".
100  "where upper(od_name)=upper('".Database::escape_string($this->name)."')".
101  "and jrn_def_id=".$this->p_jrn)
102  != 0 )
103  {
104  $this->name="copy_".$this->name."_".microtime(true);
105  }
106  if ( $this->count() > MAX_PREDEFINED_OPERATION )
107  {
108  echo '<span class="notice">'.("Vous avez atteint le max. d'op&eacute;ration pr&eacute;d&eacute;finie, d&eacute;sol&eacute;").'</span>';
109  return false;
110  }
111  $sql='insert into op_predef (jrn_def_id,od_name,od_item,od_jrn_type,od_direct,od_description)'.
112  'values'.
113  "($1,$2,$3,$4,$5 ,$6 )";
114  $this->db->exec_sql($sql,array($this->p_jrn,
115  $this->name,
116  $this->nb_item,
117  $this->jrn_type,
118  $this->od_direct,
119  $this->description,
120  ));
121  $this->od_id=$this->db->get_current_seq('op_def_op_seq');
122  return true;
123  }
124  /*!\brief load the data from the database and return an array
125  * \return an array
126  */
127  function load()
128  {
129  $sql="select od_id,jrn_def_id,od_name,od_item,od_jrn_type,od_description".
130  " from op_predef where od_id=".$this->od_id.
131  " order by od_name";
132  $res=$this->db->exec_sql($sql);
134  foreach (array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as $field) {
135  $this->$field=$array[0][$field];
136  }
137  switch ($this->od_jrn_type) {
138  case 'ACH':
139  $this->detail=new Pre_op_ach($this->db);
140  break;
141  case 'VEN':
142  $this->detail=new Pre_Op_ven($this->db);
143  break;
144  case 'ODS':
145  $this->detail=new Pre_op_advanced($this->db);
146  break;
147  default:
148  throw new Exception('Load PreOperatoin failed'.$this->od_jrn_type);
149  }
150  $this->detail->set_od_id($this->od_id);
151  $this->detail->jrn_def_id=$this->jrn_def_id;
152 
153  return $array;
154  }
155  function compute_array()
156  {
157  $p_array=$this->load();
158  $array=array(
159  "e_comm"=>$p_array[0]["od_name"],
160  "nb_item"=>(($p_array[0]["od_item"]<10)?10:$p_array[0]["od_item"]) ,
161  "p_jrn"=>$p_array[0]["jrn_def_id"],
162  "jrn_type"=>$p_array[0]["od_jrn_type"],
163  "od_description"=>$p_array['0']['od_description']
164  );
165  return $array;
166 
167  }
168 
169  /*!\brief show the button for selecting a predefined operation */
170  function show_button()
171  {
172 
173  $select=new ISelect();
174  $value=$this->db->make_array("select od_id,od_name from op_predef ".
175  " where jrn_def_id=".$this->p_jrn.
176  " and od_direct ='".$this->od_direct."'".
177  " order by od_name");
178 
179  if ( empty($value)==true) return "";
180  $select->value=$value;
181  $r=$select->input("pre_def");
182 
183  return $r;
184  }
185  /*!\brief count the number of pred operation for a ledger */
186  function count()
187  {
188  $a=$this->db->count_sql("select od_id,od_name from op_predef ".
189  " where jrn_def_id=".$this->p_jrn.
190  " and od_direct ='".$this->od_direct."'".
191  " order by od_name");
192  return $a;
193  }
194  /*!\brief get the list of the predef. operation of a ledger
195  * \return string
196  */
197  function get_list_ledger()
198  {
199  $sql="select od_id,od_name,od_description from op_predef ".
200  " where jrn_def_id=".$this->p_jrn.
201  " and od_direct ='".$this->od_direct."'".
202  " order by od_name";
203  $res=$this->db->exec_sql($sql);
205  return $all;
206  }
207  /*!\brief set the ledger
208  * \param $p_jrn is the ledger (jrn_id)
209  */
210  function set_jrn($p_jrn)
211  {
212  $this->p_jrn=$p_jrn;
213  }
214 
215  /**
216  *
217  * @brief display the detail of predefined operation, normally everything
218  * is loaded
219  */
220  function display()
221  {
222  $array=$this->detail->compute_array();
223  echo $this->detail->display($array);
224  }
225 }
226 
227 /*!\brief mother of the pre_op_XXX, it contains only one data : an
228  * object Pre_Operation. The child class contains an array of
229  * Pre_Operation object
230  */
232 {
234  function __construct($p_cn,$p_id=0)
235  {
236  $this->db=$p_cn;
237  $this->operation=new Pre_operation($this->db);
238  $this->valid=array('ledger'=>'jrn_def_id','ledger_type'=>'jrn_type','direct'=>'od_direct');
239  $this->jrn_def_id=-1;
240  }
241 
242 
243  /*!\brief show a form to use pre_op
244  */
245  function form_get ($p_url)
246  {
247  $r=HtmlInput::button_action(_("Modèle d'opérations"), ' $(\'modele_op_div\').style.display=\'block\';$(\'lk_modele_op_tab\').focus();');
248  $r.='<div id="modele_op_div" class="noprint">';
249  $r.=HtmlInput::title_box(_("Modèle d'opérations"), 'modele_op_div', 'hide');
250  $hid=new IHidden();
251  $r.=$hid->input("action","use_opd");
252  $r.=$hid->input("jrn_type",$this->get("ledger_type"));
253  $r.= $this->show_button($p_url);
254  $r.=' <p style="text-align: center">'.
255  HtmlInput::button_hide('modele_op_div').
256  '</p>';
257  $r.='</div>';
258  return $r;
259 
260  }
261  /*!\brief count the number of pred operation for a ledger */
262  function count()
263  {
264  $a=$this->db->count_sql("select od_id,od_name from op_predef ".
265  " where jrn_def_id=".$this->jrn_def_id.
266  " and od_direct ='".$this->od_direct."'".
267  " order by od_name");
268  return $a;
269  }
270  /*!\brief show the button for selecting a predefined operation */
271  function show_button($p_url)
272  {
273 
274 
275  $value=$this->db->get_array("select od_id,od_name,od_description from op_predef ".
276  " where jrn_def_id=$1".
277  " and od_direct =$2".
278  " order by od_name",
279  array($this->jrn_def_id,$this->od_direct ));
280 
281  if ( $this->jrn_def_id=='') $value=array();
282 
283  $r="";
284  $r.='<h2>'._("Choisissez un modèle").'</h2>';
285  $r.=_('Cherche').' '.HtmlInput::filter_table('modele_op_tab', '0', '0');
286  $r.='<table style="width:100%" id="modele_op_tab">';
287  for ($i=0;$i<count($value);$i++) {
288  $r.='<tr class="'.(($i%2==0)?"even":"odd").'">';
289  $r.='<td style="font-weight:bold;vertical-align:top;text-decoration:underline">';
290  $r.=sprintf('<a href="%s&pre_def=%s" onclick="waiting_box()">%s</a> ',
291  $p_url,$value[$i]['od_id'],$value[$i]['od_name']);
292  $r.='</td>';
293  $r.='<td>'.h($value[$i]['od_description']).'</td>';
294  $r.='</tr>';
295  }
296  $r.='</table>';
297  return $r;
298  }
299  public function get_operation()
300  {
301  if ( $this->jrn_def_id=='') return array();
302  $value=$this->db->make_array("select od_id,od_name from op_predef ".
303  " where jrn_def_id=".sql_string($this->jrn_def_id).
304  " and od_direct ='".sql_string($this->od_direct)."'".
305  " order by od_name",1);
306  return $value;
307  }
308  function set($p_param,$value)
309  {
310  if ( ! isset ($this->valid[$p_param] ) )
311  {
312  $msg=_(" le parametre $p_param n'existe pas ".__FILE__.':'.__LINE__);
313  throw new Exception($msg);
314  }
315  $attr=$this->valid[$p_param];
316  $this->$attr=$value;
317  }
318  function get($p_param)
319  {
320 
321  if ( ! isset ($this->valid[$p_param] ) )
322  {
323  $msg=_(" le parametre $p_param n'existe pas ".__FILE__.':'.__LINE__);
324  throw new Exception($msg);
325  }
326  $attr=$this->valid[$p_param];
327  return $this->$attr;
328  }
329 
330  function get_post()
331  {
332  $this->operation->get_post();
333  }
334 
335 }
display()
display the detail of predefined operation, normally everything is loaded
$_POST['ac']
Definition: do.php:279
$select
static fetch_all($ret)
wrapper for the function pg_fetch_all
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:457
static button_hide($div_name)
Hide the HTML popup.
show_button()
show the button for selecting a predefined operation
manage the predefined operation, link to the table op_def and op_def_detail
$p_url
__construct($cn, $p_id=0)
$value
static title_box($name, $div, $mod="close", $p_js="")
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
count()
count the number of pred operation for a ledger
get_list_ledger()
get the list of the predef. operation of a ledger
$opd_description
concerns the predefined operation for ACH ledger
static filter_table($p_table_id, $p_col, $start_row)
$from_poste name
get_post()
fill the object with the $_POST variable
form_get($p_url)
show a form to use pre_op
static button_action($action, $javascript, $id="xx", $p_class="button")
button Html
save()
save the predef check first is the name is unique
$_REQUEST['ac']
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
mother of the pre_op_XXX, it contains only one data : an object Pre_Operation. The child class contai...
$all
count()
count the number of pred operation for a ledger
load()
load the data from the database and return an array
show_button($p_url)
show the button for selecting a predefined operation
const MAX_PREDEFINED_OPERATION
Definition: constant.php:121
static save_propose()
Propose to save the operation into a predefined operation.
$SecUser db
set_jrn($p_jrn)
set the ledger