noalyss Version-9
pre_operation.class.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 */
31{
32 private $db; /*!< $db database connection */
33 private $nb_item; /*!< $nb_item nb of item */
34 private $p_jrn; /*!< $p_jrn jrn_def_id */
35 private $jrn_type; /*!< $jrn_type */
36 private $name; /*!< $name name of the predef. operation */
37 private $detail; /*!< Pre_operation_detail object */
38 var $od_direct ; /*!< Compatibility for ACH in direct mode, only for ODS */
39 private $od_id; /*!< id of the Predefined Operation */
40 private $isloaded;
41 private $description; /*!< description of the predefined operation */
42 function __construct($cn,$p_id=0)
43 {
44 $this->db=$cn;
45 $this->od_direct='f';
46 $this->od_id=$p_id;
47 $this->p_jrn=0;
48 $this->jrn_type='x';
49 $this->name='';
50 $this->isloaded=false;
51 $this->description="";
52
53 }
54
55 /**
56 * @brief Propose to save the operation into a predefined operation
57 * @return HTML string
58 */
59 static function save_propose() {
60 $r="";
61 $r.= '<p class="decale">';
62 $r.= _("Donnez un nom pour sauver cette opération comme modèle")." <br>";
63 $opd_name = new IText('opd_name');
64 $r.=_( "Nom du modèle " ) . $opd_name->input();
65 $opd_description=new ITextarea('od_description');
66 $opd_description->style=' class="itextarea" style="width:30em;height:4em;vertical-align:top"';
67 $r.='</p>';
68 $r.= '<p class="decale">';
69 $r.= _('Description (max 50 car.)');
70 $r.='<br>';
71 $r.=$opd_description->input();
72 $r.='</p>';
73 return $r;
74 }
75 /**
76 * @return string
77 */
78 public function get_description()
79 {
80 return $this->description;
81 }/**
82 * @param string $description
83 */
85 {
86 $this->description = $description;
87 return $this;
88 }
89
90
91 /*!\brief fill the object with the $_POST variable */
92 function get_post()
93 {
94 $http=new HttpInput();
95 $this->nb_item=$http->post('nb_item',"number");
96 $this->p_jrn=$http->request('p_jrn',"number");
97 $this->jrn_type=$http->post('jrn_type');
98 $this->name=$http->post('opd_name');
99
100 $this->description= $http->post('od_description');
101 if ( $this->name=="")
102 {
103 $n=$this->db->get_next_seq('op_def_op_seq');
104 $this->name=$this->jrn_type.$n;
105
106 }
107
108 // get also info for the details
109 // common value
110 $this->detail=Pre_operation_detail::build_detail($this->jrn_type,$this->db);
111 $this->detail->get_post();
112 }
113
114 /**
115 * delete a template operation and children
116 */
117 function delete ()
118 {
119 $sql="delete from op_predef where od_id=$1";
120 $this->db->exec_sql($sql,array($this->od_id));
121 }
122 function save()
123 {
124 if ($this->od_id < 1) {
125 $this->save_insert();
126 } else {
127 $this->save_update();
128 }
129
130 }
131 function save_update()
132 {
133 $sql = "update op_predef set jrn_def_id = $1 , od_name = $2 ,
134 od_item =$3, od_description = $4 where od_id=$5";
135 $this->db->exec_sql($sql,array($this->p_jrn,$this->name,$this->nb_item,$this->description,$this->od_id));
136 // delete detail&
137 $this->db->exec_sql("delete from op_predef_detail where od_id = $1",array($this->od_id));
138 $this->detail->save($this->od_id,$this->nb_item);
139 }
140 /*!\brief save the predef check first is the name is unique
141 * \return true op.success otherwise false
142 */
143 function save_insert()
144 {
145
146 if ( $this->db->count_sql("select * from op_predef ".
147 "where upper(od_name)=upper('".Database::escape_string($this->name)."')".
148 "and jrn_def_id=".$this->p_jrn." and od_id <> ".$this->od_id)
149 != 0 )
150 {
151 $this->name="copy_".$this->name."_".microtime(true);
152 }
153 if ( $this->count() > MAX_PREDEFINED_OPERATION )
154 {
155 echo '<span class="notice">'.("Vous avez atteint le max. d'opération prédéfinie, désolé").'</span>';
156 return false;
157 }
158 try {
159 $this->db->start();
160 $sql='insert into op_predef (jrn_def_id,od_name,od_item,od_jrn_type,od_direct,od_description) '.
161 ' values '.
162 "($1,$2,$3,$4,$5 ,$6)".
163 'returning od_id';
164 $this->od_id= $this->db->get_value($sql,array($this->p_jrn,
165 $this->name,
166 $this->nb_item,
167 $this->jrn_type,
168 $this->od_direct,
169 $this->description,
170 ));
171
172
173 $this->detail->save($this->od_id,$this->nb_item);
174 $this->db->commit();
175 } catch (Exception $e) {
176 record_log("PROP139.Failed save predefined operation ");
177 $this->db->rollback();
178 }
179
180 return true;
181 }
182 /*!\brief load the data from the database and return an array
183 * \return an double array containing all the data from database
184 */
185 function load():array
186 {
187 $this->isloaded=true;
188 //------------------------------------------
189 // if new , then od_id == 0 and we need to use blank()
190 //------------------------------------------
191 if ($this->od_id == -1 ) {
192 $array=$this->blank($this->p_jrn);
193 return $array;
194 }
195 $sql="select od_id,jrn_def_id,od_name,od_item,od_jrn_type,od_description".
196 " from op_predef where od_id=$1 ".
197 " order by od_name";
198 $res=$this->db->exec_sql($sql,[$this->od_id]);
200 foreach (array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as $field) {
201 $this->$field=$array[0][$field];
202 }
203 $this->detail = Pre_operation_detail::build_detail($this->od_jrn_type, $this->db);
204 $array+=$this->detail->load($this->od_id);
205 return $array;
206 }
207 /**
208 * create a blank object to insert it later
209 * @param $p_ledger_id
210 * @throws Exception
211 */
212 function blank() {
213 $array["od_id"]=-1;
214 $array['jrn_def_id']=0;
215 $array['od_name']="";
216 $array['od_item']=2;
217 $array['od_jrn_type']=$this->get_jrn_type();
218 $array['od_description']="";
219 foreach (array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as $field) {
220 $this->$field=$array[$field];
221 }
222 $this->od_jrn_type=$array['od_jrn_type'];
223
224 $this->detail = Pre_operation_detail::build_detail($array['od_jrn_type'], $this->db);
225 $darray[0]=$array;
226 return $darray;
227 }
228
229 function compute_array()
230 {
231 if ($this->od_id > 0) {
232 $p_array = $this->load();
233 } else {
234 $p_array=$this->blank();
235 }
236 $array=array(
237 "e_comm"=>$p_array[0]["od_name"],
238 "nb_item"=>(($p_array[0]["od_item"]<10)?10:$p_array[0]["od_item"]) ,
239 "p_jrn"=>$p_array[0]["jrn_def_id"],
240 "jrn_type"=>$p_array[0]["od_jrn_type"],
241 "od_description"=>$p_array['0']['od_description']
242 );
243 $this->detail = Pre_operation_detail::build_detail($this->od_jrn_type, $this->db);
244 $array += $this->detail->compute_array($this->od_id);
245 return $array;
246
247 }
248
249 /*!\brief show the button for selecting a predefined operation
250 @deprecated
251 */
253 {
254
255 $select=new ISelect();
256 $value=$this->db->make_array("select od_id,od_name from op_predef ".
257 " where jrn_def_id=".$this->p_jrn.
258 " and od_direct ='".$this->od_direct."'".
259 " order by od_name");
260
261 if ( empty($value)==true) return "";
262 $select->value=$value;
263 $r=$select->input("pre_def");
264
265 return $r;
266 }
267 /*!\brief count the number of pred operation for a ledger */
268 function count()
269 {
270 $a=$this->db->count_sql("select od_id,od_name from op_predef ".
271 " where jrn_def_id= $1 ".
272 " and od_direct = $2 ".
273 " order by od_name",array($this->p_jrn,$this->od_direct));
274 return $a;
275 }
276 /*!\brief get the list of the predef. operation of a ledger
277 * \return string
278 */
280 {
281 $sql="select od_id,od_name,od_description from op_predef ".
282 " where jrn_def_id= $1 ".
283 " and od_direct = $2 ".
284 " order by od_name";
285 $res=$this->db->exec_sql($sql,array($this->p_jrn,$this->od_direct));
287 return $all;
288 }
289
290 /**
291 *
292 * @brief display the detail of predefined operation, normally everything
293 * is loaded
294 */
295 function display()
296 {
297 $array=$this->compute_array();
298 $select_ledger=$this->choose_ledger($array['jrn_type'],$array['p_jrn']);
299
300 require NOALYSS_TEMPLATE."/pre_operation_display.php";
301 echo $this->detail->display($array);
302 }
303 /*!\brief show a form to use pre_op
304 */
305 function form_get ($p_url)
306 {
307 $r=HtmlInput::button_action(_("Modèle d'opérations"),
308 ' $(\'modele_op_div\').style.display=\'block\';if ( $(\'lk_modele_op_tab\')) { $(\'lk_modele_op_tab\').focus();}');
309 $r.='<div id="modele_op_div" class="noprint">';
310 $r.=HtmlInput::title_box(_("Modèle d'opérations"), 'modele_op_div', 'hide',"","n");
311 $hid=new IHidden();
312 $r.=$hid->input("action","use_opd");
313 $r.=$hid->input("jrn_type",$this->jrn_type);
315 $r.=' <p style="text-align: center">'.
316 HtmlInput::button_hide('modele_op_div').
317 '</p>';
318 $r.='</div>';
319 return $r;
320
321 }
322
323 /*!\brief show the button for selecting a predefined operation */
325 {
326
327
328 $value=$this->db->get_array("select od_id,od_name,od_description from op_predef ".
329 " where jrn_def_id=$1".
330 " order by od_name",
331 array($this->p_jrn));
332
333 if ( $this->p_jrn=='') $value=array();
334
335 $r="";
336 if (count($value)==0) {
337 $r.=_("Vous n'avez encore sauvé aucun modèle");
338 return $r;
339 }
340 $r.=_('Cherche').' '.HtmlInput::filter_table('modele_op_tab', '0,1', '0');
341 $r.='<table style="width:100%" id="modele_op_tab">';
342 for ($i=0;$i<count($value);$i++) {
343 $r.='<tr class="'.(($i%2==0)?"even":"odd").'">';
344 $r.='<td style="font-weight:bold;vertical-align:top;text-decoration:underline">';
345 $r.=sprintf('<a href="%s&pre_def=%s" onclick="waiting_box()">%s</a> ',
346 $p_url,$value[$i]['od_id'],$value[$i]['od_name']);
347 $r.='</td>';
348 $r.='<td>'.h($value[$i]['od_description']).'</td>';
349 $r.='</tr>';
350 }
351 $r.='</table>';
352 return $r;
353 }
354 public function get_operation()
355 {
356 if ( $this->jrn_def_id=='') return array();
357 $value=$this->db->make_array("select od_id,od_name from op_predef ".
358 " where jrn_def_id=".sql_string($this->jrn_def_id).
359 " and od_direct ='".sql_string($this->od_direct)."'".
360 " order by od_name",1);
361 return $value;
362 }
363
364 /**
365 * @return mixed
366 */
367 public function get_db()
368 {
369 return $this->db;
370 return $this;
371 }
372
373 /**
374 * @param mixed $db
375 */
376 public function set_db($db)
377 {
378 $this->db = $db;
379 return $this;
380 }
381
382 /**
383 * @return mixed
384 */
385 public function get_nb_item()
386 {
387 return $this->nb_item;
388 return $this;
389 }
390
391 /**
392 * @param mixed $nb_item
393 */
394 public function set_nb_item($nb_item)
395 {
396 $this->nb_item = $nb_item;
397 return $this;
398 }
399
400 /**
401 * @return string
402 */
403 public function get_jrn_type()
404 {
405 return $this->jrn_type;
406 }
407
408 /**
409 * @param string $jrn_type
410 */
411 public function set_jrn_type($jrn_type)
412 {
413 $jrn_type=strtoupper($jrn_type);
414 if ( ! in_array ($jrn_type,['ACH','FIN','VEN','ODS'] )) throw new Exception('prop03.invalid ledger type');
415 $this->jrn_type = $jrn_type;
416 return $this;
417 }
418
419 /**
420 * @return string
421 */
422 public function get_name()
423 {
424 return $this->name;
425 return $this;
426 }
427
428 /**
429 * @param string $name
430 */
431 public function set_name($name)
432 {
433 $this->name = $name;
434 return $this;
435 }
436
437 /**
438 * @return array
439 */
440 public function get_detail()
441 {
442 return $this->detail;
443 return $this;
444 }
445
446 /**
447 * @param array $detail
448 */
450 {
451 $this->detail = $detail;
452 return $this;
453 }
454
455 /**
456 * @return string
457 */
458 public function get_od_direct()
459 {
460 return $this->od_direct;
461 return $this;
462 }
463
464 /**
465 * @param string $od_direct
466 */
467 public function set_od_direct($od_direct)
468 {
469 if ( ! in_array($od_direct,['f','t'])) throw new Exception('prop02.invalid od_direct');
470 $this->od_direct = $od_direct;
471 return $this;
472 }
473
474 /**
475 * @return int|mixed
476 */
477 public function get_od_id()
478 {
479 return $this->od_id;
480 }
481
482 /**
483 * @param int|mixed $od_id
484 */
485 public function set_od_id($od_id)
486 {
487 $this->od_id = $od_id;
488 return $this;
489 }
490
491
492 /*!\brief set the ledger
493 * \param $p_jrn is the ledger (jrn_id)
494 */
496 {
497 $this->p_jrn=$p_jrn;
498 $this->jrn_type=$this->db->get_value("select jrn_def_type from jrn_def where jrn_def_id=$1",[$p_jrn]);
499 return $this;
500 }
501
502 /**
503 * Build the select list for choosing the ledger
504 * @param string $p_string ledger type ACH VEN or ODS
505 * @param $p_default selected ledger , -1 if none
506 * @return ISelect
507 */
508 function choose_ledger($p_ledger_type,$p_default) {
509 $select_ledger=new ISelect("p_jrn");
510 $select_ledger->value=$this->db->make_array("select jrn_def_id,jrn_def_name
511 from jrn_def where jrn_def_type=$1 order by 2",
512 0,
513 [$p_ledger_type]);
514 $select_ledger->selected=$p_default;
515 return $select_ledger;
516 }
517}
518
519/*!\brief mother of the pre_op_XXX, it contains only one data : an
520 * object Pre_Operation. The child class contains an array of
521 * Pre_Operation object
522 */
524{
525 function __construct($p_cn)
526 {
527 $this->db=$p_cn;
528
529 }
530
531 static function build_detail($p_jrn_type,Database $database)
532 {
533 switch ($p_jrn_type) {
534 case 'ACH':
535 $detail=new Pre_op_ach($database);
536 break;
537 case 'VEN':
538 $detail=new Pre_Op_ven($database);
539 break;
540 case 'ODS':
541 $detail=new Pre_op_advanced($database);
542 break;
543 default:
544 throw new Exception(sprintf(_('Echec PreOperation chargement %s'),$p_jrn_type));
545 }
546 return $detail;
547 }
548
549}
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:511
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$opd_description
margin jrn_def_id
$from_poste name
static fetch_all($ret)
wrapper for the function pg_fetch_all
contains the class for connecting to Noalyss
static button_hide($div_name)
Hide the HTML popup.
static filter_table($p_table_id, $p_col, $start_row)
filter the rows in a table and keep the colored row in alternance
static button_action($action, $javascript, $id=NULL, $p_class="button", $p_symbole="")
button Html with javascript
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n')
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
manage the http input (get , post, request) and extract from an array
Html Input.
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input.
Definition: itext.class.php:30
Manage the TEXTAREA html element.
concerns the predefined operation for ACH ledger
mother of the pre_op_XXX, it contains only one data : an object Pre_Operation. The child class contai...
static build_detail($p_jrn_type, Database $database)
manage the predefined operation, link to the table op_def and op_def_detail
form_get($p_url)
show a form to use pre_op
get_post()
fill the object with the $_POST variable
count()
count the number of pred operation for a ledger
display_list_operation($p_url)
show the button for selecting a predefined operation
blank()
create a blank object to insert it later
get_list_ledger()
get the list of the predef. operation of a ledger
choose_ledger($p_ledger_type, $p_default)
Build the select list for choosing the ledger.
set_detail(Pre_operation_detail $detail)
set_p_jrn($p_jrn)
set the ledger
set_od_direct($od_direct)
set_description($description)
__construct($cn, $p_id=0)
load()
load the data from the database and return an array
show_button_deprecated()
show the button for selecting a predefined operation
static save_propose()
Propose to save the operation into a predefined operation.
save_insert()
save the predef check first is the name is unique
display()
display the detail of predefined operation, normally everything is loaded
$all
const MAX_PREDEFINED_OPERATION
Definition: constant.php:138
$SecUser db
$p_url