noalyss Version-9
acc_ledger_info.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
21require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
22
23/*!\file
24 * \brief Manage additional info for Accountancy
25 */
26
27/*!
28 * \brief Manage the additionnal info for operation (from jrn), when an invoice is generated,
29 * the order or other info are going to be stored and used in the detail.
30 * this class maps the table jrn_info
31 */
33{
34 var $cn; /*!< connection */
35 var $ji_id; /*!< primary key */
36 var $id_type; /*!< type id */
37 var $jr_id; /*!< primary key of the table jrn */
38 var $ji_value; /*!< value for this */
39 function __construct($p_cn,$p_ji_id=0)
40 {
41 $this->cn=$p_cn;
42 $this->ji_id=$p_ji_id;
43 }
44 function insert()
45 {
46 if ( ! isset ($this->jr_id) ||
47 ! isset ($this->ji_value) ||
48 ! isset ($this->id_type ) )
49 {
50 echo 'Appel incorrecte '.__FILE__.__LINE__;
51 var_dump($this);
52 throw new Exception(_('appel incorrect'));
53 }
54 try
55 {
56 $sql=$this->cn->exec_sql('insert into jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)'.
57 ' returning ji_id ',
58 array ($this->jr_id,$this->id_type,$this->ji_value)
59 );
60 $this->ji_id=Database::fetch_result($sql,0,0);
61 }
62 catch (Exception $e)
63 {
65 echo "Echec sauvegarde info additionnelles";
66 throw $e;
67 }
68 }
69 function update()
70 {
71 if ( ! isset ($this->jr_id) ||
72 ! isset ($this->ji_value) ||
73 ! isset ($this->jr_id ) )
74 {
75 echo 'Appel incorrecte '.__FILE__.__LINE__;
76 var_dump($this);
77 throw new Exception('appel incorrect');
78 }
79 try
80 {
81 $sql=$this->exec_sql('update jrn_info set jr_id=$1 ,id_type=$2,ji_value=$3 where ji_id=$4)'.
82 array ($this->jr_id,$this->id_type,$this->ji_value,$this->ji_id)
83 );
84 }
85 catch (Exception $e)
86 {
88 $this->cn->rollback();
89 echo "Echec sauvegarde info additionnelles";
90 throw $e;
91 }
92 }
93 /**
94 * @brief load the todo_list row thanks it's ID
95 * @return boolean true if found else false
96 */
97 function load():bool
98 {
99 $sql="select jr_id,id_type,ji_value from jrn_info where ji_id=$1";
100 $r=$this->cn->exec_sql($sql,[$this->ji_id]);
101 if (Database::num_row ($r) > 0 )
102 {
104 return true;
105 }
106 else
107 {
108 return false;
109 }
110
111 }
113 {
114 foreach (array("jr_id","id_type","ji_value") as $col)
115 {
116 $this->$col=$p_array[$col];
117 }
118 }
119 function set_id($p_ji_id)
120 {
121 $this->$ji_id=$p_ji_id;
122 }
124 {
125 $this->jr_id=$p_id;
126 }
127 function set_type($p_id)
128 {
129 $this->id_type=$p_id;
130 }
131 function set_value($p_id)
132 {
133 $this->ji_value=$p_id;
134 }
135 /*!\brief load all the jrn_info thanks the jr_id
136 * \return an array of object
137 */
138 function load_all()
139 {
140 if ( ! isset ($this->jr_id) )
141 {
142 echo "jr_id is not set ".__FILE__.__LINE__;
143 throw new Exception('Error : jr_id not set');
144 }
145
146 $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
147 $r=$this->cn->exec_sql($sql);
148 if (Database::num_row($r) == 0 )
149 return array();
151 $ret=array();
152 foreach ($array as $row)
153 {
154 $o=new Acc_Ledger_Info($this->cn,$row['ji_id']);
155 $o->load();
156 $ret[]=clone $o;
157 }
158 return $ret;
159
160 }
161 function count()
162 {
163 $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
164 return $this->cn->count_sql($sql);
165 }
166 function search_id_internal($p_internal)
167 {
168 $sql="select jr_id from jrn where jr_internal='$p_internal'";
169 $r=$this->cn->exec_sql($sql);
170 if (Database::num_row($r) > 0 )
171 {
172 $this->jr_id=Database::fetch_result($r,0,0);
173 return $this->jr_id;
174 }
175 else
176 {
177 $this->jr_id=-1;
178 return $this->jr_id;
179 }
180 }
181 /**
182 *@brief save all extra information in once, called by compta_ven and compta_ach
183 *@param $p_jr_id is the jrn.jr_id concerned,
184 *@param $p_array is the array with the data usually it is $_POST
185 *@note will change this->jr_id
186 *@see compta_ven.inc.php compta_ach.inc.php
187 */
188 function save_extra($p_jr_id,$p_array)
189 {
190 $this->jr_id=$p_jr_id;
191 if (noalyss_strlentrim($p_array['bon_comm'] ) != 0 )
192 {
193 $this->set_type('BON_COMMANDE');
194 $this->set_value($p_array['bon_comm']);
195 $this->insert();
196 }
197 if (noalyss_strlentrim($p_array['other_info'] ) != 0 )
198 {
199 $this->set_type('OTHER');
200 $this->set_value($p_array['other_info']);
201 $this->insert();
202 }
203 }
204}
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$op jr_id
Definition: ajax_ledger.php:83
$input_from cn
Definition: balance.inc.php:66
Manage the additionnal info for operation (from jrn), when an invoice is generated,...
load()
load the todo_list row thanks it's ID
save_extra($p_jr_id, $p_array)
save all extra information in once, called by compta_ven and compta_ach
search_id_internal($p_internal)
load_all()
load all the jrn_info thanks the jr_id
__construct($p_cn, $p_ji_id=0)
static fetch_all($ret)
wrapper for the function pg_fetch_all
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows