noalyss Version-9
noalyss_parameter_folder.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// Copyright Author Dany De Bontridder danydb@aevalys.eu
20/*! \file
21 * \brief Class to manage the company parameter (address, name...)
22 */
23/*!
24 * \brief Class to manage the company parameter (address, name...)
25 */
26#[AllowDynamicProperties]
28{
29 var $db;
34 var $MY_CP;
53 var $MY_REPORT; //!< In Belgium , we need a report on the beginning of the exercice , not in French,
54
55
56 // constructor
57 function __construct($p_cn)
58 {
59 $this->db=$p_cn;
60 $Res=$p_cn->exec_sql("select * from parameter where pr_id like 'MY_%'");
61 for ($i = 0;$i < Database::num_row($Res);$i++)
62 {
64 $key=$row['pr_id'];
65 $elt=$row['pr_value'];
66 // store value here
67 $this->{"$key"}=$elt;
68 }
69
70 }
71
72 public function __toString(): string
73 {
74 $r = <<<EOF
75MY_TVA = [ {$this->MY_TVA }]
76MY_STREET = [ {$this->MY_STREET }]
77MY_NUMBER= [ {$this->MY_NUMBER }]
78MY_CP= [ {$this->MY_CP }]
79MY_TEL= [ {$this->MY_TEL }]
80MY_PAYS= [ {$this->MY_PAYS }]
81MY_COMMUNE= [ {$this->MY_COMMUNE }]
82MY_FAX= [ {$this->MY_FAX }]
83MY_ANALYTIC= [ {$this->MY_ANALYTIC }]
84MY_STRICT= [ {$this->MY_STRICT }]
85MY_TVA_USE= [ {$this->MY_TVA_USE }]
86MY_PJ_SUGGEST= [ {$this->MY_PJ_SUGGEST }]
87MY_CHECK_PERIODE= [ {$this->MY_CHECK_PERIODE }]
88MY_DATE_SUGGEST= [ {$this->MY_DATE_SUGGEST }]
89MY_ALPHANUM= [ {$this->MY_ALPHANUM }]
90MY_UPDLAB= [ {$this->MY_UPDLAB }]
91MY_STOCK= [ {$this->MY_STOCK }]
92MY_DEFAULT_ROUND_ERROR_DEB= [ {$this->MY_DEFAULT_ROUND_ERROR_DEB }]
93MY_DEFAULT_ROUND_ERROR_CRED= [ {$this->MY_DEFAULT_ROUND_ERROR_CRED }]
94MY_ANC_FILTER= [ {$this->MY_ANC_FILTER }]
95MY_REPORT = [ {$this->MY_REPORT } ]
96
97EOF;
98 return $r;
99 }
100
101 function check_anc_filter($p_value):void
102 {
103 $tmp_value=$p_value;
104 $tmp_value=preg_replace("/[0-9]|,/", '', $p_value);
105 if ( $tmp_value != "") {
106 throw new Exception (sprintf(_("Valeur invalide %s"),$tmp_value),1000);
107 }
108 if (trim($p_value) == "") {
109 throw new Exception (sprintf(_("Erreur Filtre analytique %s"),$tmp_value),1001);
110
111 }
112
113 }
114 function check($p_attr, $p_value)
115 {
116 $ret_value=$p_value;
117 switch ($p_attr)
118 {
119 case 'MY_STRICT':
120
121 if (empty($p_value) ||($p_value!='Y'&&$p_value!='N'))
122 {
123 $ret_value='N';
124 }
125
126 break;
127 case 'MY_ANC_FILTER':
128 try
129 {
130 $p_value=noalyss_str_replace(" ", "", $p_value);
131 $this->check_anc_filter($p_value);
132 $ret_value=$p_value;
133 }
134 catch (Exception $exc)
135 {
136 throw $exc;
137 }
138
139 break;
140 default :
141 $ret_value=htmlspecialchars($p_value);
142 }
143 return $ret_value;
144 }
145
146 /*!
147 **************************************************
148 * \brief save the parameter into the database by inserting or updating
149 *
150 *
151 * \param $p_attr give the attribut name
152 *
153 */
154 function save($p_attr)
155 {
156 try {
157 $value=$this->check($p_attr,$this->$p_attr);
158
159 // check if the parameter does exist
160 if ( $this->db->get_value('select count(*) from parameter where pr_id=$1',array($p_attr)) != 0 )
161 {
162 $Res=$this->db->exec_sql("update parameter set pr_value=$1 where pr_id=$2",
163 array($value,$p_attr));
164 }
165 else
166 {
167
168 $Res=$this->db->exec_sql("insert into parameter (pr_id,pr_value) values( $1,$2)",
169 array($p_attr,$value));
170
171 }
172 } catch (Exception $e) {
173 throw $e;
174 }
175
176 }
177
178 /*!
179 **************************************************
180 * \brief save data
181 *
182 *
183 */
184 function update()
185 {
186
187 $this->save('MY_NAME');
188 $this->save('MY_TVA');
189 $this->save('MY_STREET');
190 $this->save('MY_NUMBER');
191 $this->save('MY_CP');
192 $this->save('MY_TEL');
193 $this->save('MY_PAYS');
194 $this->save('MY_COMMUNE');
195 $this->save('MY_FAX');
196 $this->save('MY_ANALYTIC');
197 $this->save('MY_STRICT');
198 $this->save('MY_TVA_USE');
199 $this->save('MY_PJ_SUGGEST');
200 $this->save('MY_CHECK_PERIODE');
201 $this->save('MY_DATE_SUGGEST');
202 $this->save('MY_ALPHANUM');
203 $this->save('MY_UPDLAB');
204 $this->save('MY_STOCK');
205 $this->save('MY_DEFAULT_ROUND_ERROR_DEB');
206 $this->save('MY_DEFAULT_ROUND_ERROR_CRED');
207 $this->save("MY_ANC_FILTER");
208 $this->save("MY_REPORT");
209
210 }
211 /**
212 * Check if an accounting match the anc_filter
213 * @param string $p_accounting
214 * @return boolean FALSE does not match , TRUE matches
215 */
216 function match_analytic($p_accounting)
217 {
218 $string="/^[".$this->MY_ANC_FILTER."]+/";
219 if ( preg_match($string,$p_accounting) == 0 ) return FALSE;
220 return TRUE;
221 }
222
223}
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
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
Class to manage the company parameter (address, name...)
save($p_attr)
save the parameter into the database by inserting or updating
match_analytic($p_accounting)
Check if an accounting match the anc_filter.
$MY_REPORT
In Belgium , we need a report on the beginning of the exercice , not in French,.
$Res
$SecUser db