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