noalyss Version-9
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 if (count($value)==0) {
338 $r.=_("Vous n'avez encore sauvé aucun modèle");
339 return $r;
340 }
341 $r.=_('Cherche').' '.HtmlInput::filter_table('modele_op_tab', '0,1', '0');
342 $r.='<table style="width:100%" id="modele_op_tab">';
343 for ($i=0;$i<count($value);$i++) {
344 $r.='<tr class="'.(($i%2==0)?"even":"odd").'">';
345 $r.='<td style="font-weight:bold;vertical-align:top;text-decoration:underline">';
346 $r.=sprintf('<a href="%s&pre_def=%s" onclick="waiting_box()">%s</a> ',
347 $p_url,$value[$i]['od_id'],$value[$i]['od_name']);
348 $r.='</td>';
349 $r.='<td>'.h($value[$i]['od_description']).'</td>';
350 $r.='</tr>';
351 }
352 $r.='</table>';
353 return $r;
354 }
355 public function get_operation()
356 {
357 if ( $this->jrn_def_id=='') return array();
358 $value=$this->db->make_array("select od_id,od_name from op_predef ".
359 " where jrn_def_id=".sql_string($this->jrn_def_id).
360 " and od_direct ='".sql_string($this->od_direct)."'".
361 " order by od_name",1);
362 return $value;
363 }
364
365 /**
366 * @return mixed
367 */
368 public function get_db()
369 {
370 return $this->db;
371 return $this;
372 }
373
374 /**
375 * @param mixed $db
376 */
377 public function set_db($db)
378 {
379 $this->db = $db;
380 return $this;
381 }
382
383 /**
384 * @return mixed
385 */
386 public function get_nb_item()
387 {
388 return $this->nb_item;
389 return $this;
390 }
391
392 /**
393 * @param mixed $nb_item
394 */
395 public function set_nb_item($nb_item)
396 {
397 $this->nb_item = $nb_item;
398 return $this;
399 }
400
401 /**
402 * @return string
403 */
404 public function get_jrn_type()
405 {
406 return $this->jrn_type;
407 }
408
409 /**
410 * @param string $jrn_type
411 */
412 public function set_jrn_type($jrn_type)
413 {
414 $jrn_type=strtoupper($jrn_type);
415 if ( ! in_array ($jrn_type,['ACH','FIN','VEN','ODS'] )) throw new Exception('prop03.invalid ledger type');
416 $this->jrn_type = $jrn_type;
417 return $this;
418 }
419
420 /**
421 * @return string
422 */
423 public function get_name()
424 {
425 return $this->name;
426 return $this;
427 }
428
429 /**
430 * @param string $name
431 */
432 public function set_name($name)
433 {
434 $this->name = $name;
435 return $this;
436 }
437
438 /**
439 * @return array
440 */
441 public function get_detail()
442 {
443 return $this->detail;
444 return $this;
445 }
446
447 /**
448 * @param array $detail
449 */
451 {
452 $this->detail = $detail;
453 return $this;
454 }
455
456 /**
457 * @return string
458 */
459 public function get_od_direct()
460 {
461 return $this->od_direct;
462 return $this;
463 }
464
465 /**
466 * @param string $od_direct
467 */
468 public function set_od_direct($od_direct)
469 {
470 if ( ! in_array($od_direct,['f','t'])) throw new Exception('prop02.invalid od_direct');
471 $this->od_direct = $od_direct;
472 return $this;
473 }
474
475 /**
476 * @return int|mixed
477 */
478 public function get_od_id()
479 {
480 return $this->od_id;
481 }
482
483 /**
484 * @param int|mixed $od_id
485 */
486 public function set_od_id($od_id)
487 {
488 $this->od_id = $od_id;
489 return $this;
490 }
491
492
493 /*!\brief set the ledger
494 * \param $p_jrn is the ledger (jrn_id)
495 */
497 {
498 $this->p_jrn=$p_jrn;
499 $this->jrn_type=$this->db->get_value("select jrn_def_type from jrn_def where jrn_def_id=$1",[$p_jrn]);
500 return $this;
501 }
502
503 /**
504 * Build the select list for choosing the ledger
505 * @param string $p_string ledger type ACH VEN or ODS
506 * @param $p_default selected ledger , -1 if none
507 * @return ISelect
508 */
509 function choose_ledger($p_ledger_type,$p_default) {
510 $select_ledger=new ISelect("p_jrn");
511 $select_ledger->value=$this->db->make_array("select jrn_def_id,jrn_def_name
512 from jrn_def where jrn_def_type=$1 order by 2",
513 0,
514 [$p_ledger_type]);
515 $select_ledger->selected=$p_default;
516 return $select_ledger;
517 }
518}
519
520/*!
521@class Pre_operation_detail
522@brief mother of the pre_op_XXX, it contains only one data : an
523 * object Pre_Operation. The child class contains an array of
524 * Pre_Operation object
525 *
526 */
527#[AllowDynamicProperties]
529{
530 protected $db;
531 function __construct($p_cn)
532 {
533 $this->db=$p_cn;
534
535 }
536
537 static function build_detail($p_jrn_type,Database $database)
538 {
539 switch ($p_jrn_type) {
540 case 'ACH':
541 $detail=new Pre_op_ach($database);
542 break;
543 case 'VEN':
544 $detail=new Pre_Op_ven($database);
545 break;
546 case 'ODS':
547 $detail=new Pre_op_advanced($database);
548 break;
549 default:
550 throw new Exception(sprintf(_('Echec PreOperation chargement %s'),$p_jrn_type));
551 }
552 return $detail;
553 }
554
555}
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)
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.
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:137
$SecUser db